Commit 32f36685 authored by Matthieu Schaller's avatar Matthieu Schaller
Browse files

Merge branch 'gcc8_fix' into 'master'

Fix some warnings reported by GCC 8.1 regarding string manipulations.

See merge request !568
parents 7c44c0bb 6faf3132
......@@ -220,7 +220,10 @@ void restart_read_blocks(void *ptr, size_t size, size_t nblocks, FILE *stream,
errstr, head.len, nblocks * size);
/* Return label, if required. */
if (label != NULL) strncpy(label, head.label, LABLEN);
if (label != NULL) {
head.label[LABLEN] = '\0';
strncpy(label, head.label, LABLEN+1);
}
nread = fread(ptr, size, nblocks, stream);
if (nread != nblocks)
......
......@@ -485,7 +485,7 @@ float units_general_a_factor(const struct unit_system* us,
void units_general_cgs_conversion_string(char* buffer,
const struct unit_system* us,
const float baseUnitsExponants[5]) {
char temp[14];
char temp[20];
const double a_exp = units_general_a_factor(us, baseUnitsExponants);
const double h_exp = units_general_h_factor(us, baseUnitsExponants);
......@@ -518,7 +518,7 @@ void units_general_cgs_conversion_string(char* buffer,
sprintf(temp, "h^%d ", (int)h_exp);
else
sprintf(temp, "h^%7.4f ", h_exp);
strncat(buffer, temp, 12);
strcat(buffer, temp);
/* Add conversion units */
for (int i = 0; i < 5; ++i)
......@@ -536,11 +536,11 @@ void units_general_cgs_conversion_string(char* buffer,
sprintf(temp, "%s^%7.4f ",
units_get_base_unit_internal_symbol((enum base_units)i),
baseUnitsExponants[i]);
strncat(buffer, temp, 12);
strcat(buffer, temp);
}
/* Add CGS units */
strncat(buffer, " [ ", 3);
strcat(buffer, " [ ");
for (int i = 0; i < 5; ++i) {
if (baseUnitsExponants[i] != 0) {
......@@ -557,11 +557,11 @@ void units_general_cgs_conversion_string(char* buffer,
sprintf(temp, "%s^%7.4f ",
units_get_base_unit_cgs_symbol((enum base_units)i),
baseUnitsExponants[i]);
strncat(buffer, temp, 12);
strcat(buffer, temp);
}
}
strncat(buffer, "]", 2);
strcat(buffer, "]");
}
/**
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment