This patch to the Go frontend increases the size of a temporary buffer
to avoid a new warning.  The warning was breaking bootstrapping with
Go.

GCC has a new -Wformat-truncation warning that triggers on some Go
frontend 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.  This patch
bumps the buffer size to avoid the warning.

This fixes https://gcc.gnu.org/PR117833.

Bootstrapped and ran Go testsuite on x86_64-pc-linux-gnu.  Committed
to mainline.

Ian
1021933a9ff6e15e982c858766c90cc8e58a103a
diff --git a/gcc/go/gofrontend/MERGE b/gcc/go/gofrontend/MERGE
index 59badf80f40..3bd755ce515 100644
--- a/gcc/go/gofrontend/MERGE
+++ b/gcc/go/gofrontend/MERGE
@@ -1,4 +1,4 @@
-f9ea9801058aa98a421784da12b76cda0b4c6cf2
+dfe585bf82380630697e96c249de825c5f655afe
 
 The first line of this file holds the git revision number of the last
 merge done from the gofrontend repository.
diff --git a/gcc/go/gofrontend/go-encode-id.cc 
b/gcc/go/gofrontend/go-encode-id.cc
index 7ab65f513b3..5c82aa74533 100644
--- a/gcc/go/gofrontend/go-encode-id.cc
+++ b/gcc/go/gofrontend/go-encode-id.cc
@@ -172,7 +172,7 @@ go_encode_id(const std::string &id)
                }
              else
                {
-                 char buf[8];
+                 char buf[16];
                  snprintf(buf, sizeof buf, "_x%02x", c);
                  ret.append(buf);
                }

Reply via email to