From: Jim Meyering Date: Sat, 25 Aug 2001 09:19:59 +0000 (+0000) Subject: (different): Don't assume that lengths can fit X-Git-Tag: TEXTUTILS-2_0_15~329 X-Git-Url: http://git.ipfire.org/gitweb/index.cgi?a=commitdiff_plain;h=c1471b042b5425a72054d2f48d207780dfeeaf65;p=thirdparty%2Fcoreutils.git (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. --- diff --git a/src/uniq.c b/src/uniq.c index 4f870bf3d9..2fae7a53d6 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