From 30834bce24f61ea60f629c2c9045e287353aaae7 Mon Sep 17 00:00:00 2001 From: Wei-keng Liao Date: Thu, 14 Nov 2024 16:50:43 -0600 Subject: [PATCH] add const type qualifier to argument err_msg Contents of argument err_msg is not modified --- src/drivers/common/error_mpi2nc.c | 10 +++++----- src/drivers/include/common.h | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/drivers/common/error_mpi2nc.c b/src/drivers/common/error_mpi2nc.c index af4b79a76..2d4f3981c 100644 --- a/src/drivers/common/error_mpi2nc.c +++ b/src/drivers/common/error_mpi2nc.c @@ -20,11 +20,12 @@ /*----< ncmpii_error_mpi2nc() -----------------------------------------------*/ /* translate MPI error codes to PnetCDF/netCDF error codes */ -int ncmpii_error_mpi2nc(int mpi_errorcode, /* returned value from MPI call */ - char *err_msg) /* extra error message */ +int ncmpii_error_mpi2nc(int mpi_errorcode, /* returned value from MPI call */ + const char *err_msg) /* extra error message */ { int errorclass, errorStringLen; char errorString[MPI_MAX_ERROR_STRING]; + const char *dump_str = (err_msg == NULL) ? "" : err_msg; /* check for specific error codes understood by PnetCDF */ @@ -65,14 +66,13 @@ int ncmpii_error_mpi2nc(int mpi_errorcode, /* returned value from MPI call */ */ MPI_Error_string(mpi_errorcode, errorString, &errorStringLen); - if (err_msg == NULL) err_msg = ""; #ifdef PNETCDF_DEBUG /* report the world rank */ int rank; MPI_Comm_rank(MPI_COMM_WORLD, &rank); - printf("rank %d: MPI error (%s) : %s\n", rank, err_msg, errorString); + printf("rank %d: MPI error (%s) : %s\n", rank, dump_str, errorString); #else - printf("MPI error (%s) : %s\n", err_msg, errorString); + printf("MPI error (%s) : %s\n", dump_str, errorString); #endif return NC_EFILE; /* other unknown file I/O error */ diff --git a/src/drivers/include/common.h b/src/drivers/include/common.h index 4f6d4f953..8e3d30aa3 100644 --- a/src/drivers/include/common.h +++ b/src/drivers/include/common.h @@ -107,7 +107,7 @@ ncmpii_create_imaptype(int ndims, const MPI_Offset *count, MPI_Datatype *imaptype); extern int -ncmpii_error_mpi2nc(int mpi_errorcode, char *msg); +ncmpii_error_mpi2nc(int mpi_errorcode, const char *msg); extern int ncmpii_error_posix2nc(char *err_msg);