From 9a82261e4afac88e92ada1d2241bb913dde6ba6f Mon Sep 17 00:00:00 2001 From: Olly Betts Date: Mon, 19 Apr 2021 18:09:24 +1200 Subject: [PATCH] Fix GCC -Wstringop-truncation warning The code in testcase memberin_extend_c would end up without a terminating nul if passed a 50 byte string, and then make_upper() would run off the end of the buffer. Fix by using strncat() (which always nul terminates the result, and also doesn't zero-fill the tail of the buffer if the result is shorter). --- Examples/test-suite/memberin_extend_c.i | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Examples/test-suite/memberin_extend_c.i b/Examples/test-suite/memberin_extend_c.i index 0599e65a0..c7e017305 100644 --- a/Examples/test-suite/memberin_extend_c.i +++ b/Examples/test-suite/memberin_extend_c.i @@ -32,7 +32,8 @@ char *Person_name_get(Person *p) { } void Person_name_set(Person *p, char *val) { - strncpy(p->name,val,50); + p->name[0] = '\0'; + strncat(p->name, val, sizeof(p->name) - 1); make_upper(p->name); } %}