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.
Both Output and BoutException now use a static const int BUFFER_LEN to control the length of the buffer used for C style output.
Conflicts: src/fileio/datafile.cxx
ZedThree
left a comment
There was a problem hiding this comment.
I think only the ShiftOutput thing definitely needs to be fixed, but the dummy argument is a little concerning.
Also, I'm not sure about the name. Maybe bout_vsnprintf, or something, instead?
src/fileio/datafile.cxx
Outdated
| #include "formatfactory.hxx" | ||
|
|
||
| Datafile::Datafile(Options *opt) : parallel(false), flush(true), guards(true), floats(false), openclose(true), enabled(true), shiftOutput(false), file(NULL) { | ||
| Datafile::Datafile(Options *opt) : parallel(false), flush(true), guards(true), floats(false), openclose(true), enabled(true), file(NULL) { |
There was a problem hiding this comment.
This removes shiftOutput(false) from the initializer list. I assume this is accidental?
include/utils.hxx
Outdated
| /// reallocated. | ||
| /// len: the length of said buffer. May be changed, mussn't be const. | ||
| /// fmt: the const char * descriping the format. | ||
| /// va: A dummy argument. will |
There was a problem hiding this comment.
Is the dummy argument needed? It looks confusing when the macro is called.
There was a problem hiding this comment.
you are right, removed it 👍
| } | ||
|
|
||
| throw BoutException("Error in field: %s", err_buffer); | ||
| delete[] err_buffer; |
There was a problem hiding this comment.
This will never be hit, and presumably leads to a memory leak if the exception isn't caught?
I'm not really sure a) if this is a problem and b) if so, how to fix it.
There was a problem hiding this comment.
This leads to a memory leak, no matter if caught or not. (not caught however doesn't really matter)
b) use std::string
There was a problem hiding this comment.
I added BoutException(std::string) in order to avoid this issue
|
Maybe in future it would be possible to replace all this C stuff with nice C++ idioms? This library looks like a really nice replacement for the |
|
Does "this library" (fmt?) support traditional formatting like |
|
From what I can tell, it supports not only traditional |
|
Only the python format style - python also supports c-printf like statements ...( as the one above, left centered, at least 10 chars, and 3 digits after the point) Update: sorry, I missed 'not only'. |
|
Yep, look at Also, see the SO answer here. Looks like we can do all this in pure C++, but still use I'll have a bash at it tomorrow. |
|
Is this still needed for Also, is it possible that this functionality could be done using C++11 features instead of macros, e.g. |
|
Using variadic templates requires that all this is defined in header files ... I cannot see that this is already fixed in v4 RC: |
|
This would be better than what's there now, but using type safe templates
might be better
…On 28 November 2016 at 16:51, dschwoerer ***@***.***> wrote:
Using variadic templates requires that all this is defined in header files
...
I cannot see that this is already fixed in v4 RC:
https://github.com/boutproject/BOUT-dev/blob/v4.
0.0-RC/src/sys/boutexception.cxx#L80
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#365 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AANYYcBU6wdj4PTd1OuHes-d3n81_6EWks5rCwaQgaJpZM4KoyYc>
.
|
|
To avoid best becoming the enemy of better, I vote we merge this for now, and then look at changing to a C++ solution later. |
|
base changed + conflicts resolved: |
Inlike the PR #319 (the PR for the master branch) this should also work for the derived exceptions.