Here comes the third part: Elimination of some 'continue;'
statements.
The problem with the 'continue;' statements is that they are pitfall
regarding refactorings that transform
for (int i = 0; i < n; i++, p++)
{
[...]
}
to
for (int i = 0; i < n; i++)
{
[...]
p++;
}
or vice versa. Such refactorings will be part of the next step,
the reduction of variable scopes.
When a 'continue;' statement can easily be replaced with an if/else,
this fixes the pitfall. The patch below does this.
There are good uses of 'continue;', such as
- in 'switch' statements,
- when parsing some string,
- or in a complicated algorithm, 'continue;' is sometimes the better way
of writing a 'goto' statement.
I'm not touching these cases.
2025-11-18 Bruno Haible <[email protected]>
lib: Replace some 'continue;' statements with if/else.
* lib/base32.c (base32_decode_ctx): Use if/else instead of 'continue;'.
* lib/base64.c (base64_decode_ctx): Likewise.
* lib/bitset/array.c (abitset_list): Likewise.
* lib/bitset/list.c (lbitset_disjoint_p): Likewise.
* lib/bitset/table.c (tbitset_equal_p, tbitset_list, tbitset_subset_p,
tbitset_disjoint_p, tbitset_op3_cmp): Likewise.
* lib/bitset/vector.c (vbitset_list): Likewise.
* lib/diffseq.h (diag): Likewise.
* lib/file-has-acl.c (fdfile_has_aclinfo): Likewise.
* lib/fwriteerror.c (main): Likewise.
* lib/getugroups.c (getugroups): Likewise.
* lib/hash.c (transfer_entries): Likewise.
* lib/inet_pton.c (inet_pton6): Likewise.
* lib/mountlist.c (read_file_system_list): Likewise.
* lib/poll.c (poll): Likewise.
* lib/select.c (rpl_select): Likewise.
* lib/set-permissions.c (set_acls_from_mode): Likewise.
* lib/timevar.c (timevar_print): Likewise.
* lib/wcscasecmp-impl.h (wcscasecmp): Likewise.
* lib/wcscmp-impl.h (wcscmp): Likewise.
* lib/wcsncasecmp-impl.h (wcsncasecmp): Likewise.
* lib/wcsncmp-impl.h (wcsncmp): Likewise.
* lib/wmemcmp-impl.h (wmemcmp): Likewise.
"git diff -w" below.
diff --git a/lib/base32.c b/lib/base32.c
index cc74f921e0..9df9878d8c 100644
--- a/lib/base32.c
+++ b/lib/base32.c
@@ -503,9 +503,9 @@ base32_decode_ctx (struct base32_decode_context *ctx,
{
++in;
--inlen;
- continue;
}
-
+ else
+ {
/* Restore OUT and OUTLEFT. */
out -= outleft_save - outleft;
outleft = outleft_save;
@@ -533,6 +533,7 @@ base32_decode_ctx (struct base32_decode_context *ctx,
inlen = in_end - in;
}
}
+ }
*outlen -= outleft;
diff --git a/lib/base64.c b/lib/base64.c
index 8a0edd4a6e..cfdfef0bb0 100644
--- a/lib/base64.c
+++ b/lib/base64.c
@@ -505,9 +505,9 @@ base64_decode_ctx (struct base64_decode_context *ctx,
{
++in;
--inlen;
- continue;
}
-
+ else
+ {
/* Restore OUT and OUTLEFT. */
out -= outleft_save - outleft;
outleft = outleft_save;
@@ -535,6 +535,7 @@ base64_decode_ctx (struct base64_decode_context *ctx,
inlen = in_end - in;
}
}
+ }
*outlen -= outleft;
diff --git a/lib/bitset/array.c b/lib/bitset/array.c
index b796d0d190..817dbaaac9 100644
--- a/lib/bitset/array.c
+++ b/lib/bitset/array.c
@@ -226,9 +226,8 @@ abitset_list (bitset src, bitset_bindex *list,
for (; windex < size; windex++, bitoff += BITSET_WORD_BITS)
{
bitset_word word = srcp[windex];
- if (!word)
- continue;
-
+ if (word)
+ {
/* Is there enough room to avoid checking in each iteration? */
if ((count + BITSET_WORD_BITS) < num)
BITSET_FOR_EACH_BIT (pos, word)
@@ -244,6 +243,7 @@ abitset_list (bitset src, bitset_bindex *list,
}
}
}
+ }
*next = bitoff;
return count;
diff --git a/lib/bitset/list.c b/lib/bitset/list.c
index 9d30274a48..724e7d47ec 100644
--- a/lib/bitset/list.c
+++ b/lib/bitset/list.c
@@ -921,13 +921,14 @@ lbitset_disjoint_p (bitset dst, bitset src)
}
/* Since the elements are different, there is no
intersection of these elements. */
- continue;
}
-
+ else
+ {
for (unsigned j = 0; j < LBITSET_ELT_WORDS; j++)
if (selt->words[j] & delt->words[j])
return false;
}
+ }
return true;
}
diff --git a/lib/bitset/table.c b/lib/bitset/table.c
index 615fa05841..da6b304865 100644
--- a/lib/bitset/table.c
+++ b/lib/bitset/table.c
@@ -406,8 +406,8 @@ tbitset_equal_p (bitset dst, bitset src)
tbitset_elt *selt = selts[j];
tbitset_elt *delt = delts[j];
- if (!selt && !delt)
- continue;
+ if (selt || delt)
+ {
if ((selt && !delt) || (!selt && delt))
return false;
@@ -415,6 +415,7 @@ tbitset_equal_p (bitset dst, bitset src)
if (TBITSET_WORDS (selt)[i] != TBITSET_WORDS (delt)[i])
return false;
}
+ }
return true;
}
@@ -645,9 +646,8 @@ tbitset_list (bitset bset, bitset_bindex *list,
for (; eindex < size; eindex++)
{
tbitset_elt *elt = elts[eindex];
- if (!elt)
- continue;
-
+ if (elt)
+ {
bitset_word *srcp = TBITSET_WORDS (elt);
bitset_windex windex = eindex * TBITSET_ELT_WORDS;
bitno = windex * BITSET_WORD_BITS;
@@ -704,6 +704,7 @@ tbitset_list (bitset bset, bitset_bindex *list,
}
}
}
+ }
*next = bitno;
return count;
@@ -821,9 +822,8 @@ tbitset_subset_p (bitset dst, bitset src)
tbitset_elt *selt = j < ssize ? selts[j] : NULL;
tbitset_elt *delt = j < dsize ? delts[j] : NULL;
- if (!selt && !delt)
- continue;
-
+ if (selt || delt)
+ {
if (!selt)
selt = &tbitset_zero_elts[0];
if (!delt)
@@ -834,6 +834,7 @@ tbitset_subset_p (bitset dst, bitset src)
!= (TBITSET_WORDS (selt)[i] | TBITSET_WORDS (delt)[i]))
return false;
}
+ }
return true;
}
@@ -853,13 +854,13 @@ tbitset_disjoint_p (bitset dst, bitset src)
tbitset_elt *selt = j < ssize ? selts[j] : NULL;
tbitset_elt *delt = j < dsize ? delts[j] : NULL;
- if (!selt || !delt)
- continue;
-
+ if (selt && delt)
+ {
for (unsigned i = 0; i < TBITSET_ELT_WORDS; i++)
if ((TBITSET_WORDS (selt)[i] & TBITSET_WORDS (delt)[i]))
return false;
}
+ }
return true;
}
@@ -897,9 +898,9 @@ tbitset_op3_cmp (bitset dst, bitset src1, bitset src2, enum
bitset_ops op)
changed = true;
tbitset_elt_remove (dst, j);
}
- continue;
}
-
+ else
+ {
if (!selt1)
selt1 = &tbitset_zero_elts[0];
if (!selt2)
@@ -975,6 +976,7 @@ tbitset_op3_cmp (bitset dst, bitset src1, bitset src2, enum
bitset_ops op)
else
tbitset_elt_free (delt);
}
+ }
/* If we have elements of DST left over, free them all. */
for (; j < dsize; j++)
diff --git a/lib/bitset/vector.c b/lib/bitset/vector.c
index efd73d4b37..3c8a0203b1 100644
--- a/lib/bitset/vector.c
+++ b/lib/bitset/vector.c
@@ -260,9 +260,8 @@ vbitset_list (bitset src, bitset_bindex *list,
for (; windex < size; windex++, bitoff += BITSET_WORD_BITS)
{
bitset_word word = srcp[windex];
- if (!word)
- continue;
-
+ if (word)
+ {
/* Is there enough room to avoid checking in each iteration? */
if ((count + BITSET_WORD_BITS) < num)
BITSET_FOR_EACH_BIT (pos, word)
@@ -278,6 +277,7 @@ vbitset_list (bitset src, bitset_bindex *list,
}
}
}
+ }
*next = bitoff;
return count;
diff --git a/lib/diffseq.h b/lib/diffseq.h
index b2f24c82af..b4959813d7 100644
--- a/lib/diffseq.h
+++ b/lib/diffseq.h
@@ -286,9 +286,8 @@ diag (OFFSET xoff, OFFSET xlim, OFFSET yoff, OFFSET ylim,
bool find_minimal,
}
}
- if (find_minimal)
- continue;
-
+ if (!find_minimal)
+ {
#ifdef USE_HEURISTIC
bool heuristic = ctxt->heuristic;
#else
@@ -438,6 +437,7 @@ diag (OFFSET xoff, OFFSET xlim, OFFSET yoff, OFFSET ylim,
bool find_minimal,
return;
}
}
+ }
#undef XREF_YREF_EQUAL
}
diff --git a/lib/file-has-acl.c b/lib/file-has-acl.c
index d2fa69a283..b1eb1f2e8e 100644
--- a/lib/file-has-acl.c
+++ b/lib/file-has-acl.c
@@ -660,8 +660,8 @@ fdfile_has_aclinfo (MAYBE_UNUSED int fd,
(aclent_t *) malloc (alloc * sizeof (aclent_t));
if (entries == NULL)
return -1;
- continue;
}
+ else
break;
}
if (count < 0)
@@ -732,8 +732,8 @@ fdfile_has_aclinfo (MAYBE_UNUSED int fd,
entries = malloced = (ace_t *) malloc (alloc * sizeof (ace_t));
if (entries == NULL)
return -1;
- continue;
}
+ else
break;
}
if (count < 0)
diff --git a/lib/fwriteerror.c b/lib/fwriteerror.c
index c5c5e5c1a8..ceda293504 100644
--- a/lib/fwriteerror.c
+++ b/lib/fwriteerror.c
@@ -151,11 +151,9 @@ main ()
FILE *stream = fopen (UNWRITABLE_FILE, "w");
if (stream == NULL)
- {
fprintf (stderr, "Test %u:%u: could not open file\n", i, j);
- continue;
- }
-
+ else
+ {
fwrite (dummy, 347, 1, stream);
fwrite (dummy, size - 347, 1, stream);
if (j)
@@ -172,6 +170,7 @@ main ()
i, j);
}
}
+ }
return 0;
}
diff --git a/lib/getugroups.c b/lib/getugroups.c
index e4a8c8d6c6..6d17e43b6c 100644
--- a/lib/getugroups.c
+++ b/lib/getugroups.c
@@ -82,9 +82,8 @@ getugroups (int maxcount, gid_t *grouplist, char const
*username,
{
int n;
- if (!streq (username, *cp))
- continue;
-
+ if (streq (username, *cp))
+ {
/* See if this group number is already on the list. */
for (n = 0; n < count; ++n)
if (grouplist && grouplist[n] == grp->gr_gid)
@@ -108,6 +107,7 @@ getugroups (int maxcount, gid_t *grouplist, char const
*username,
}
}
}
+ }
if (errno != 0)
count = -1;
diff --git a/lib/hash.c b/lib/hash.c
index 61c7b5889d..ed03a8695c 100644
--- a/lib/hash.c
+++ b/lib/hash.c
@@ -740,8 +740,8 @@ transfer_entries (Hash_table *dst, Hash_table *src, bool
safe)
state. */
data = bucket->data;
bucket->next = NULL;
- if (safe)
- continue;
+ if (!safe)
+ {
new_bucket = safe_hasher (dst, data);
if (new_bucket->data)
@@ -766,6 +766,7 @@ transfer_entries (Hash_table *dst, Hash_table *src, bool
safe)
bucket->data = NULL;
src->n_buckets_used--;
}
+ }
return true;
}
diff --git a/lib/inet_pton.c b/lib/inet_pton.c
index e096eb341b..d891cd0a60 100644
--- a/lib/inet_pton.c
+++ b/lib/inet_pton.c
@@ -199,9 +199,8 @@ inet_pton6 (const char *restrict src, unsigned char
*restrict dst)
if (val > 0xffff)
return (0);
saw_xdigit = 1;
- continue;
}
- if (ch == ':')
+ else if (ch == ':')
{
curtok = src;
if (!saw_xdigit)
@@ -209,27 +208,29 @@ inet_pton6 (const char *restrict src, unsigned char
*restrict dst)
if (colonp)
return (0);
colonp = tp;
- continue;
}
else if (*src == '\0')
{
return (0);
}
- if (tp + NS_INT16SZ > endp)
+ else if (tp + NS_INT16SZ > endp)
return (0);
+ else
+ {
*tp++ = (unsigned char) (val >> 8) & 0xff;
*tp++ = (unsigned char) val & 0xff;
saw_xdigit = 0;
val = 0;
- continue;
}
- if (ch == '.' && ((tp + NS_INADDRSZ) <= endp) &&
+ }
+ else if (ch == '.' && ((tp + NS_INADDRSZ) <= endp) &&
inet_pton4 (curtok, tp) > 0)
{
tp += NS_INADDRSZ;
saw_xdigit = 0;
break; /* '\0' was seen by inet_pton4(). */
}
+ else
return (0);
}
if (saw_xdigit)
diff --git a/lib/mountlist.c b/lib/mountlist.c
index 963dc7b6f1..aa5d70ec01 100644
--- a/lib/mountlist.c
+++ b/lib/mountlist.c
@@ -495,37 +495,31 @@ read_file_system_list (bool need_fs_type)
&devmaj, &devmin,
&mntroot_s);
- if (rc != 2 && rc != 3) /* 3 if %n included in count. */
- continue;
-
+ if (rc == 2 || rc == 3) /* 3 if %n included in count. */
+ {
/* find end of MNTROOT. */
char *mntroot = line + mntroot_s;
char *blank = terminate_at_blank (mntroot);
- if (! blank)
- continue;
-
+ if (blank)
+ {
/* find end of TARGET. */
char *target = blank + 1;
blank = terminate_at_blank (target);
- if (! blank)
- continue;
-
+ if (blank)
+ {
/* skip optional fields, terminated by " - " */
char *dash = strstr (blank + 1, " - ");
- if (! dash)
- continue;
-
+ if (dash)
+ {
/* advance past the " - " separator. */
char *fstype = dash + 3;
blank = terminate_at_blank (fstype);
- if (! blank)
- continue;
-
+ if (blank)
+ {
/* find end of SOURCE. */
char *source = blank + 1;
- if (! terminate_at_blank (source))
- continue;
-
+ if (terminate_at_blank (source))
+ {
/* manipulate the sub-strings in place. */
unescape_tab (source);
unescape_tab (target);
@@ -551,6 +545,12 @@ read_file_system_list (bool need_fs_type)
*mtail = me;
mtail = &me->me_next;
}
+ }
+ }
+ }
+ }
+ }
+ }
free (line);
@@ -695,9 +695,8 @@ read_file_system_list (bool need_fs_type)
char *name;
struct stat statbuf;
- if (streq (d->d_name, ".."))
- continue;
-
+ if (! streq (d->d_name, ".."))
+ {
if (streq (d->d_name, "."))
name = xstrdup ("/");
else
@@ -721,6 +720,7 @@ read_file_system_list (bool need_fs_type)
else
free (name);
}
+ }
closedir (dirp);
}
*rootdir_tail = NULL;
diff --git a/lib/poll.c b/lib/poll.c
index 0794ad0d6f..ef1b92c3ae 100644
--- a/lib/poll.c
+++ b/lib/poll.c
@@ -417,8 +417,8 @@ poll (struct pollfd *pfd, nfds_t nfd, int timeout)
FD_ZERO (&efds);
for (int i = 0; i < nfd; i++)
{
- if (pfd[i].fd < 0)
- continue;
+ if (pfd[i].fd >= 0)
+ {
if (maxfd < pfd[i].fd)
{
maxfd = pfd[i].fd;
@@ -438,6 +438,7 @@ poll (struct pollfd *pfd, nfds_t nfd, int timeout)
if (pfd[i].events & (POLLPRI | POLLRDBAND))
FD_SET (pfd[i].fd, &efds);
}
+ }
/* examine fd sets */
rc = select (maxfd + 1, &rfds, &wfds, &efds, ptv);
@@ -488,12 +489,10 @@ restart:
{
int sought = pfd[i].events;
pfd[i].revents = 0;
- if (pfd[i].fd < 0)
- continue;
- if (!(sought & (POLLIN | POLLRDNORM | POLLOUT | POLLWRNORM | POLLWRBAND
+ if (pfd[i].fd >= 0
+ && (sought & (POLLIN | POLLRDNORM | POLLOUT | POLLWRNORM | POLLWRBAND
| POLLPRI | POLLRDBAND)))
- continue;
-
+ {
h = (HANDLE) _get_osfhandle (pfd[i].fd);
assure (h != NULL);
if (IsSocketHandle (h))
@@ -533,6 +532,7 @@ restart:
timeout = 0;
}
}
+ }
if (select (0, &rfds, &wfds, &xfds, &tv0) > 0)
{
@@ -579,12 +579,10 @@ restart:
{
int happened;
- if (pfd[i].fd < 0)
- continue;
- if (!(pfd[i].events & (POLLIN | POLLRDNORM |
+ if (pfd[i].fd >= 0
+ && (pfd[i].events & (POLLIN | POLLRDNORM |
POLLOUT | POLLWRNORM | POLLWRBAND)))
- continue;
-
+ {
h = (HANDLE) _get_osfhandle (pfd[i].fd);
if (h != handle_array[nhandles])
{
@@ -616,6 +614,7 @@ restart:
if ((pfd[i].revents |= happened) != 0)
rc++;
}
+ }
if (!rc && timeout == INFTIM)
{
diff --git a/lib/select.c b/lib/select.c
index 169e1c20a5..88e454b673 100644
--- a/lib/select.c
+++ b/lib/select.c
@@ -319,13 +319,13 @@ rpl_select (int nfds, fd_set *rfds, fd_set *wfds, fd_set
*xfds,
{
fd = rfds->fd_array[i];
h = (HANDLE) _get_osfhandle (fd);
- if (IsConsoleHandle (h)
- && !GetNumberOfConsoleInputEvents (h, &nbuffer))
- continue;
-
+ if (!IsConsoleHandle (h)
+ || GetNumberOfConsoleInputEvents (h, &nbuffer))
+ {
rbits.in[fd / CHAR_BIT] |= 1 << (fd & (CHAR_BIT - 1));
anyfds_in[fd / CHAR_BIT] |= 1 << (fd & (CHAR_BIT - 1));
}
+ }
else
rfds = (fd_set *) alloca (sizeof (fd_set));
@@ -334,13 +334,13 @@ rpl_select (int nfds, fd_set *rfds, fd_set *wfds, fd_set
*xfds,
{
fd = wfds->fd_array[i];
h = (HANDLE) _get_osfhandle (fd);
- if (IsConsoleHandle (h)
- && GetNumberOfConsoleInputEvents (h, &nbuffer))
- continue;
-
+ if (!IsConsoleHandle (h)
+ || !GetNumberOfConsoleInputEvents (h, &nbuffer))
+ {
wbits.in[fd / CHAR_BIT] |= 1 << (fd & (CHAR_BIT - 1));
anyfds_in[fd / CHAR_BIT] |= 1 << (fd & (CHAR_BIT - 1));
}
+ }
else
wfds = (fd_set *) alloca (sizeof (fd_set));
@@ -365,9 +365,8 @@ rpl_select (int nfds, fd_set *rfds, fd_set *wfds, fd_set
*xfds,
/* Classify handles. Create fd sets for sockets, poll the others. */
for (int i = 0; i < nfds; i++)
{
- if ((anyfds_in[i / CHAR_BIT] & (1 << (i & (CHAR_BIT - 1)))) == 0)
- continue;
-
+ if ((anyfds_in[i / CHAR_BIT] & (1 << (i & (CHAR_BIT - 1)))) != 0)
+ {
h = (HANDLE) _get_osfhandle (i);
if (!h)
{
@@ -413,6 +412,7 @@ rpl_select (int nfds, fd_set *rfds, fd_set *wfds, fd_set
*xfds,
wait_timeout = 0;
}
}
+ }
/* Place a sentinel at the end of the array. */
handle_array[nhandles] = NULL;
@@ -480,9 +480,8 @@ restart:
nhandles = 1;
for (int i = 0; i < nfds; i++)
{
- if ((anyfds_in[i / CHAR_BIT] & (1 << (i & (CHAR_BIT - 1)))) == 0)
- continue;
-
+ if ((anyfds_in[i / CHAR_BIT] & (1 << (i & (CHAR_BIT - 1)))) != 0)
+ {
h = (HANDLE) _get_osfhandle (i);
if (h == handle_array[nhandles])
{
@@ -495,6 +494,7 @@ restart:
rc++;
}
}
+ }
if (rc == 0
&& (wait_timeout == INFINITE
@@ -526,9 +526,8 @@ restart:
nhandles = 1;
for (int i = 0; i < nfds; i++)
{
- if ((anyfds_in[i / CHAR_BIT] & (1 << (i & (CHAR_BIT - 1)))) == 0)
- continue;
-
+ if ((anyfds_in[i / CHAR_BIT] & (1 << (i & (CHAR_BIT - 1)))) != 0)
+ {
h = (HANDLE) _get_osfhandle (i);
if (h != handle_array[nhandles])
{
@@ -554,6 +553,7 @@ restart:
FD_SET (i, xfds);
}
}
+ }
return rc;
}
diff --git a/lib/set-permissions.c b/lib/set-permissions.c
index f12168a26d..27f41fde51 100644
--- a/lib/set-permissions.c
+++ b/lib/set-permissions.c
@@ -99,8 +99,8 @@ set_acls_from_mode (const char *name, int desc, mode_t mode,
bool *must_chmod)
errno = ENOMEM;
return -1;
}
- continue;
}
+ else
break;
}
diff --git a/lib/timevar.c b/lib/timevar.c
index 7e9f08728f..90ce8a3363 100644
--- a/lib/timevar.c
+++ b/lib/timevar.c
@@ -320,28 +320,28 @@ timevar_print (FILE *fp)
{
/* Don't print the total execution time here; that goes at the
end. */
- if ((timevar_id_t) id == tv_total)
- continue;
-
+ if ((timevar_id_t) id != tv_total)
+ {
/* Don't print timing variables that were never used. */
struct timevar_def *tv = &timevars[(timevar_id_t) id];
- if (!tv->used)
- continue;
-
+ if (tv->used)
+ {
/* Percentages. */
const int usr = total->user ? tv->elapsed.user * 100 /
total->user : 0;
const int sys = total->sys ? tv->elapsed.sys * 100 / total->sys
: 0;
const int wall = total->wall ? tv->elapsed.wall * 100 /
total->wall : 0;
/* Ignore insignificant lines. */
- if (!usr && !sys && !wall)
- continue;
-
+ if (usr || sys || wall)
+ {
fprintf (fp, " %-22s", tv->name);
fprintf (fp, "%8.3f (%2d%%)", tv->elapsed.user * 1e-9, usr);
fprintf (fp, "%8.3f (%2d%%)", tv->elapsed.sys * 1e-9, sys);
fprintf (fp, "%11.6f (%2d%%)\n", tv->elapsed.wall * 1e-9,
wall);
}
+ }
+ }
+ }
/* Print total time. */
fprintf (fp, " %-22s", timevars[tv_total].name);
diff --git a/lib/wcscasecmp-impl.h b/lib/wcscasecmp-impl.h
index aa3f72ee91..03065ee5c9 100644
--- a/lib/wcscasecmp-impl.h
+++ b/lib/wcscasecmp-impl.h
@@ -22,8 +22,7 @@ wcscasecmp (const wchar_t *s1, const wchar_t *s2)
{
wchar_t wc1 = towlower (*s1++);
wchar_t wc2 = towlower (*s2++);
- if (wc1 != (wchar_t)'\0' && wc1 == wc2)
- continue;
+ if (wc1 == (wchar_t)'\0' || wc1 != wc2)
/* Note that wc1 and wc2 each have at most 31 bits. */
return (int)wc1 - (int)wc2;
/* > 0 if wc1 > wc2, < 0 if wc1 < wc2,
diff --git a/lib/wcscmp-impl.h b/lib/wcscmp-impl.h
index b60424f8fa..3d0870187f 100644
--- a/lib/wcscmp-impl.h
+++ b/lib/wcscmp-impl.h
@@ -22,8 +22,7 @@ wcscmp (const wchar_t *s1, const wchar_t *s2)
{
wchar_t wc1 = *s1++;
wchar_t wc2 = *s2++;
- if (wc1 != (wchar_t)'\0' && wc1 == wc2)
- continue;
+ if (wc1 == (wchar_t)'\0' || wc1 != wc2)
/* ISO C requires wcscmp to work with all wchar_t values.
We cannot assume that wc1 and wc2 are in the range 0..INT_MAX. */
return _GL_CMP (wc1, wc2);
diff --git a/lib/wcsncasecmp-impl.h b/lib/wcsncasecmp-impl.h
index 7cdd9410e2..eb01a7d75f 100644
--- a/lib/wcsncasecmp-impl.h
+++ b/lib/wcsncasecmp-impl.h
@@ -22,15 +22,12 @@ wcsncasecmp (const wchar_t *s1, const wchar_t *s2, size_t n)
{
wchar_t wc1 = towlower (*s1++);
wchar_t wc2 = towlower (*s2++);
- if (wc1 != (wchar_t)'\0' && wc1 == wc2)
- {
- n--;
- continue;
- }
+ if (wc1 == (wchar_t)'\0' || wc1 != wc2)
/* Note that wc1 and wc2 each have at most 31 bits. */
return (int)wc1 - (int)wc2;
/* > 0 if wc1 > wc2, < 0 if wc1 < wc2,
= 0 if wc1 and wc2 are both '\0'. */
+ n--;
}
return 0;
}
diff --git a/lib/wcsncmp-impl.h b/lib/wcsncmp-impl.h
index c65a4bdfde..7204151949 100644
--- a/lib/wcsncmp-impl.h
+++ b/lib/wcsncmp-impl.h
@@ -22,16 +22,13 @@ wcsncmp (const wchar_t *s1, const wchar_t *s2, size_t n)
{
wchar_t wc1 = *s1++;
wchar_t wc2 = *s2++;
- if (wc1 != (wchar_t)'\0' && wc1 == wc2)
- {
- n--;
- continue;
- }
+ if (wc1 == (wchar_t)'\0' || wc1 != wc2)
/* ISO C requires wcsncmp to work with all wchar_t values.
We cannot assume that wc1 and wc2 are in the range 0..INT_MAX. */
return _GL_CMP (wc1, wc2);
/* > 0 if wc1 > wc2, < 0 if wc1 < wc2,
= 0 if wc1 and wc2 are both '\0'. */
+ n--;
}
return 0;
}
diff --git a/lib/wmemcmp-impl.h b/lib/wmemcmp-impl.h
index d33f656f0f..b96e04828a 100644
--- a/lib/wmemcmp-impl.h
+++ b/lib/wmemcmp-impl.h
@@ -22,15 +22,12 @@ wmemcmp (const wchar_t *s1, const wchar_t *s2, size_t n)
{
wchar_t wc1 = *s1++;
wchar_t wc2 = *s2++;
- if (wc1 == wc2)
- {
- n--;
- continue;
- }
+ if (wc1 != wc2)
/* ISO C requires wmemcmp to work with all wchar_t values.
We cannot assume that wc1 and wc2 are in the range 0..INT_MAX. */
return _GL_CMP (wc1, wc2);
/* > 0 if wc1 > wc2, < 0 if wc1 < wc2. */
+ n--;
}
return 0;
}