From Bugzilla Helper: User-Agent: Mozilla/5.0 (X11; U; Linux 2.4.2-2 i686; en-US; 0.7) Gecko/20010316 Description of problem: I had a hard time creating a contrived example of this bug, so here is the actual function in which I originally found the bug... #include <string> #include <iostream> string ObjectName2Filename(string moduleName) { int pos; while((pos = moduleName.find_first_of(':')) >= 0) moduleName.replace(pos, 2, "/"); // return moduleName; //removing this line should cause an error } int main() { cout << ObjectName2Filename("package::Object") << endl; return 0; } How reproducible: Some code does it, some doesn't, but the same piece of code will always give the same result. Steps to Reproduce: 1. Compile the code with GCC. Use -O2 and -Wall if you like, but they won't make a difference. 2. Run it. Actual Results: Code compiled, ran, and segfaulted. I assume the segfault occurred due to the function returning some sort of undefined garbage rather than a string. Strangely, if -O2 was not used, the program would not segfault, but would print a blank line -- still not what it was supposed to do, though. Expected Results: An error or warning indicating the problem. Additional info: If you un-comment the return statement, everything works great. I have a funny way of forgetting return statements sometimes, and random segfaults (which usually occur later on in the code) don't help me find my mistake. :) Then again, the bug has made me get used to doing personal code reviews, so some good has come of it. :) I am using gcc 2.96-85.
This has been fixed in G++ 3.0 with http://gcc.gnu.org/ml/gcc-patches/2000-10/msg00115.html and a bunch of follow-up patches. But I don't feel safely about adding them in now, because it could destabilize the compiler.