-
Notifications
You must be signed in to change notification settings - Fork 284
Fix over-writing library prologue #5244
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
when linking the cprover library. The default mode for this constructor of stringstream is to over-write the string used in construction, which presumably was not the intention here. Note: until now there wasn't anything too interesting in the prologue except for the string-abstraction define, which was ignored. But we might want more defines in the future.
| std::ostringstream library_text(prologue); | ||
| // the default mode is ios_base::out which means subsequent write to the | ||
| // stream will overwrite the original content | ||
| std::ostringstream library_text(prologue, std::ios_base::ate); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#include <iostream>
#include <sstream>
int main(void) {
std::ostringstream send_help{"SOS"};
send_help << "WAT";
std::cout << send_help.str() << '\n';
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
WAT is the point of this constructor...
A potentially more obvious fix might be
std::ostringstream library_text;
library_text << prologue
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@thk123 In a slightly less humorous note, I can see uses for this (for example, if you need to guarantee some minimum width for the output so you add in a bunch of filler characters to override first), the “wtf” here is that this is the default, which I think few sane people would expect.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
std::ostringstream library_text(prologue);
library_text.seekp(0, library_text.end);
would also work.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
|
Turning it off |
|
And turning it on again |
|
Superseded by #5285 |
when linking the cprover library. The default mode for this constructor of
stringstream is to over-write the string used in construction, which presumably
was not the intention here.
Note: until now there wasn't anything too interesting in the prologue except for
the string-abstraction define, which was ignored. But we might want more defines
in the future.