Bug 48094 - Lack of return statement not always reported.
Lack of return statement not always reported.
Status: CLOSED DEFERRED
Product: Red Hat Linux
Classification: Retired
Component: gcc (Show other bugs)
7.1
i586 Linux
medium Severity low
: ---
: ---
Assigned To: Jakub Jelinek
David Lawrence
:
Depends On:
Blocks:
  Show dependency treegraph
 
Reported: 2001-07-09 13:32 EDT by Kenton Varda
Modified: 2007-04-18 12:34 EDT (History)
0 users

See Also:
Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
Environment:
Last Closed: 2001-07-09 13:32:40 EDT
Type: ---
Regression: ---
Mount Type: ---
Documentation: ---
CRM:
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---


Attachments (Terms of Use)

  None (edit)
Description Kenton Varda 2001-07-09 13:32:37 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...

#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.
Comment 1 Jakub Jelinek 2001-07-25 10:32:39 EDT
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.

Note You need to log in before you can comment on or make changes to this bug.