cleanup: use proper size when allocating string

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
Berthold Stoeger 2024-03-01 23:09:21 +01:00 committed by bstoeger
parent ef5859437a
commit a4091189b0

View file

@ -2261,7 +2261,7 @@ int parse_dlf_buffer(unsigned char *buffer, size_t size, struct divelog *log)
/* Recording the starting battery status to extra data */
if (battery_start.volt1) {
size_t stringsize = snprintf(NULL, 0, "%dmV (%d%%)", battery_start.volt1, battery_start.percent1) + 1;
char *ptr = malloc(size);
char *ptr = malloc(stringsize);
if (ptr) {
snprintf(ptr, stringsize, "%dmV (%d%%)", battery_start.volt1, battery_start.percent1);