Repository navigation
Compile flag fixes - #114
jpsamper2009 wants to merge 1 commit into
Conversation
| { | ||
| size_t idx = 0; | ||
| size_t end_idx = end - begin; | ||
| size_t end_idx = (size_t)(end - begin); |
There was a problem hiding this comment.
Looking around a bit, I think the basic problem here is that taking the difference between two pointers should be represented by ptrdiff_t, not size_t (in theory, the difference can be negative: https://bytes.com/topic/c/answers/460624-subtracting-pointers-type-use-store-result). While changing to this, you'll probably also have to change the type of idx to match.
| return; | ||
| } | ||
| size_t bytes_it_would_have_written = snprintf( | ||
| size_t bytes_it_would_have_written = (size_t)snprintf( |
There was a problem hiding this comment.
There's actually a few problems here. snprintf is defined to return an integer, because the return value can be negative on failure. So the return value should be stored in an integer. After that, bytes_it_would_have_written should be checked for negative; if it failed, we definitely don't want to continue on and pass bogus sizes around as unsigned. Finally, we would need a cast from int to size_t while passing bytes_it_would_have_written into allocator.allocate() and the lower-down snprintf to avoid the warnings.
| va_copy(args2, args1); | ||
| // first calculate the output string | ||
| size_t bytes_to_be_written = rcutils_vsnprintf(NULL, 0, format_string, args1); | ||
| size_t bytes_to_be_written = (size_t)rcutils_vsnprintf(NULL, 0, format_string, args1); |
There was a problem hiding this comment.
Like in error_handling.c, the return value of rcutils_vsnprintf is actually int, not size_t, since it can fail. The same comments apply about storing in an int, checking for negative, and then casting where it is used.
|
This PR was a for a much older version of the code. I'll close it and readdress with a newer version (if the issues still exist). |
Description