https://gcc.gnu.org/bugzilla/show_bug.cgi?id=117833

--- Comment #8 from GCC Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Ian Lance Taylor <i...@gcc.gnu.org>:

https://gcc.gnu.org/g:ed712cfe2e826cd846705defb1f6ae391baecb3d

commit r15-5808-ged712cfe2e826cd846705defb1f6ae391baecb3d
Author: Ian Lance Taylor <i...@golang.org>
Date:   Thu Nov 28 13:14:34 2024 -0800

    compiler: increase buffer size to avoid warning

    GCC has a new -Wformat-truncation warning that triggers on this code:

    ../../gcc/go/gofrontend/go-encode-id.cc: In function 'std::string
go_encode_id(const std::string&)':
    ../../gcc/go/gofrontend/go-encode-id.cc:176:48: error: '%02x' directive
output may be truncated writing between 2 and 8 bytes into a region of size 6
[-Werror=format-truncation=]
      176 |                   snprintf(buf, sizeof buf, "_x%02x", c);
          |                                                ^~~~
    ../../gcc/go/gofrontend/go-encode-id.cc:176:45: note: directive argument in
the range [128, 4294967295]
      176 |                   snprintf(buf, sizeof buf, "_x%02x", c);
          |                                             ^~~~~~~~
    ../../gcc/go/gofrontend/go-encode-id.cc:176:27: note: 'snprintf' output
between 5 and 11 bytes into a destination of size 8
      176 |                   snprintf(buf, sizeof buf, "_x%02x", c);
          |                   ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    The code is safe, because the value of c is known to be >= 0 && <= 0xff.
    But it's difficult for the compiler to know that.
    Bump the buffer size to avoid the warning.

    Fixes PR go/117833

    Reviewed-on: https://go-review.googlesource.com/c/gofrontend/+/632455

Reply via email to