From: Chris Meyering Date: Thu, 30 Jan 2020 06:34:48 +0000 (-0800) Subject: build: rearrange yes(1) code to prevent GCC 10 warning X-Git-Tag: v8.32~31 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=dda53d75a89c5dda63c51b05c3e9953de471fd4c;p=thirdparty%2Fcoreutils.git build: rearrange yes(1) code to prevent GCC 10 warning * src/yes.c (main): Convert for loop to do-while in order to indicate that the loop will be run at least once. This avoids the following warning after the second loop: src/yes.c:110:20: error: writing 1 byte into a region of size 0 --- diff --git a/src/yes.c b/src/yes.c index e012130654..c357555623 100644 --- a/src/yes.c +++ b/src/yes.c @@ -79,7 +79,8 @@ main (int argc, char **argv) large overhead of stdio buffering each item. */ size_t bufalloc = 0; bool reuse_operand_strings = true; - for (char **operandp = operands; operandp < operand_lim; operandp++) + char **operandp = operands; + do { size_t operand_len = strlen (*operandp); bufalloc += operand_len + 1; @@ -87,6 +88,7 @@ main (int argc, char **argv) && *operandp + operand_len + 1 != operandp[1]) reuse_operand_strings = false; } + while (++operandp < operand_lim); /* Improve performance by using a buffer size greater than BUFSIZ / 2. */ if (bufalloc <= BUFSIZ / 2) @@ -99,7 +101,8 @@ main (int argc, char **argv) the operands strings; this wins when the buffer would be large. */ char *buf = reuse_operand_strings ? *operands : xmalloc (bufalloc); size_t bufused = 0; - for (char **operandp = operands; operandp < operand_lim; operandp++) + operandp = operands; + do { size_t operand_len = strlen (*operandp); if (! reuse_operand_strings) @@ -107,6 +110,7 @@ main (int argc, char **argv) bufused += operand_len; buf[bufused++] = ' '; } + while (++operandp < operand_lim); buf[bufused - 1] = '\n'; /* If a larger buffer was allocated, fill it by repeating the buffer