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>
This commit is contained in:
Berthold Stoeger 2018-01-04 09:18:46 +01:00 committed by Lubomir I. Ivanov
parent 90ba4e5dca
commit c4c57b287e

View file

@ -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);