This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug c/33167] New: Hex constant characters with \x escape not parsing correctly


There seems to be a problem with how gcc parses the \x escape sequences.  It
doesn't look at just the first 2 hex digits, but will take the right most 2 hex
digits in a string of hex digits.  

[Recreate]
---------------[ SNIP ]---------------------
// test.c
#include <stdio.h>
#include <string.h>

int main() {
        char *string = "\x01\x02\x03Bob";
        printf("len: %d\n",  strlen(string) );
        return 1;
}
---------------[ SNIP ]---------------------

[Compilation options]
gcc -Wall test.c -o test

[Expected Results]
You would expect this to print out "len: 6", but it actually prints out "len:
5" It seems that its parsing the last \x escape as the hex value 0x3B instead
of 2 characters, 0x03 and 'B'.

[Platforms]
I've noticed this problem in gcc 4.1.0 and 4.0.1 (on a mac).  Heres more info
on one of the systems I've experiences this on:

gcc (GCC) 4.1.0 (SUSE Linux)
Using built-in specs.
Target: i586-suse-linux
Configured with: ../configure --enable-threads=posix --prefix=/usr
--with-local-prefix=/usr/local --infodir=/usr/share/info
--mandir=/usr/share/man --libdir=/usr/lib --libexecdir=/usr/lib
--enable-languages=c,c++,objc,fortran,java,ada --enable-checking=release
--with-gxx-include-dir=/usr/include/c++/4.1.0 --enable-ssp --disable-libssp
--enable-java-awt=gtk --enable-gtk-cairo --disable-libjava-multilib
--with-slibdir=/lib --with-system-zlib --enable-shared --enable-__cxa_atexit
--enable-libstdcxx-allocator=new --without-system-libunwind --with-cpu=generic
--host=i586-suse-linux
Thread model: posix
gcc version 4.1.0 (SUSE Linux)

$ uname -a
linux haldol 2.6.16.13-4-default #1 Wed May 3 04:53:23 UTC 2006 i686 athlon
i386 GNU/Linux


-- 
           Summary: Hex constant characters with \x escape not parsing
                    correctly
           Product: gcc
           Version: 4.1.0
            Status: UNCONFIRMED
          Severity: minor
          Priority: P3
         Component: c
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: weston at computer dot org
 GCC build triplet: i586-suse-linux
  GCC host triplet: i586-suse-linux
GCC target triplet: i586-suse-linux


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]