Skip to content

Commit

Permalink
resource.c: WA for GCC's -Wstringop-truncation bug
Browse files Browse the repository at this point in the history
When file includes both common.c & resource.c, i.e. GCC (13.2.1)
sees how latter uses functions from former, there's:
-------------------------------------------------------------
utils/common/common.c: In function ‘otel_resource_attributes’:
utils/common/common.c:92:3: error: ‘__builtin_strncpy’ output truncated before terminating nul copying as many bytes from a string as its length [-Werror=stringop-truncation]
   92 |   strncpy(dest, src != NULL ? src : "", n - 1);
      |   ^
-------------------------------------------------------------
Although the next line from sstrncpy() _does_ set terminator...

As this is the only place I've seen this, increase stack array size to
keep the otherwise useful GCC warning option.

Signed-off-by: Eero Tamminen <eero.t.tamminen@intel.com>
  • Loading branch information
eero-t committed May 20, 2024
1 parent f48d523 commit c676255
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/daemon/resource.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ static void otel_resource_attributes(void) {
return;
}

size_t tmp_sz = strlen(ra) + 1;
/* second +1 is WA for GCC -Wstringop-truncation bug with sstrncpy() */
size_t tmp_sz = strlen(ra) + 1 + 1;
char tmp[tmp_sz];
sstrncpy(tmp, ra, sizeof(tmp));

Expand Down

0 comments on commit c676255

Please sign in to comment.