Workaround the stringop-overflow check false positives.

This commit is contained in:
Qi Wang
2019-08-27 13:44:41 -07:00
committed by Qi Wang
parent 93d6151800
commit 22bc75ee3e
3 changed files with 26 additions and 6 deletions

View File

@@ -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);
}
}