public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
From: Stefan Liebler <stli@linux.ibm.com>
To: GNU C Library <libc-alpha@sourceware.org>
Subject: Question regarding gcc 12 Werror=stringop-overflow in iconv/loop.c
Date: Wed, 27 Apr 2022 16:55:01 +0200	[thread overview]
Message-ID: <7f96a24c-86c7-1fb9-7820-1e27bce6cd56@linux.ibm.com> (raw)

Hi,

with GCC 12, when building with -O3 I'm getting this werror on s390x
when compiling sysdeps/s390/utf8-utf16-z9.c:
../iconv/loop.c: In function ‘__from_utf8_loop_etf3eh_single’:
../iconv/loop.c:445:22: error: writing 1 byte into a region of size 0
[-Werror=stringop-overflow=]
  445 |     bytebuf[inlen++] = *inptr++;
      |     ~~~~~~~~~~~~~~~~~^~~~~~~~~~
../iconv/loop.c:381:17: note: at offset 4 into destination object
‘bytebuf’ of size 4
  381 |   unsigned char bytebuf[MAX_NEEDED_INPUT];
      |                 ^~~~~~~
../iconv/loop.c:445:22: error: writing 1 byte into a region of size 0
[-Werror=stringop-overflow=]
  445 |     bytebuf[inlen++] = *inptr++;
      |     ~~~~~~~~~~~~~~~~~^~~~~~~~~~
../iconv/loop.c:381:17: note: at offset 5 into destination object
‘bytebuf’ of size 4
  381 |   unsigned char bytebuf[MAX_NEEDED_INPUT];
      |                 ^~~~~~~

In this case MAX_NEEDED_INPUT is 4.
I can silence the warning if I use a while-loop in loop.c:
  while (inlen < MAX_NEEDED_INPUT && inptr < inend)
    bytebuf[inlen++] = *inptr++;
instead of the do-while-loop.

But then I'm get an werror with GCC 11.2 in iconvdata/gbgbk.c.

Is there a guarantee that (inptr < inend) is always met?
Then extending the unreachable-case above the loop would silence the
werrors in both files:
if (inlen >= MAX_NEEDED_INPUT || inptr >= inend)
    /* Avoid a -Wstringop-overflow= warning when this loop is
       unrolled.  The compiler cannot otherwise see that this is
       unreachable because it depends on (state->__count & 7) not
       being too large after a previous conversion step.  */
    __builtin_unreachable ();


Otherwise an extra check above the loop like this, would also silence
the werrors in both files:
  if (inptr >= inend)
    return __GCONV_INCOMPLETE_INPUT;

Thanks in advance for any help and hints.
Stefan

             reply	other threads:[~2022-04-27 14:55 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-04-27 14:55 Stefan Liebler [this message]
2022-04-27 15:24 ` Florian Weimer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=7f96a24c-86c7-1fb9-7820-1e27bce6cd56@linux.ibm.com \
    --to=stli@linux.ibm.com \
    --cc=libc-alpha@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).