------- Comment #4 from fxcoudert at gcc dot gnu dot org  2008-05-10 16:02 
-------
(In reply to comment #3)
>       else if (!gfc_wide_is_printable (*p))
>         {
>           sprintf (q, "\\U%08" HOST_WIDE_INT_PRINT "ux",
>                    (unsigned HOST_WIDE_INT) *p);
>           q += 10;
>         }
> 
> "\\U%08" takes 11 bytes, not 10, if you count trailing '\0'.

Yes, but the trailing '\0' will be overwritten with the next character, as it
should be. The issue is really that the format "%08lux" is not valid, it should
simply be "%08lx" (as "x" means unsigned hexadecimal, no need for a "u"). The
most depressing is that I spent quite some time reading the printf man page to
make sure I got it right :(  And it's not seen in other cases, because the x is
overwritten by the next character.

So, the following patch should fix it:

Index: module.c
===================================================================
--- module.c    (revision 135109)
+++ module.c    (working copy)
@@ -1502,7 +1502,7 @@ quote_string (const gfc_char_t *s, const
        *q++ = '\\', *q++ = '\\';
       else if (!gfc_wide_is_printable (*p))
        {
-         sprintf (q, "\\U%08" HOST_WIDE_INT_PRINT "ux",
+         sprintf (q, "\\U%08" HOST_WIDE_INT_PRINT "x",
                   (unsigned HOST_WIDE_INT) *p);
          q += 10;
        }

 (It fixes the valgrind message on x86_64-linux). I'll commit it as obvious as
soon as my regtesting is over.

Now, there is a another problem in that we shouldn't have this wide char in the
first place.


-- 

fxcoudert at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
     Ever Confirmed|0                           |1
   Last reconfirmed|0000-00-00 00:00:00         |2008-05-10 16:02:52
               date|                            |


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=36197

Reply via email to