account for null-terminator character#275
Conversation
|
The doc for snprintf says:
So I don't think this patch is correct. |
|
If you have a suggestion on how to properly handle, I'll happily merge it into this branch. |
|
Since we do want n characters to be written (and not n-1) the patch is changing (and in my opinion breaking) the behavior. If we do rely on truncating the data then the code should explicitly check the return value (in which case I would expect the warning to disappear). |
bc8d18f to
588b974
Compare
|
Thanks @dirk-thomas for the explanation. I modified the patch to actually write all characters provided by the user / test and not n - 1 |
588b974 to
c2d6605
Compare
| size_t step_length = (maxlength - minlength) / size; | ||
| char * tmpstr = reinterpret_cast<char *>(malloc(maxlength)); | ||
| std::snprintf(tmpstr, minlength, "%*d", minlength, min); | ||
| char * tmpstr = reinterpret_cast<char *>(malloc(maxlength + 1)); |
There was a problem hiding this comment.
Unrelated to the patch: this doesn't need a reinterpret_cast - a static_cast would be sufficient and "better" here.
similar to ros2/system_tests#269
Fixes the following warnings: https://ci.ros2.org/job/ci_packaging_linux/92/warnings23Result/package.464043688/
related to ros2/ros2#481