Fix potential uninitialized variable (#3602)

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
This commit is contained in:
Dana Robinson 2023-09-27 07:56:25 -07:00 committed by GitHub
parent b892c43e49
commit d8fbc56f78
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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++) {