Fix for gcc-12 warning about string truncation in H5Opline.c (#1835)

This commit is contained in:
Dana Robinson 2022-06-30 07:47:34 -07:00 committed by GitHub
parent 72db748dd9
commit 552833213c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -639,7 +639,6 @@ static herr_t
H5O__pline_debug(H5F_t H5_ATTR_UNUSED *f, const void *mesg, FILE *stream, int indent, int fwidth)
{
const H5O_pline_t *pline = (const H5O_pline_t *)mesg;
size_t i, j;
FUNC_ENTER_PACKAGE_NOERR
@ -654,10 +653,15 @@ H5O__pline_debug(H5F_t H5_ATTR_UNUSED *f, const void *mesg, FILE *stream, int in
pline->nalloc);
/* Loop over all the filters */
for (i = 0; i < pline->nused; i++) {
char name[32];
for (size_t i = 0; i < pline->nused; i++) {
/* 19 characters for text + 20 characters for largest 64-bit size_t +
* terminal NUL = 40 characters.
*/
char name[64];
HDmemset(name, 0, 64);
HDsnprintf(name, sizeof(name), "Filter at position %zu", i);
HDfprintf(stream, "%*s%-*s\n", indent, "", fwidth, name);
HDfprintf(stream, "%*s%-*s 0x%04x\n", indent + 3, "", MAX(0, fwidth - 3),
"Filter identification:", (unsigned)(pline->filter[i].id));
@ -672,14 +676,14 @@ H5O__pline_debug(H5F_t H5_ATTR_UNUSED *f, const void *mesg, FILE *stream, int in
"Num CD values:", pline->filter[i].cd_nelmts);
/* Filter parameters */
for (j = 0; j < pline->filter[i].cd_nelmts; j++) {
for (size_t j = 0; j < pline->filter[i].cd_nelmts; j++) {
char field_name[32];
HDsnprintf(field_name, sizeof(field_name), "CD value %lu", (unsigned long)j);
HDfprintf(stream, "%*s%-*s %u\n", indent + 6, "", MAX(0, fwidth - 6), field_name,
pline->filter[i].cd_values[j]);
} /* end for */
} /* end for */
}
}
FUNC_LEAVE_NOAPI(SUCCEED)
} /* end H5O__pline_debug() */