Skip to content

Commit 5745139

Browse files
tautschnigDaniel Kroening
authored and
Daniel Kroening
committed
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.
1 parent 79178ce commit 5745139

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
CORE
2+
main.c
3+
--pointer-check --bounds-check --program-only
4+
^EXIT=0$
5+
^SIGNAL=0$
6+
--
7+
^warning: ignoring
8+
dynamic_object#\d+ WITH

src/ansi-c/library/string.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -571,7 +571,7 @@ inline char *strdup(const char *str)
571571
__CPROVER_HIDE:;
572572
__CPROVER_size_t bufsz;
573573
bufsz=(strlen(str)+1);
574-
char *cpy=(char *)malloc(bufsz*sizeof(char));
574+
char *cpy = (char *)calloc(bufsz * sizeof(char), sizeof(char));
575575
if(cpy==((void *)0)) return 0;
576576
#ifdef __CPROVER_STRING_ABSTRACTION
577577
__CPROVER_assume(__CPROVER_buffer_size(cpy)==bufsz);

0 commit comments

Comments
 (0)