fixed -Wformat-overflow compiler warnings / added missing newline to log messages#115
fixed -Wformat-overflow compiler warnings / added missing newline to log messages#115firewave wants to merge 1 commit intotrzy:masterfrom
-Wformat-overflow compiler warnings / added missing newline to log messages#115Conversation
-Wformat-overflow Clang compiler warnings / added missing newline to log messages
8a00f76 to
5858095
Compare
5858095 to
c2f5ed5
Compare
-Wformat-overflow Clang compiler warnings / added missing newline to log messages-Wformat-overflow compiler warnings / added missing newline to log messages
trzy
left a comment
There was a problem hiding this comment.
Please see the attached comments. I don't think the buffer lengths should be touched in Logger.cpp, there is no need for it. Rather, use the safe forms of vsprintf and sprintf (vsnprintf and snprintf). Also, the \n in debug logging was intentionally omitted. It's not a typo.
Src/OSD/Logger.cpp
Outdated
|
|
||
| char string1[4096]; | ||
| char string2[4096]; | ||
| char string2[4105]; // add 8 for the prefix and 1 for newline |
There was a problem hiding this comment.
These are not needed. 4096 was chosen somewhat arbitrarily. We don't actually check the size of the resulting output. If you want to fix this, you should instead prefer to use vsnprintf() and pass 4096 as the "n" parameter. Likewise, sprintf -> snprintf.
There was a problem hiding this comment.
Okay. I moved back to the original buffer length and use *snprintf() now.
Src/OSD/Logger.cpp
Outdated
|
|
||
| vsprintf(string1, fmt, vl); | ||
| sprintf(string2, "[Debug] %s", string1); | ||
| sprintf(string2, "[Debug] %s\n", string1); |
There was a problem hiding this comment.
This newline is actually incorrect. DebugLog is special and you'll notice wherever it is used in Supermodel, a \n is manually included. The intent behind this was to allow formatting debug output more freely with multiple calls to generate a single line if needed. However, now that the [Debug] tag has been added, it may be worthwhile to automatically include a \n but if this is done, all places where DebugLog is used must be updated to drop their \n.
Src/OSD/Logger.cpp
Outdated
|
|
||
| vsprintf(string1, fmt, vl); | ||
| sprintf(string2, "[Debug] %s", string1); | ||
| sprintf(string2, "[Debug] %s\n", string1); |
| // Set the video mode | ||
| char baseTitleStr[128]; | ||
| char titleStr[128]; | ||
| char titleStr[256]; |
There was a problem hiding this comment.
This change is fine, I suppose. Does anything actually exceed 128 bytes? We should probably also move to using snprintf() for safety here.
There was a problem hiding this comment.
As it appends up to 128 bytes from baseTitleStr in that string it needs to be at least 128 + n.
Src/OSD/SDL/Main.cpp:1086:30: warning: ‘ (Paused)’ directive writing 9 bytes into a region of size between 1 and 128 [-Wformat-overflow=]
1086 | sprintf(titleStr, "%s (Paused)", baseTitleStr);
| ^~~~~~~~~
Src/OSD/SDL/Main.cpp:1086:16: note: ‘sprintf’ output between 10 and 137 bytes into a destination of size 128
1086 | sprintf(titleStr, "%s (Paused)", baseTitleStr);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
Will you be able to make the suggested changes? |
Yes. Hopefully I finally get to it this week. |
c2f5ed5 to
640aeda
Compare
4042cdd to
afe8ddf
Compare
|
There are additional warnings now but I cannot change that file because there are some issues with the line endings. |
afe8ddf to
075bfa2
Compare
Some examples for reference: