C library/strdup: use calloc for an array that will be overwritten

calloc will zero-initialize the array, making it amenable to constant
propagation. If subsequent updates via strcpy write constants, we can keep
constant-propagating the array.
This commit is contained in:
Michael Tautschnig 2019-01-28 15:37:47 +00:00 committed by Daniel Kroening
parent 79178ce04f
commit 574513999a
2 changed files with 9 additions and 1 deletions

View File

@ -0,0 +1,8 @@
CORE
main.c
--pointer-check --bounds-check --program-only
^EXIT=0$
^SIGNAL=0$
--
^warning: ignoring
dynamic_object#\d+ WITH

View File

@ -571,7 +571,7 @@ inline char *strdup(const char *str)
__CPROVER_HIDE:;
__CPROVER_size_t bufsz;
bufsz=(strlen(str)+1);
char *cpy=(char *)malloc(bufsz*sizeof(char));
char *cpy = (char *)calloc(bufsz * sizeof(char), sizeof(char));
if(cpy==((void *)0)) return 0;
#ifdef __CPROVER_STRING_ABSTRACTION
__CPROVER_assume(__CPROVER_buffer_size(cpy)==bufsz);