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 4, 2024
1 parent c2c2c24 commit 438685f
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

0 comments on commit 438685f

Please sign in to comment.