Skip to content

Commit

Permalink
rocm: fix snprintf handling
Browse files Browse the repository at this point in the history
The expected return value from snprintf is < PAPI_MAX_STR_LEN. If it is
>= PAPI_MAX_STR_LEN, the input string was longer than the output
string and this is an unexpected condition that needs to be handled
properly.
  • Loading branch information
gcongiu committed Jul 6, 2023
1 parent 643fa21 commit 84c644e
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/components/rocm/rocp.c
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ static hsa_status_t (*rocp_remove_queue_cbsPtr)(void);
(*hsa_status_stringPtr)(status, &init_err_str_ptr); \
int _exp = snprintf(init_err_str, PAPI_MAX_STR_LEN, "%s", \
init_err_str_ptr); \
if (_exp > PAPI_MAX_STR_LEN) { \
if (_exp >= PAPI_MAX_STR_LEN) { \
SUBDBG("Error string truncated"); \
} \
init_err_str_ptr = init_err_str; \
Expand All @@ -151,7 +151,7 @@ static hsa_status_t (*rocp_remove_queue_cbsPtr)(void);
(*rocp_error_stringPtr)(&init_err_str_ptr); \
int _exp = snprintf(init_err_str, PAPI_MAX_STR_LEN, "%s", \
init_err_str_ptr); \
if (_exp > PAPI_MAX_STR_LEN) { \
if (_exp >= PAPI_MAX_STR_LEN) { \
SUBDBG("Error string truncated"); \
} \
init_err_str_ptr = init_err_str; \
Expand All @@ -162,7 +162,7 @@ static hsa_status_t (*rocp_remove_queue_cbsPtr)(void);
#define ROCP_REC_ERR_STR(string) do { \
int _exp = snprintf(init_err_str, PAPI_MAX_STR_LEN, "%s", \
string); \
if (_exp > PAPI_MAX_STR_LEN) { \
if (_exp >= PAPI_MAX_STR_LEN) { \
SUBDBG("Error string truncated"); \
} \
init_err_str_ptr = init_err_str; \
Expand Down

0 comments on commit 84c644e

Please sign in to comment.