summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJim Meyering <jim@meyering.net>2001-08-25 09:19:59 +0000
committerJim Meyering <jim@meyering.net>2001-08-25 09:19:59 +0000
commitc1471b042b5425a72054d2f48d207780dfeeaf65 (patch)
tree60bc165c15e8b645d10fc8831aaa9136e489dd9b /src
parent7bd952c2a89e7a990f526f6db8307085529735b8 (diff)
downloadcoreutils-c1471b042b5425a72054d2f48d207780dfeeaf65.tar.xz
(different): Don't assume that lengths can fit
into size_t. Tune code for the common case where the line lengths differ: we avoid comparing them entirely in that case.
Diffstat (limited to 'src')
-rw-r--r--src/uniq.c13
1 files changed, 5 insertions, 8 deletions
diff --git a/src/uniq.c b/src/uniq.c
index 4f870bf3d..2fae7a53d 100644
--- a/src/uniq.c
+++ b/src/uniq.c
@@ -207,24 +207,21 @@ find_field (const struct linebuffer *line)
static int
different (const char *old, const char *new, size_t oldlen, size_t newlen)
{
- register int order;
-
if (check_chars < oldlen)
oldlen = check_chars;
if (check_chars < newlen)
newlen = check_chars;
+ if (oldlen != newlen)
+ return 1;
+
/* Use an if-statement here rather than a function variable to
avoid portability hassles of getting a non-conflicting declaration
of memcmp. */
if (ignore_case)
- order = memcasecmp (old, new, MIN (oldlen, newlen));
+ return memcasecmp (old, new, oldlen);
else
- order = memcmp (old, new, MIN (oldlen, newlen));
-
- if (order == 0)
- return oldlen - newlen;
- return order;
+ return memcmp (old, new, oldlen);
}
/* Output the line in linebuffer LINE to stream STREAM