[bootstrap-O1] change value type to avoid sprintf buffer size warning
authorAlexandre Oliva <aoliva@redhat.com>
Fri, 6 Jan 2017 03:34:25 +0000 (03:34 +0000)
committerAlexandre Oliva <aoliva@gcc.gnu.org>
Fri, 6 Jan 2017 03:34:25 +0000 (03:34 +0000)
In stage2 of bootstrap-O1, the code that warns if sprintf might
overflow its output buffer cannot tell that an unsigned value narrowed
to 16 bits will fit in 4 bytes with %4x.

Converting the value to 'unsigned short' makes it obvious that it
fits, at least on machines with 16-bit shorts.

for  gcc/c-family/ChangeLog

* c-pretty-print.c (pp_c_tree_decl_identifier): Convert 16-bit
value to unsigned short to fit in 4 hex digits without
warnings.

From-SVN: r244121

gcc/c-family/ChangeLog
gcc/c-family/c-pretty-print.c

index 0e1b4dda006e929bbdb823aa3cb38b2aa0354b2c..375dad193589caad85623e3d7d341b6e6b733c0a 100644 (file)
@@ -1,3 +1,9 @@
+2017-01-06  Alexandre Oliva <aoliva@redhat.com>
+
+       * c-pretty-print.c (pp_c_tree_decl_identifier): Convert 16-bit
+       value to unsigned short to fit in 4 hex digits without
+       warnings.
+
 2017-01-05  Eric Botcazou  <ebotcazou@adacore.com>
 
        * c.opt (fsso-struct): Add 'native' value.
index 813bf1da8af7aa4202ab77c706546d3cde6263a8..5d79519fa7d968a70f839c4996b269a997e0148a 100644 (file)
@@ -2376,7 +2376,8 @@ pp_c_tree_decl_identifier (c_pretty_printer *pp, tree t)
   else
     {
       static char xname[8];
-      sprintf (xname, "<U%4x>", ((unsigned)((uintptr_t)(t) & 0xffff)));
+      sprintf (xname, "<U%4hx>", ((unsigned short) ((uintptr_t) (t)
+                                                   & 0xffff)));
       name = xname;
     }