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 committed May 7, 2024
1 parent 1a7ea82 commit b816189
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]
#
# -clang-analyzer-optin.performance.Padding
# We prefer logical/semantic order over (potentially insignificant)
Expand All @@ -28,7 +26,6 @@ Checks: "\
-bugprone-easily-swappable-parameters, \
-bugprone-implicit-widening-of-multiplication-result, \
-bugprone-narrowing-conversions, \
-bugprone-not-null-terminated-result, \
\
clang-analyzer, \
-clang-analyzer-optin.performance.Padding, \
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 @@ -404,7 +404,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 @@ -418,9 +419,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

1 comment on commit b816189

@JuergenReppSIT
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@joholl lgtm. Could you please create a PR with this commit.

Please sign in to comment.