Skip to content

Commit

Permalink
clang-tidy: fix bugprone-not-null-terminated-result
Browse files Browse the repository at this point in the history
Fixes: #2826

Signed-off-by: Johannes Holland <johannes.holland@infineon.de>
  • Loading branch information
Johannes Holland authored and AndreasFuchsTPM committed Jul 5, 2024
1 parent 0fda88d commit 2a2187d
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 6 deletions.
3 changes: 0 additions & 3 deletions .clang-tidy
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@
# [TODO]
# -bugprone-narrowing-conversions
# [TODO]
# -bugprone-not-null-terminated-result
# [TODO]
# -bugprone-reserved-identifier
# [TODO]
#
Expand All @@ -30,7 +28,6 @@ Checks: "\
-bugprone-easily-swappable-parameters, \
-bugprone-implicit-widening-of-multiplication-result, \
-bugprone-narrowing-conversions, \
-bugprone-not-null-terminated-result, \
-bugprone-reserved-identifier, \
\
clang-analyzer, \
Expand Down
7 changes: 4 additions & 3 deletions src/tss2-policy/tss2_policy.c
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,8 @@ Tss2_PolicyGetDescription(
policy_ctx->path);

const char *description = policy_ctx->policy.description;
size_t len = strlen(description);
/* length including null termination */
size_t len = strlen(description) + 1;

/* NULL buffer let calller know size */
if (!buffer) {
Expand All @@ -429,9 +430,9 @@ Tss2_PolicyGetDescription(
return_if_error(TSS2_POLICY_RC_BUFFER_TOO_SMALL, "Specified buffer is too small");
}

/* all is well, copy it to user and let them know size */
/* all is well, copy it to user (including null termination) and let them know size */
*size = len;
memcpy(buffer, description, len);
strcpy(buffer, description);

LOG_TRACE("finished, returning: 0x0");
return TSS2_RC_SUCCESS;
Expand Down

0 comments on commit 2a2187d

Please sign in to comment.