public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/57707] New: gcc misinterprets hex escapes in constant strings
@ 2013-06-25 12:05 duncan_roe at acslink dot net.au
  2013-06-25 12:15 ` [Bug c/57707] " schwab@linux-m68k.org
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: duncan_roe at acslink dot net.au @ 2013-06-25 12:05 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 57707
           Summary: gcc misinterprets hex escapes in constant strings
           Product: gcc
           Version: 4.7.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: duncan_roe at acslink dot net.au

Created attachment 30360
  --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=30360&action=edit
Preprocessed program source (only has builtins)

This short self contained program
=============================
int write(int fd, const void *buf, int count);
int main(int argc, char **argv)
{
  write(1, "\x05CAT\nXXXX", 5);
  //write(1, "\x05" "CAT\nXXXX", 5);  // Works
  write(1, "\x05HAT\nXXXX", 5);
  return 0;
}                                  /* main(int argc, char **argv) */
=============================
should print:
control-E CAT
control-E HAT
But it prints:
Meta-JT
XX Control-E HAT
(with no spaces). Meta-J is 0XCA - the compiler has processed all legal hex
characters following "0x" when it should have stopped after 2.
4.7.1 does issue a warning but I submit the warning is wrong - K&R2 says on
page 38 that hex constants in strings are 0xhh.
Run through "cat -A" so you see the control characters:
=============================
21:35:03$ ./hexbug | cat -A
M-JT$
XX^EHAT$
=============================
This is gcc -v -save-temps ...
=============================
Script started on Tue 25 Jun 2013 09:33:06 PM EST
21:33:06$ gcc -v -save-temps -Wall -Wextra -g3 -ggdb 'hexbug.c' -o hexbug
Reading specs from /usr/lib/gcc/i486-slackware-linux/4.7.1/specs
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/libexec/gcc/i486-slackware-linux/4.7.1/lto-wrapper
Target: i486-slackware-linux
Configured with: ../gcc-4.7.1/configure --prefix=/usr --libdir=/usr/lib
--mandir=/usr/man --infodir=/usr/info --enable-shared --enable-bootstrap
--enable-languages=ada,c,c++,fortran,go,java,lto,objc --enable-threads=posix
--enable-checking=release --enable-objc-gc --with-system-zlib
--with-python-dir=/lib/python2.7/site-packages --disable-libunwind-exceptions
--enable-__cxa_atexit --enable-libssp --enable-lto --with-gnu-ld --verbose
--enable-java-home --with-java-home=/usr/lib/jvm/jre
--with-jvm-root-dir=/usr/lib/jvm --with-jvm-jar-dir=/usr/lib/jvm/jvm-exports
--with-arch-directory=i386
--with-antlr-jar=/root/slackware-current/source/d/gcc/antlr-runtime-3.4.jar
--enable-java-awt=gtk --disable-gtktest --with-arch=i486
--target=i486-slackware-linux --build=i486-slackware-linux
--host=i486-slackware-linux
Thread model: posix
gcc version 4.7.1 (GCC) 
COLLECT_GCC_OPTIONS='-v' '-save-temps' '-Wall' '-Wextra' '-g3' '-ggdb' '-o'
'hexbug' '-mtune=i486' '-march=i486'
 /usr/libexec/gcc/i486-slackware-linux/4.7.1/cc1 -E -quiet -v -dD hexbug.c
-mtune=i486 -march=i486 -Wall -Wextra -g3 -ggdb -fworking-directory
-fpch-preprocess -o hexbug.i
ignoring nonexistent directory
"/usr/lib/gcc/i486-slackware-linux/4.7.1/../../../../i486-slackware-linux/include"
#include "..." search starts here:
#include <...> search starts here:
 /usr/lib/gcc/i486-slackware-linux/4.7.1/include
 /usr/local/include
 /usr/lib/gcc/i486-slackware-linux/4.7.1/include-fixed
 /usr/include
End of search list.
COLLECT_GCC_OPTIONS='-v' '-save-temps' '-Wall' '-Wextra' '-g3' '-ggdb' '-o'
'hexbug' '-mtune=i486' '-march=i486'
 /usr/libexec/gcc/i486-slackware-linux/4.7.1/cc1 -fpreprocessed hexbug.i -quiet
-dumpbase hexbug.c -mtune=i486 -march=i486 -auxbase hexbug -g3 -ggdb -Wall
-Wextra -version -o hexbug.s
GNU C (GCC) version 4.7.1 (i486-slackware-linux)
        compiled by GNU C version 4.7.1, GMP version 5.0.5, MPFR version 3.1.0,
MPC version 0.8.2
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
GNU C (GCC) version 4.7.1 (i486-slackware-linux)
        compiled by GNU C version 4.7.1, GMP version 5.0.5, MPFR version 3.1.0,
MPC version 0.8.2
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
Compiler executable checksum: 147333b4f444708024f96128dde54444
hexbug.c: In function 'main':
hexbug.c:8:12: warning: hex escape sequence out of range [enabled by default]
hexbug.c:6:14: warning: unused parameter 'argc' [-Wunused-parameter]
hexbug.c:6:27: warning: unused parameter 'argv' [-Wunused-parameter]
COLLECT_GCC_OPTIONS='-v' '-save-temps' '-Wall' '-Wextra' '-g3' '-ggdb' '-o'
'hexbug' '-mtune=i486' '-march=i486'

/usr/lib/gcc/i486-slackware-linux/4.7.1/../../../../i486-slackware-linux/bin/as
-v --32 -o hexbug.o hexbug.s
GNU assembler version 2.22.52.0.2 (i486-slackware-linux) using BFD version
(Linux/GNU Binutils) 2.22.52.0.2.20120424
COMPILER_PATH=/usr/libexec/gcc/i486-slackware-linux/4.7.1/:/usr/libexec/gcc/i486-slackware-linux/4.7.1/:/usr/libexec/gcc/i486-slackware-linux/:/usr/lib/gcc/i486-slackware-linux/4.7.1/:/usr/lib/gcc/i486-slackware-linux/:/usr/lib/gcc/i486-slackware-linux/4.7.1/../../../../i486-slackware-linux/bin/
LIBRARY_PATH=/usr/lib/gcc/i486-slackware-linux/4.7.1/:/usr/lib/gcc/i486-slackware-linux/4.7.1/../../../../i486-slackware-linux/lib/:/usr/lib/gcc/i486-slackware-linux/4.7.1/../../../:/lib/:/usr/lib/
COLLECT_GCC_OPTIONS='-v' '-save-temps' '-Wall' '-Wextra' '-g3' '-ggdb' '-o'
'hexbug' '-mtune=i486' '-march=i486'
 /usr/libexec/gcc/i486-slackware-linux/4.7.1/collect2 --eh-frame-hdr -m
elf_i386 -dynamic-linker /lib/ld-linux.so.2 -o hexbug
/usr/lib/gcc/i486-slackware-linux/4.7.1/../../../crt1.o
/usr/lib/gcc/i486-slackware-linux/4.7.1/../../../crti.o
/usr/lib/gcc/i486-slackware-linux/4.7.1/crtbegin.o
-L/usr/lib/gcc/i486-slackware-linux/4.7.1
-L/usr/lib/gcc/i486-slackware-linux/4.7.1/../../../../i486-slackware-linux/lib
-L/usr/lib/gcc/i486-slackware-linux/4.7.1/../../.. hexbug.o -lgcc --as-needed
-lgcc_s --no-as-needed -lc -lgcc --as-needed -lgcc_s --no-as-needed
/usr/lib/gcc/i486-slackware-linux/4.7.1/crtend.o
/usr/lib/gcc/i486-slackware-linux/4.7.1/../../../crtn.o
21:34:15$ exit
exit

Script done on Tue 25 Jun 2013 09:34:24 PM EST
=============================


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Bug c/57707] gcc misinterprets hex escapes in constant strings
  2013-06-25 12:05 [Bug c/57707] New: gcc misinterprets hex escapes in constant strings duncan_roe at acslink dot net.au
@ 2013-06-25 12:15 ` schwab@linux-m68k.org
  2013-06-25 12:28 ` duncan_roe at acslink dot net.au
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: schwab@linux-m68k.org @ 2013-06-25 12:15 UTC (permalink / raw)
  To: gcc-bugs

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

Andreas Schwab <schwab@linux-m68k.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|---                         |INVALID

--- Comment #1 from Andreas Schwab <schwab@linux-m68k.org> ---
Hex escapes use the longest matching sequence.


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Bug c/57707] gcc misinterprets hex escapes in constant strings
  2013-06-25 12:05 [Bug c/57707] New: gcc misinterprets hex escapes in constant strings duncan_roe at acslink dot net.au
  2013-06-25 12:15 ` [Bug c/57707] " schwab@linux-m68k.org
@ 2013-06-25 12:28 ` duncan_roe at acslink dot net.au
  2013-06-25 13:25 ` duncan_roe at acslink dot net.au
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: duncan_roe at acslink dot net.au @ 2013-06-25 12:28 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #2 from duncan_roe at acslink dot net.au <duncan_roe at acslink dot net.au> ---
I can see it is doing that. Where does the standard say that is correct
behavior?


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Bug c/57707] gcc misinterprets hex escapes in constant strings
  2013-06-25 12:05 [Bug c/57707] New: gcc misinterprets hex escapes in constant strings duncan_roe at acslink dot net.au
  2013-06-25 12:15 ` [Bug c/57707] " schwab@linux-m68k.org
  2013-06-25 12:28 ` duncan_roe at acslink dot net.au
@ 2013-06-25 13:25 ` duncan_roe at acslink dot net.au
  2013-06-25 22:31 ` duncan_roe at acslink dot net.au
  2013-06-25 22:33 ` pinskia at gcc dot gnu.org
  4 siblings, 0 replies; 6+ messages in thread
From: duncan_roe at acslink dot net.au @ 2013-06-25 13:25 UTC (permalink / raw)
  To: gcc-bugs

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

duncan_roe at acslink dot net.au <duncan_roe at acslink dot net.au> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|RESOLVED                    |UNCONFIRMED
         Resolution|INVALID                     |---

--- Comment #3 from duncan_roe at acslink dot net.au <duncan_roe at acslink dot net.au> ---
(Should have changed the status last comment - sorry)


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Bug c/57707] gcc misinterprets hex escapes in constant strings
  2013-06-25 12:05 [Bug c/57707] New: gcc misinterprets hex escapes in constant strings duncan_roe at acslink dot net.au
                   ` (2 preceding siblings ...)
  2013-06-25 13:25 ` duncan_roe at acslink dot net.au
@ 2013-06-25 22:31 ` duncan_roe at acslink dot net.au
  2013-06-25 22:33 ` pinskia at gcc dot gnu.org
  4 siblings, 0 replies; 6+ messages in thread
From: duncan_roe at acslink dot net.au @ 2013-06-25 22:31 UTC (permalink / raw)
  To: gcc-bugs

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

duncan_roe at acslink dot net.au <duncan_roe at acslink dot net.au> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|---                         |FIXED

--- Comment #6 from duncan_roe at acslink dot net.au <duncan_roe at acslink dot net.au> ---
Will look for 6.4.4.4. And try a non-gnu compiler. In the meantime I'll take
your word for it


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Bug c/57707] gcc misinterprets hex escapes in constant strings
  2013-06-25 12:05 [Bug c/57707] New: gcc misinterprets hex escapes in constant strings duncan_roe at acslink dot net.au
                   ` (3 preceding siblings ...)
  2013-06-25 22:31 ` duncan_roe at acslink dot net.au
@ 2013-06-25 22:33 ` pinskia at gcc dot gnu.org
  4 siblings, 0 replies; 6+ messages in thread
From: pinskia at gcc dot gnu.org @ 2013-06-25 22:33 UTC (permalink / raw)
  To: gcc-bugs

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

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         Resolution|FIXED                       |INVALID

--- Comment #7 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
(In reply to duncan_roe@acslink.net.au from comment #5)
> There's no need for that. C is defined in Kernighan & Ritchie's "The C
> Programming Language". They mandate \xhh as a character escape. No mention
> of "except when the next character happens to be a hex digit".

No it is not defined there.  It is defined by the ISO C standard.  The section
6.4.4.4 is where this specific item is defined.


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2013-06-25 22:33 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-06-25 12:05 [Bug c/57707] New: gcc misinterprets hex escapes in constant strings duncan_roe at acslink dot net.au
2013-06-25 12:15 ` [Bug c/57707] " schwab@linux-m68k.org
2013-06-25 12:28 ` duncan_roe at acslink dot net.au
2013-06-25 13:25 ` duncan_roe at acslink dot net.au
2013-06-25 22:31 ` duncan_roe at acslink dot net.au
2013-06-25 22:33 ` pinskia at gcc dot gnu.org

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).