Skip to content

Commit 099757c

Browse files
committed
Removing strnlen
1 parent b835961 commit 099757c

File tree

1 file changed

+7
-10
lines changed

1 file changed

+7
-10
lines changed

org/qmckl_error.org

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -472,18 +472,15 @@ qmckl_get_error(qmckl_context context,
472472
qmckl_context_struct* const ctx = (qmckl_context_struct*) context;
473473
assert (ctx != NULL); /* Impossible because the context is valid. */
474474

475-
/* Turn off annoying GCC warning */
476-
#ifdef __GNUC__
477-
#pragma GCC diagnostic push
478-
#pragma GCC diagnostic ignored "-Wstringop-truncation"
479-
#endif
475+
size_t sizeCp;
480476

481-
strncpy(function_name, ctx->error.function, QMCKL_MAX_FUN_LEN-1);
482-
strncpy(message , ctx->error.message , QMCKL_MAX_MSG_LEN-1);
477+
sizeCp = strlen(ctx->error.function);
478+
sizeCp = sizeCp > QMCKL_MAX_FUN_LEN ? QMCKL_MAX_FUN_LEN : sizeCp;
479+
memcpy(function_name, ctx->error.function, sizeCp);
483480

484-
#ifdef __GNUC__
485-
#pragma GCC diagnostic pop
486-
#endif
481+
sizeCp = strlen(ctx->error.message);
482+
sizeCp = sizeCp > QMCKL_MAX_MSG_LEN ? QMCKL_MAX_MSG_LEN : sizeCp;
483+
memcpy(message, ctx->error.message, sizeCp);
487484

488485
(*exit_code) = ctx->error.exit_code;
489486
}

0 commit comments

Comments
 (0)