From af0d4f507ebdaaea152ce35bca856f6fd4df4e52 Mon Sep 17 00:00:00 2001 From: Dana Robinson Date: Tue, 26 Sep 2023 16:52:15 -0700 Subject: [PATCH] Fix potential uninitialized variable Moves a union initialization up a bit so it's performed before code that can jump to the cleanup target, where file descriptors could be checked without being initialized. This could only happen in test code and only in an out-of-memory situation. Fixes Coverity 1542254 --- tools/src/h5perf/sio_engine.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/tools/src/h5perf/sio_engine.c b/tools/src/h5perf/sio_engine.c index 700416d7198..2363f6a0d99 100644 --- a/tools/src/h5perf/sio_engine.c +++ b/tools/src/h5perf/sio_engine.c @@ -139,9 +139,7 @@ do_sio(parameters param, results *res) /* IO type */ iot = param.io_type; - if (NULL == (fname = calloc(FILENAME_MAX, sizeof(char)))) - GOTOERROR(FAIL); - + /* MUST initialize fd early since we check its file IDs in cleanup code */ switch (iot) { case POSIXIO: fd.posixfd = -1; @@ -157,6 +155,9 @@ do_sio(parameters param, results *res) GOTOERROR(FAIL); } + if (NULL == (fname = calloc(FILENAME_MAX, sizeof(char)))) + GOTOERROR(FAIL); + linear_buf_size = 1; for (i = 0; i < param.rank; i++) {