Workaround the stringop-overflow check false positives.
This commit is contained in:
@@ -232,3 +232,16 @@ p_test_fail(const char *prefix, const char *message) {
|
||||
malloc_cprintf(NULL, NULL, "%s%s\n", prefix, message);
|
||||
test_status = test_status_fail;
|
||||
}
|
||||
|
||||
void
|
||||
strncpy_cond(void *dst, const char *src, bool cond) {
|
||||
if (cond) {
|
||||
/*
|
||||
* Avoid strcpy and explicitly set length to 0 because the
|
||||
* `stringop-overflow` check may warn even if the specific test
|
||||
* is unreachable.
|
||||
*/
|
||||
size_t n = cond ? strlen(src) + 1 : 0;
|
||||
strncpy(dst, src, n);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user