diff --git a/test/fake_bsp/fakegoodbsp.cpp b/test/fake_bsp/fakegoodbsp.cpp index d3cbff2a..ef2d75b3 100644 --- a/test/fake_bsp/fakegoodbsp.cpp +++ b/test/fake_bsp/fakegoodbsp.cpp @@ -44,7 +44,7 @@ typedef enum { } #define RESULT_STR(X) \ do { \ - size_t Xlen = strnlen(X, MAX_NAME_SIZE) + 1; \ + size_t Xlen = strlen(X) + 1; \ memcpy((void *)param_value, X, \ (param_value_size <= Xlen) ? param_value_size : Xlen); \ if (param_size_ret) \ @@ -282,14 +282,14 @@ AOCL_MMD_CALL int aocl_mmd_read(int handle, aocl_mmd_op_t op, size_t len, fprintf(stderr, "Error: Not handling read of 0x%x in unit test\n", (unsigned int)offset); return -1; - case OFFSET_CONFIGURATION_ROM: - if (strnlen(config_str, MAX_NAME_SIZE) <= len) { - memcpy(dst, (void *)config_str, len); - return 0; - } else { + case OFFSET_CONFIGURATION_ROM: { + const size_t config_len = strlen(config_str); + if (!(config_len < len)) { return -1; } - break; + memcpy(dst, config_str, config_len + 1); + return 0; + } case OFFSET_COUNTER: if (len == sizeof(unsigned int)) { memcpy(dst, &offset_counter, len); diff --git a/test/fake_bsp/missingfuncbsp.cpp b/test/fake_bsp/missingfuncbsp.cpp index 4b2463cc..4c831a12 100644 --- a/test/fake_bsp/missingfuncbsp.cpp +++ b/test/fake_bsp/missingfuncbsp.cpp @@ -44,7 +44,7 @@ typedef enum { } #define RESULT_STR(X) \ do { \ - size_t Xlen = strnlen(X, MAX_NAME_SIZE) + 1; \ + size_t Xlen = strlen(X) + 1; \ memcpy((void *)param_value, X, \ (param_value_size <= Xlen) ? param_value_size : Xlen); \ if (param_size_ret) \ @@ -267,14 +267,14 @@ AOCL_MMD_CALL int aocl_mmd_read(int handle, aocl_mmd_op_t op, size_t len, fprintf(stderr, "Error: Not handling read of 0x%x in unit test\n", (unsigned int)offset); return -1; - case OFFSET_CONFIGURATION_ROM: - if (strnlen(config_str, MAX_NAME_SIZE) <= len) { - memcpy(dst, (void *)config_str, len); - return 0; - } else { + case OFFSET_CONFIGURATION_ROM: { + const size_t config_len = strlen(config_str); + if (!(config_len < len)) { return -1; } - break; + memcpy(dst, config_str, config_len + 1); + return 0; + } case OFFSET_COUNTER: fprintf(stderr, "Error: Not handling read of 0x%x in unit test\n", (unsigned int)offset);