]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
(begfield, limfield): Rearrange comparisons to avoid compiler warnings.
authorJim Meyering <jim@meyering.net>
Sat, 28 Sep 2002 16:32:23 +0000 (16:32 +0000)
committerJim Meyering <jim@meyering.net>
Sat, 28 Sep 2002 16:32:23 +0000 (16:32 +0000)
(fillbuf, keycompare): Cast literal `-1' to size_t in comparisons,
to avoid compiler warnings.

src/sort.c

index c8230fbedb1d8355a6ad9db024489158d3d9d3c0..9ba085dc5df5f028b6a25e597765cea77f851ee2 100644 (file)
@@ -799,7 +799,7 @@ begfield (const struct line *line, const struct keyfield *key)
     while (ptr < lim && blanks[UCHAR (*ptr)])
       ++ptr;
 
-  if (schar < lim - ptr)
+  if (ptr + schar <= lim)
     ptr += schar;
   else
     ptr = lim;
@@ -902,7 +902,7 @@ limfield (const struct line *line, const struct keyfield *key)
       ++ptr;
 
   /* Advance PTR by ECHAR (if possible), but no further than LIM.  */
-  if (echar < lim - ptr)
+  if (ptr + echar < lim)
     ptr += echar;
   else
     ptr = lim;
@@ -992,9 +992,11 @@ fillbuf (struct buffer *buf, register FILE *fp, char const *file)
                {
                  /* Precompute the position of the first key for
                      efficiency. */
-                 line->keylim = key->eword == -1 ? p : limfield (line, key);
+                 line->keylim = (key->eword == (size_t) -1
+                                 ? p
+                                 : limfield (line, key));
 
-                 if (key->sword != -1)
+                 if (key->sword != (size_t) -1)
                    line->keybeg = begfield (line, key);
                  else
                    {
@@ -1464,12 +1466,12 @@ keycompare (const struct line *a, const struct line *b)
        break;
 
       /* Find the beginning and limit of the next field.  */
-      if (key->eword != -1)
+      if (key->eword != (size_t) -1)
        lima = limfield (a, key), limb = limfield (b, key);
       else
        lima = a->text + a->length - 1, limb = b->text + b->length - 1;
 
-      if (key->sword != -1)
+      if (key->sword != (size_t) -1)
        texta = begfield (a, key), textb = begfield (b, key);
       else
        {