From: Ivan Maidanski Date: Mon, 29 Aug 2016 12:58:00 +0000 (+0300) Subject: Eliminate 'checking if unsigned variable is <0' cppcheck style warning X-Git-Tag: v7.6.2~427 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=abeba58715048fd88517c2ac61e94e7966e8ad7a;p=gc Eliminate 'checking if unsigned variable is <0' cppcheck style warning * cord/cordbscs.c (CORD_from_fn, CORD_substr): Do not expect size_t value to be negative (replace <=0 comparison with ==0 one). * cord/cordxtra.c (CORD_cmp): Likewise. * cord/cordbscs.c (CORD_substr): Remove obsolete comment (about SunOS 4 which had signed size_t type). --- diff --git a/cord/cordbscs.c b/cord/cordbscs.c index 277d1362..cc5c700d 100644 --- a/cord/cordbscs.c +++ b/cord/cordbscs.c @@ -280,7 +280,7 @@ CORD CORD_cat(CORD x, CORD y) CORD CORD_from_fn(CORD_fn fn, void * client_data, size_t len) { - if (len <= 0) return(0); + if (len == 0) return(0); if (len <= SHORT_LIMIT) { register char * result; register size_t i; @@ -456,9 +456,7 @@ CORD CORD_substr(CORD x, size_t i, size_t n) { register size_t len = CORD_len(x); - if (i >= len || n <= 0) return(0); - /* n < 0 is impossible in a correct C implementation, but */ - /* quite possible under SunOS 4.X. */ + if (i >= len || n == 0) return(0); if (i + n > len) n = len - i; return(CORD_substr_checked(x, i, n)); } diff --git a/cord/cordxtra.c b/cord/cordxtra.c index a185185c..d6e0462f 100644 --- a/cord/cordxtra.c +++ b/cord/cordxtra.c @@ -171,8 +171,9 @@ int CORD_cmp(CORD x, CORD y) if (!CORD_pos_valid(ypos)) { return(1); } - if ((avail = CORD_pos_chars_left(xpos)) <= 0 - || (yavail = CORD_pos_chars_left(ypos)) <= 0) { + avail = CORD_pos_chars_left(xpos); + if (avail == 0 + || (yavail = CORD_pos_chars_left(ypos)) == 0) { register char xcurrent = CORD_pos_fetch(xpos); register char ycurrent = CORD_pos_fetch(ypos); if (xcurrent != ycurrent) return(xcurrent - ycurrent);