From: Augustin Degomme Date: Mon, 9 Jul 2018 16:03:06 +0000 (+0200) Subject: prevent <0 errorcodes in MPI_Error_code X-Git-Tag: v3_21~502 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/421c63c7a505d3c80bdaca5614d186348f4c8ab0 prevent <0 errorcodes in MPI_Error_code --- diff --git a/src/smpi/bindings/smpi_pmpi.cpp b/src/smpi/bindings/smpi_pmpi.cpp index b0f7cc3272..5b9b8733d9 100644 --- a/src/smpi/bindings/smpi_pmpi.cpp +++ b/src/smpi/bindings/smpi_pmpi.cpp @@ -209,12 +209,16 @@ int PMPI_Error_class(int errorcode, int* errorclass) { } int PMPI_Error_string(int errorcode, char* string, int* resultlen){ - static const char *smpi_error_string[] = { - FOREACH_ERROR(GENERATE_STRING) - }; - *resultlen = strlen(smpi_error_string[errorcode]); - strncpy(string, smpi_error_string[errorcode], *resultlen); - return MPI_SUCCESS; + if (errorcode<0 || string ==nullptr){ + return MPI_ERR_ARG; + } else { + static const char *smpi_error_string[] = { + FOREACH_ERROR(GENERATE_STRING) + }; + *resultlen = strlen(smpi_error_string[errorcode]); + strncpy(string, smpi_error_string[errorcode], *resultlen); + return MPI_SUCCESS; + } } int PMPI_Keyval_create(MPI_Copy_function* copy_fn, MPI_Delete_function* delete_fn, int* keyval, void* extra_state) {