diff options
author | Berthold Stoeger <bstoeger@mail.tuwien.ac.at> | 2018-01-04 09:18:46 +0100 |
---|---|---|
committer | Lubomir I. Ivanov <neolit123@gmail.com> | 2018-01-05 00:29:20 +0100 |
commit | c4c57b287e7c3c284139c1868646e3d6c27e6aff (patch) | |
tree | 36775f8342a280289cf8c2e8482fe766f7b4b68a /core/libdivecomputer.c | |
parent | 90ba4e5dcad7add798986e493c9b8972bdaf43fe (diff) | |
download | subsurface-c4c57b287e7c3c284139c1868646e3d6c27e6aff.tar.gz |
Increase size of name_buffer to fit any integer
In libdivecomputer.c, name_buffer is formatted with calls like
snprintf(name_buffer, 9, "%d cuft", rounded_size);
This works fine in the regular case, but it generates compiler
warnings, since theoretically the integer might produce up to
11 digits, leading to a truncation of the string.
Increasing the size of name_buffer to 17 chars silences these
warnings. This may seem like pointless warning-silencing.
Nevertheless, in the case of invalid data, it might make debugging
easier since, in the above case, the "cuft" is never truncated.
In total, it seems that this is a benign change with potential,
though in a very unlikely case, positive effects.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Diffstat (limited to 'core/libdivecomputer.c')
-rw-r--r-- | core/libdivecomputer.c | 12 |
1 files changed, 6 insertions, 6 deletions
diff --git a/core/libdivecomputer.c b/core/libdivecomputer.c index 70b747114..75cb0ce4c 100644 --- a/core/libdivecomputer.c +++ b/core/libdivecomputer.c @@ -175,25 +175,25 @@ static int parse_gasmixes(device_data_t *devdata, struct dive *dive, dc_parser_t * for cuft sizes (as that's all that you can enter) */ dive->cylinder[i].type.workingpressure.mbar = lrint( dive->cylinder[i].type.workingpressure.mbar * 206.843 / 206.7 ); - char name_buffer[9]; + char name_buffer[17]; int rounded_size = lrint(ml_to_cuft(gas_volume(&dive->cylinder[i], dive->cylinder[i].type.workingpressure))); rounded_size = (int)((rounded_size + 5) / 10) * 10; switch (dive->cylinder[i].type.workingpressure.mbar) { case 206843: - snprintf(name_buffer, 9, "AL%d", rounded_size); + snprintf(name_buffer, sizeof(name_buffer), "AL%d", rounded_size); break; case 234422: /* this is wrong - HP tanks tend to be 3440, but Suunto only allows 3400 */ - snprintf(name_buffer, 9, "HP%d", rounded_size); + snprintf(name_buffer, sizeof(name_buffer), "HP%d", rounded_size); break; case 179263: - snprintf(name_buffer, 9, "LP+%d", rounded_size); + snprintf(name_buffer, sizeof(name_buffer), "LP+%d", rounded_size); break; case 165474: - snprintf(name_buffer, 9, "LP%d", rounded_size); + snprintf(name_buffer, sizeof(name_buffer), "LP%d", rounded_size); break; default: - snprintf(name_buffer, 9, "%d cuft", rounded_size); + snprintf(name_buffer, sizeof(name_buffer), "%d cuft", rounded_size); break; } dive->cylinder[i].type.description = copy_string(name_buffer); |