Conversation
Safe version, which guards against buffer overruns by specifying the length of the buffer into which text is being printed. This was used in both Output and BoutException classes to provide C printf-style output.
Missed a couple of instances in BoutException derived classes.
src/sys/boutexception.cxx
Outdated
| char buffer[1024]; | ||
| va_start(ap, s); | ||
| vsprintf(buffer, s, ap); | ||
| vsnprintf(buffer, 1024, s, ap); |
There was a problem hiding this comment.
Can this be a constant too? BoutException::BUFFERLEN?
Both Output and BoutException now use a static const int BUFFER_LEN to control the length of the buffer used for C style output.
|
The return value of |
|
Throwing an exception inside BoutException could end badly. In output I don't think throwing an exception is the best way. These outputs will be mainly used for printing information on a run as it goes, so terminating just because an output couldn't be printed is probably not what the user would want. Possibly allocating more memory, but 1024 characters should be enough for anyone... One question is how fixes like this should be applied to next. Should there be a second branch from next, which would presumably then conflict in any merge, or wait and merge master into next later? |
|
In output, this would only happen if the path of the file, you are trying to open would be longer than whatever. In exception it shouldn't be to much work to reallocate memory ... |
|
With a bit of luck, next will be ready to be merged into master soon-ish. Then, hopefully the development branch and master won't be too far apart, so hotfixes like this can be applied to both at the same time, though that would have to be done from the command line (or with a second PR, I guess?) |
|
Good point about output filenames. Linux has a maximum path length of 4096 characters. Although I'm not sure we want to be allocating that much all the time. |
|
ok, this is used in three places:
The correct fix in "next" would be to use variadic templates for the functions, rather than C vararg. |
|
About 1): seems to me like it would be opening a file, not writing to it. about about 2): about 3) |
Safe version, which guards against buffer overruns
by specifying the length of the buffer into which text
is being printed.
This was used in both Output and BoutException classes
to provide C printf-style output.
This fixes issue #286