mirror of https://github.com/swig/swig
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).
This commit is contained in:
parent
5ec65fde0a
commit
9a82261e4a
|
@ -32,7 +32,8 @@ char *Person_name_get(Person *p) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void Person_name_set(Person *p, char *val) {
|
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);
|
make_upper(p->name);
|
||||||
}
|
}
|
||||||
%}
|
%}
|
||||||
|
|
Loading…
Reference in New Issue