Skip to content

Conversation

@nlewycky
Copy link

stringstream::str() creates a temporary that is destroyed at the end of the full-expression (the semi-colon), and c_str() on that string returns a pointer internal to the string. This function returns a pointer to freed memory.

Spotted by clang warning:

error.h:51:12: warning: returning address of local temporary object [-Wreturn-stack-address]
    return ss.str().c_str();
           ^~~~~~~~
1 warning generated.

stringstream::str() creates a temporary that is destroyed at the end of the full-expression (the semi-colon), and c_str() on that string returns a pointer internal to the string. This function returns a pointer to freed memory.

Spotted by clang warning:
```
error.h:51:12: warning: returning address of local temporary object [-Wreturn-stack-address]
    return ss.str().c_str();
           ^~~~~~~~
1 warning generated.
```
@nlewycky
Copy link
Author

I think the CodeQL check failure isn't due to this PR:

  Makefile:29: *** STOKE_PLATFORM is not set.  Did you run ./configure.sh?.  Stop.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant