Skip to content

Commit de77525

Browse files
authored
Fix an snprintf warning in H5match_types.c (#5825)
gcc complains about writing too many characters into a buffer since we're writing from a 2D array. This limits the output and quiets the warnings.
1 parent 0a73bd9 commit de77525

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

fortran/src/H5match_types.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,7 @@ main(void)
152152
int RealKinds[] = H5_FORTRAN_REAL_KINDS;
153153
int RealKinds_SizeOf[] = H5_FORTRAN_REAL_KINDS_SIZEOF;
154154
char Real_C_TYPES[10][32];
155+
int Real_C_TYPES_Y = 31; /* Has to match second dimension of Real_C_TYPES - 1 */
155156

156157
int FORTRAN_NUM_INTEGER_KINDS = H5_FORTRAN_NUM_INTEGER_KINDS;
157158
int H5_FORTRAN_NUM_REAL_KINDS;
@@ -357,8 +358,9 @@ main(void)
357358

358359
for (i = 0; i < H5_FORTRAN_NUM_REAL_KINDS; i++) {
359360
if (RealKinds[i] > 0) {
360-
snprintf(chrA, sizeof(chrA), "Fortran_REAL_%s", Real_C_TYPES[i]);
361-
snprintf(chrB, sizeof(chrB), "real_%s_f", Real_C_TYPES[i]);
361+
/* Limit snprintf to Real_C_TYPES_Y characters to quiet warnings */
362+
snprintf(chrA, sizeof(chrA), "Fortran_REAL_%.*s", Real_C_TYPES_Y, Real_C_TYPES[i]);
363+
snprintf(chrB, sizeof(chrB), "real_%.*s_f", Real_C_TYPES_Y, Real_C_TYPES[i]);
362364
writeToFiles("float", chrA, chrB, RealKinds[i]);
363365
}
364366
}

0 commit comments

Comments
 (0)