Red Hat Bugzilla – Bug 48094
Lack of return statement not always reported.
Last modified: 2007-04-18 12:34:35 EDT
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...
string ObjectName2Filename(string moduleName)
while((pos = moduleName.find_first_of(':')) >= 0)
moduleName.replace(pos, 2, "/");
// return moduleName; //removing this line should cause an error
cout << ObjectName2Filename("package::Object") << endl;
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.
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.
An error or warning indicating the problem.
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
and a bunch of follow-up patches. But I don't feel safely about adding them
in now, because it could destabilize the compiler.