Skip to content

Commit 8d2fd74

Browse files
jschwartz-crayJulianKunkel
authored andcommittedFeb 3, 2022
Fix #410.
Added a local variable to the affected macros which ensures the parameter is expanded first to prevent multiple calls to any embedded functions.
1 parent 3c3705f commit 8d2fd74

File tree

3 files changed

+11
-7
lines changed

3 files changed

+11
-7
lines changed
 

‎src/aiori-HDF5.c

+4-3
Original file line numberDiff line numberDiff line change
@@ -48,15 +48,16 @@
4848
#if H5_VERS_MAJOR > 1 && H5_VERS_MINOR > 6
4949
#define HDF5_CHECK(HDF5_RETURN, MSG) do { \
5050
char resultString[1024]; \
51+
herr_t _HDF5_RETURN = (HDF5_RETURN); \
5152
\
52-
if (HDF5_RETURN < 0) { \
53+
if (_HDF5_RETURN < 0) { \
5354
fprintf(stdout, "** error **\n"); \
5455
fprintf(stdout, "ERROR in %s (line %d): %s.\n", \
5556
__FILE__, __LINE__, MSG); \
56-
strcpy(resultString, H5Eget_major((H5E_major_t)HDF5_RETURN)); \
57+
strcpy(resultString, H5Eget_major((H5E_major_t)_HDF5_RETURN)); \
5758
if (strcmp(resultString, "Invalid major error number") != 0) \
5859
fprintf(stdout, "HDF5 %s\n", resultString); \
59-
strcpy(resultString, H5Eget_minor((H5E_minor_t)HDF5_RETURN)); \
60+
strcpy(resultString, H5Eget_minor((H5E_minor_t)_HDF5_RETURN)); \
6061
if (strcmp(resultString, "Invalid minor error number") != 0) \
6162
fprintf(stdout, "%s\n", resultString); \
6263
fprintf(stdout, "** exiting **\n"); \

‎src/aiori-NCMPI.c

+4-2
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,13 @@
3232
* NCMPI_CHECK will display a custom error message and then exit the program
3333
*/
3434
#define NCMPI_CHECK(NCMPI_RETURN, MSG) do { \
35-
if (NCMPI_RETURN != NC_NOERR) { \
35+
int _NCMPI_RETURN = (NCMPI_RETURN); \
36+
\
37+
if (_NCMPI_RETURN != NC_NOERR) { \
3638
fprintf(stdout, "** error **\n"); \
3739
fprintf(stdout, "ERROR in %s (line %d): %s.\n", \
3840
__FILE__, __LINE__, MSG); \
39-
fprintf(stdout, "ERROR: %s.\n", ncmpi_strerror(NCMPI_RETURN)); \
41+
fprintf(stdout, "ERROR: %s.\n", ncmpi_strerror(_NCMPI_RETURN)); \
4042
fprintf(stdout, "** exiting **\n"); \
4143
exit(EXIT_FAILURE); \
4244
} \

‎src/aiori-debug.h

+3-2
Original file line numberDiff line numberDiff line change
@@ -81,9 +81,10 @@ void FailMessage(int rank, const char *location, char *format, ...);
8181
#define MPI_CHECKF(MPI_STATUS, FORMAT, ...) do { \
8282
char resultString[MPI_MAX_ERROR_STRING]; \
8383
int resultLength; \
84+
int _MPI_STATUS = (MPI_STATUS); \
8485
\
85-
if (MPI_STATUS != MPI_SUCCESS) { \
86-
MPI_Error_string(MPI_STATUS, resultString, &resultLength); \
86+
if (_MPI_STATUS != MPI_SUCCESS) { \
87+
MPI_Error_string(_MPI_STATUS, resultString, &resultLength); \
8788
fprintf(out_logfile, "ERROR: " FORMAT ", MPI %s, (%s:%d)\n", \
8889
__VA_ARGS__, resultString, __FILE__, __LINE__); \
8990
fflush(out_logfile); \

0 commit comments

Comments
 (0)