From: Collin Funk Date: Sun, 22 Jun 2025 04:50:27 +0000 (-0700) Subject: maint: use _GL_CMP instead of handwriting three-valued comparisons X-Git-Tag: v9.8~297 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=1f6186b82c4b834219a477fce789e8b607dd85f2;p=thirdparty%2Fcoreutils.git maint: use _GL_CMP instead of handwriting three-valued comparisons * src/comm.c (compare_files): Use _GL_CMP. * src/join.c (keycmp): Likewise. * src/ls.c (off_cmp): Likewise. * src/ptx.c (compare_words, compare_occurs): Likewise. * src/set-fields.c (compare_ranges): Likewise. * src/sort.c (compare_random, diff_reversed, compare): Likewise. --- diff --git a/src/comm.c b/src/comm.c index 92be28528c..dd61dd9c80 100644 --- a/src/comm.c +++ b/src/comm.c @@ -318,8 +318,7 @@ compare_files (char **infiles) size_t len = MIN (thisline[0]->length, thisline[1]->length) - 1; order = memcmp (thisline[0]->buffer, thisline[1]->buffer, len); if (order == 0) - order = ((thisline[0]->length > thisline[1]->length) - - (thisline[0]->length < thisline[1]->length)); + order = _GL_CMP (thisline[0]->length, thisline[1]->length); } } diff --git a/src/join.c b/src/join.c index 93ffdafc13..faf402eeab 100644 --- a/src/join.c +++ b/src/join.c @@ -384,7 +384,7 @@ keycmp (struct line const *line1, struct line const *line2, if (diff) return diff; - return (len1 > len2) - (len1 < len2); + return _GL_CMP (len1, len2); } /* Check that successive input lines PREV and CURRENT from input file diff --git a/src/ls.c b/src/ls.c index bbc1bb2fd8..e84e0facff 100644 --- a/src/ls.c +++ b/src/ls.c @@ -3898,7 +3898,7 @@ cmp_btime (struct fileinfo const *a, struct fileinfo const *b, static int off_cmp (off_t a, off_t b) { - return (a > b) - (a < b); + return _GL_CMP (a, b); } static int diff --git a/src/ptx.c b/src/ptx.c index 8c42db2d24..006eb66afe 100644 --- a/src/ptx.c +++ b/src/ptx.c @@ -558,7 +558,7 @@ compare_words (const void *void_first, const void *void_second) } } - return (first->size > second->size) - (first->size < second->size); + return _GL_CMP (first->size, second->size); } /*-----------------------------------------------------------------------. @@ -576,8 +576,7 @@ compare_occurs (const void *void_first, const void *void_second) value = compare_words (&first->key, &second->key); return (value ? value - : ((first->key.start > second->key.start) - - (first->key.start < second->key.start))); + : _GL_CMP (first->key.start, second->key.start)); #undef first #undef second } diff --git a/src/set-fields.c b/src/set-fields.c index 0063ed8444..31547e4e9a 100644 --- a/src/set-fields.c +++ b/src/set-fields.c @@ -61,7 +61,7 @@ static int compare_ranges (const void *a, const void *b) { struct field_range_pair const *ap = a, *bp = b; - return (ap->lo > bp->lo) - (ap->lo < bp->lo); + return _GL_CMP (ap->lo, bp->lo); } /* Reallocate Range Pair entries, with corresponding diff --git a/src/sort.c b/src/sort.c index 7af1a25121..4a1fdfd375 100644 --- a/src/sort.c +++ b/src/sort.c @@ -2295,7 +2295,7 @@ compare_random (char *restrict texta, size_t lena, { xfrm_diff = memcmp (buf, buf + sizea, MIN (sizea, sizeb)); if (! xfrm_diff) - xfrm_diff = (sizea > sizeb) - (sizea < sizeb); + xfrm_diff = _GL_CMP (sizea, sizeb); } } } @@ -2312,7 +2312,7 @@ compare_random (char *restrict texta, size_t lena, { xfrm_diff = memcmp (texta, textb, MIN (lena, lenb)); if (! xfrm_diff) - xfrm_diff = (lena > lenb) - (lena < lenb); + xfrm_diff = _GL_CMP (lena, lenb); } diff = xfrm_diff; @@ -2678,7 +2678,7 @@ key_warnings (struct keyfield const *gkey, bool gkey_only) static int diff_reversed (int diff, bool reversed) { - return reversed ? (diff < 0) - (diff > 0) : diff; + return reversed ? _GL_CMP (0, diff) : diff; } /* Compare two lines A and B trying every key in sequence until there @@ -2842,7 +2842,7 @@ keycompare (struct line const *a, struct line const *b) diff = memcmp (texta, textb, lenmin); if (! diff) - diff = (lena > lenb) - (lena < lenb); + diff = _GL_CMP (lena, lenb); } if (diff) @@ -2915,7 +2915,7 @@ compare (struct line const *a, struct line const *b) { diff = memcmp (a->text, b->text, MIN (alen, blen)); if (!diff) - diff = (alen > blen) - (alen < blen); + diff = _GL_CMP (alen, blen); } return diff_reversed (diff, reverse);