Skip to content

Commit f8df76a

Browse files
authored
Merge pull request diffblue#2276 from tautschnig/c-string-zero
Zero-length C string operations should not yield pointer checks
2 parents bb1bae9 + 523f8ae commit f8df76a

File tree

1 file changed

+11
-11
lines changed

1 file changed

+11
-11
lines changed

src/ansi-c/library/string.c

+11-11
Original file line numberDiff line numberDiff line change
@@ -597,11 +597,11 @@ void *memcpy(void *dst, const void *src, size_t n)
597597
__CPROVER_precondition(__CPROVER_POINTER_OBJECT(dst)!=
598598
__CPROVER_POINTER_OBJECT(src),
599599
"memcpy src/dst overlap");
600-
(void)*(char *)dst; // check that the memory is accessible
601-
(void)*(const char *)src; // check that the memory is accessible
602600

603601
if(n > 0)
604602
{
603+
(void)*(char *)dst; // check that the memory is accessible
604+
(void)*(const char *)src; // check that the memory is accessible
605605
(void)*(((char *)dst) + n - 1); // check that the memory is accessible
606606
(void)*(((const char *)src) + n - 1); // check that the memory is accessible
607607
//for(__CPROVER_size_t i=0; i<n ; i++) ((char *)dst)[i]=((const char *)src)[i];
@@ -639,12 +639,12 @@ void *__builtin___memcpy_chk(void *dst, const void *src, __CPROVER_size_t n, __C
639639
__CPROVER_precondition(__CPROVER_POINTER_OBJECT(dst)!=
640640
__CPROVER_POINTER_OBJECT(src),
641641
"memcpy src/dst overlap");
642-
(void)*(char *)dst; // check that the memory is accessible
643-
(void)*(const char *)src; // check that the memory is accessible
644642
(void)size;
645643

646644
if(n > 0)
647645
{
646+
(void)*(char *)dst; // check that the memory is accessible
647+
(void)*(const char *)src; // check that the memory is accessible
648648
(void)*(((char *)dst) + n - 1); // check that the memory is accessible
649649
(void)*(((const char *)src) + n - 1); // check that the memory is accessible
650650
//for(__CPROVER_size_t i=0; i<n ; i++) ((char *)dst)[i]=((const char *)src)[i];
@@ -685,10 +685,10 @@ void *memset(void *s, int c, size_t n)
685685
else
686686
__CPROVER_is_zero_string(s)=0;
687687
#else
688-
(void)*(char *)s; // check that the memory is accessible
689688

690689
if(n > 0)
691690
{
691+
(void)*(char *)s; // check that the memory is accessible
692692
(void)*(((char *)s) + n - 1); // check that the memory is accessible
693693
//char *sp=s;
694694
//for(__CPROVER_size_t i=0; i<n ; i++) sp[i]=c;
@@ -724,10 +724,10 @@ void *__builtin_memset(void *s, int c, __CPROVER_size_t n)
724724
__CPROVER_is_zero_string(s)=0;
725725
}
726726
#else
727-
(void)*(char *)s; // check that the memory is accessible
728727

729728
if(n > 0)
730729
{
730+
(void)*(char *)s; // check that the memory is accessible
731731
(void)*(((char *)s) + n - 1); // check that the memory is accessible
732732
//char *sp=s;
733733
//for(__CPROVER_size_t i=0; i<n ; i++) sp[i]=c;
@@ -763,11 +763,11 @@ void *__builtin___memset_chk(void *s, int c, __CPROVER_size_t n, __CPROVER_size_
763763
else
764764
__CPROVER_is_zero_string(s)=0;
765765
#else
766-
(void)*(char *)s; // check that the memory is accessible
767766
(void)size;
768767

769768
if(n > 0)
770769
{
770+
(void)*(char *)s; // check that the memory is accessible
771771
(void)*(((char *)s) + n - 1); // check that the memory is accessible
772772
//char *sp=s;
773773
//for(__CPROVER_size_t i=0; i<n ; i++) sp[i]=c;
@@ -804,11 +804,11 @@ void *memmove(void *dest, const void *src, size_t n)
804804
else
805805
__CPROVER_is_zero_string(dest)=0;
806806
#else
807-
(void)*(char *)dest; // check that the memory is accessible
808-
(void)*(const char *)src; // check that the memory is accessible
809807

810808
if(n > 0)
811809
{
810+
(void)*(char *)dest; // check that the memory is accessible
811+
(void)*(const char *)src; // check that the memory is accessible
812812
(void)*(((char *)dest) + n - 1); // check that the memory is accessible
813813
(void)*(((const char *)src) + n - 1); // check that the memory is accessible
814814
char src_n[n];
@@ -848,12 +848,12 @@ void *__builtin___memmove_chk(void *dest, const void *src, size_t n, __CPROVER_s
848848
__CPROVER_is_zero_string(dest)=0;
849849
}
850850
#else
851-
(void)*(char *)dest; // check that the memory is accessible
852-
(void)*(const char *)src; // check that the memory is accessible
853851
(void)size;
854852

855853
if(n > 0)
856854
{
855+
(void)*(char *)dest; // check that the memory is accessible
856+
(void)*(const char *)src; // check that the memory is accessible
857857
(void)*(((char *)dest) + n - 1); // check that the memory is accessible
858858
(void)*(((const char *)src) + n - 1); // check that the memory is accessible
859859
char src_n[n];

0 commit comments

Comments
 (0)