string.find returns results when it should not: x=4294967295 Found:a test x=4294967294 Found:a test x=4294967293 Found:a test x=4294967292 Not found x=4294967291 Not found x=4294967290 Not found x=4294967289 Not found x=4294967288 Not found x=4294967287 Not found x=4294967286 Not found
Also happens on gcc4.1.2 FreeBSD gcc2.95.2 Unixware 7.1 and gcc4.1.1 Linux 64 [~]$ g++ -v --save-temps -Wall -ansi -pedantic str3.cpp Using built-in specs. Target: i386-redhat-linux Configured with: ../configure --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --enable-shared --enable-threads=posix --enable-checking=release --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-libgcj-multifile --enable-languages=c,c++,objc,obj-c++,java,fortran,ada --enable-java-awt=gtk --disable-dssi --enable-plugin --with-java-home=/usr/lib/jvm/java-1.4.2-gcj-1.4.2.0/jre --with-cpu=generic --host=i386-redhat-linux Thread model: posix gcc version 4.1.1 20070105 (Red Hat 4.1.1-52) /usr/libexec/gcc/i386-redhat-linux/4.1.1/cc1plus -E -quiet -v -D_GNU_SOURCE str3.cpp -mtune=generic -ansi -Wall -pedantic -fpch-preprocess -o str3.ii ignoring nonexistent directory "/usr/lib/gcc/i386-redhat-linux/4.1.1/../../../../i386-redhat-linux/include" #include "..." search starts here: #include <...> search starts here: /usr/lib/gcc/i386-redhat-linux/4.1.1/../../../../include/c++/4.1.1 /usr/lib/gcc/i386-redhat-linux/4.1.1/../../../../include/c++/4.1.1/i386-redhat-linux /usr/lib/gcc/i386-redhat-linux/4.1.1/../../../../include/c++/4.1.1/backward /usr/local/include /usr/lib/gcc/i386-redhat-linux/4.1.1/include /usr/include End of search list. /usr/libexec/gcc/i386-redhat-linux/4.1.1/cc1plus -fpreprocessed str3.ii -quiet -dumpbase str3.cpp -mtune=generic -ansi -auxbase str3 -Wall -pedantic -ansi -version -o str3.s GNU C++ version 4.1.1 20070105 (Red Hat 4.1.1-52) (i386-redhat-linux) compiled by GNU C version 4.1.1 20070105 (Red Hat 4.1.1-52). GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072 Compiler executable checksum: aa6f91b930c2d3bef702d56afc079b20 as -V -Qy -o str3.o str3.s GNU assembler version 2.17.50.0.6-2.el5 (i386-redhat-linux) using BFD version 2.17.50.0.6-2.el5 20061020 /usr/libexec/gcc/i386-redhat-linux/4.1.1/collect2 --eh-frame-hdr -m elf_i386 --hash-style=gnu -dynamic-linker /lib/ld-linux.so.2 /usr/lib/gcc/i386-redhat-linux/4.1.1/../../../crt1.o /usr/lib/gcc/i386-redhat-linux/4.1.1/../../../crti.o /usr/lib/gcc/i386-redhat-linux/4.1.1/crtbegin.o -L/usr/lib/gcc/i386-redhat-linux/4.1.1 -L/usr/lib/gcc/i386-redhat-linux/4.1.1 -L/usr/lib/gcc/i386-redhat-linux/4.1.1/../../.. str3.o -lstdc++ -lm -lgcc_s -lgcc -lc -lgcc_s -lgcc /usr/lib/gcc/i386-redhat-linux/4.1.1/crtend.o /usr/lib/gcc/i386-redhat-linux/4.1.1/../../../crtn.o #include <iostream> #include <string> #include <climits> int main(int argc, char *argv[]) { std::string a("this is a test"); std::string b("a t"); for(unsigned long x=ULONG_MAX; x>ULONG_MAX-10; --x) { std::string::size_type y=a.find(b, x); if(y==std::string::npos) { std::cout << "x=" << x << " Not found\n"; } else { std::cout << "x=" << x << " Found:" << a.substr(y) << std::endl; } } return 0; } -- Summary: std::string.find(x, std::string::npos) searchs from begining of string Product: gcc Version: 4.1.1 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: gnu at bluedreamer dot com http://gcc.gnu.org/bugzilla/show_bug.cgi?id=32730