diff options
author | David Young <dyoung@hdfgroup.org> | 2022-04-30 03:29:20 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-04-30 03:29:20 (GMT) |
commit | c4d70e3571262df0fcf381f5804b671dc9f86bc1 (patch) | |
tree | d5942228d0e2b320b23fdae7c5de278063d77955 /src/H5Bdbg.c | |
parent | ffd311cf36814c2742234b8a02f47078cb7c8158 (diff) | |
download | hdf5-c4d70e3571262df0fcf381f5804b671dc9f86bc1.zip hdf5-c4d70e3571262df0fcf381f5804b671dc9f86bc1.tar.gz hdf5-c4d70e3571262df0fcf381f5804b671dc9f86bc1.tar.bz2 |
Be a bit safer with signed arithmetic, thus quieting some signed-overflow warnings from GCC (#1706)
* Avoid a signed overflow: check the range of `entry_ptr->age` before
increasing it instead of increasing it and then checking the range.
This quiets a GCC warning.
* Avoid the potential for signed overflow by rewriting expressions
`MAX(0, fwidth - n)` as `MAX(n, fwidth) - n` for various `n`.
This change quiets some GCC warnings.
* Change some local variables that cannot take sensible negative values
from signed to unsigned. This quiets GCC warnings about potential
signed overflow.
* In a handful of instances, check the range of a signed integer before
increasing/decreasing it, just in case the increase/decrease overflows.
This quiets a handful of GCC signed-overflow warnings.
* Committing clang-format changes
Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com>
Diffstat (limited to 'src/H5Bdbg.c')
-rw-r--r-- | src/H5Bdbg.c | 10 |
1 files changed, 5 insertions, 5 deletions
diff --git a/src/H5Bdbg.c b/src/H5Bdbg.c index 23d0a8f..de07442 100644 --- a/src/H5Bdbg.c +++ b/src/H5Bdbg.c @@ -110,20 +110,20 @@ H5B_debug(H5F_t *f, haddr_t addr, FILE *stream, int indent, int fwidth, const H5 */ for (u = 0; u < bt->nchildren; u++) { HDfprintf(stream, "%*sChild %d...\n", indent, "", u); - HDfprintf(stream, "%*s%-*s %" PRIuHADDR "\n", indent + 3, "", MAX(0, fwidth - 3), + HDfprintf(stream, "%*s%-*s %" PRIuHADDR "\n", indent + 3, "", MAX(3, fwidth) - 3, "Address:", bt->child[u]); /* If there is a key debugging routine, use it to display the left & right keys */ if (type->debug_key) { /* Decode the 'left' key & print it */ - HDfprintf(stream, "%*s%-*s\n", indent + 3, "", MAX(0, fwidth - 3), "Left Key:"); + HDfprintf(stream, "%*s%-*s\n", indent + 3, "", MAX(3, fwidth) - 3, "Left Key:"); HDassert(H5B_NKEY(bt, shared, u)); - (void)(type->debug_key)(stream, indent + 6, MAX(0, fwidth - 6), H5B_NKEY(bt, shared, u), udata); + (void)(type->debug_key)(stream, indent + 6, MAX(6, fwidth) - 6, H5B_NKEY(bt, shared, u), udata); /* Decode the 'right' key & print it */ - HDfprintf(stream, "%*s%-*s\n", indent + 3, "", MAX(0, fwidth - 3), "Right Key:"); + HDfprintf(stream, "%*s%-*s\n", indent + 3, "", MAX(3, fwidth) - 3, "Right Key:"); HDassert(H5B_NKEY(bt, shared, u + 1)); - (void)(type->debug_key)(stream, indent + 6, MAX(0, fwidth - 6), H5B_NKEY(bt, shared, u + 1), + (void)(type->debug_key)(stream, indent + 6, MAX(6, fwidth) - 6, H5B_NKEY(bt, shared, u + 1), udata); } /* end if */ } /* end for */ |