@@ -52,15 +52,13 @@ __inline char *__builtin___strcat_chk(char *dst, const char *src, __CPROVER_size
52
52
while (dst [i ]!= 0 ) i ++ ;
53
53
54
54
__CPROVER_size_t j = 0 ;
55
- char ch ;
56
- do
55
+ char ch = 1 ;
56
+ for (; i < s && ch != ( char ) 0 ; ++ i , ++ j )
57
57
{
58
58
ch = src [j ];
59
59
dst [i ]= ch ;
60
- i ++ ;
61
- j ++ ;
62
60
}
63
- while ( i < s && ch != ( char ) 0 ) ;
61
+ dst [ i ] = '\0' ;
64
62
#endif
65
63
return dst ;
66
64
}
@@ -90,10 +88,19 @@ __inline char *__builtin___strncat_chk(
90
88
#else
91
89
__CPROVER_assert (__CPROVER_POINTER_OBJECT (dst )!=
92
90
__CPROVER_POINTER_OBJECT (src ), "strncat src/dst overlap" );
93
- (void )* dst ;
94
- (void )* src ;
95
- (void )n ;
96
- (void )s ;
91
+
92
+ __CPROVER_size_t i = 0 ;
93
+ while (dst [i ] != 0 )
94
+ i ++ ;
95
+
96
+ __CPROVER_size_t j = 0 ;
97
+ char ch = 1 ;
98
+ for (; i < s && j < n && ch != (char )0 ; ++ i , ++ j )
99
+ {
100
+ ch = src [j ];
101
+ dst [i ] = ch ;
102
+ }
103
+ dst [i ] = '\0' ;
97
104
#endif
98
105
return dst ;
99
106
}
@@ -236,15 +243,13 @@ inline char *strcat(char *dst, const char *src)
236
243
while (dst [i ]!= 0 ) i ++ ;
237
244
238
245
__CPROVER_size_t j = 0 ;
239
- char ch ;
240
- do
246
+ char ch = 1 ;
247
+ for (; ch != ( char ) 0 ; ++ i , ++ j )
241
248
{
242
249
ch = src [j ];
243
250
dst [i ]= ch ;
244
- i ++ ;
245
- j ++ ;
246
251
}
247
- while ( ch != ( char ) 0 ) ;
252
+ dst [ i ] = '\0' ;
248
253
#endif
249
254
return dst ;
250
255
}
@@ -279,9 +284,19 @@ inline char *strncat(char *dst, const char *src, size_t n)
279
284
#else
280
285
__CPROVER_assert (__CPROVER_POINTER_OBJECT (dst )!=
281
286
__CPROVER_POINTER_OBJECT (src ), "strncat src/dst overlap" );
282
- (void )* dst ;
283
- (void )* src ;
284
- (void )n ;
287
+
288
+ __CPROVER_size_t i = 0 ;
289
+ while (dst [i ] != 0 )
290
+ i ++ ;
291
+
292
+ __CPROVER_size_t j = 0 ;
293
+ char ch = 1 ;
294
+ for (; j < n && ch != (char )0 ; ++ i , ++ j )
295
+ {
296
+ ch = src [j ];
297
+ dst [i ] = ch ;
298
+ }
299
+ dst [i ] = '\0' ;
285
300
#endif
286
301
return dst ;
287
302
}
@@ -533,10 +548,16 @@ void *memcpy(void *dst, const void *src, size_t n)
533
548
__CPROVER_POINTER_OBJECT (src ), "memcpy src/dst overlap" );
534
549
(void )* (char * )dst ; // check that the memory is accessible
535
550
(void )* (const char * )src ; // check that the memory is accessible
536
- //for(__CPROVER_size_t i=0; i<n ; i++) ((char *)dst)[i]=((const char *)src)[i];
537
- char src_n [n ];
538
- __CPROVER_array_copy (src_n , (char * )src );
539
- __CPROVER_array_replace ((char * )dst , src_n );
551
+
552
+ if (n > 0 )
553
+ {
554
+ (void )* (((char * )dst ) + n - 1 ); // check that the memory is accessible
555
+ (void )* (((const char * )src ) + n - 1 ); // check that the memory is accessible
556
+ //for(__CPROVER_size_t i=0; i<n ; i++) ((char *)dst)[i]=((const char *)src)[i];
557
+ char src_n [n ];
558
+ __CPROVER_array_copy (src_n , (char * )src );
559
+ __CPROVER_array_replace ((char * )dst , src_n );
560
+ }
540
561
#endif
541
562
return dst ;
542
563
}
@@ -566,10 +587,16 @@ void *__builtin___memcpy_chk(void *dst, const void *src, __CPROVER_size_t n, __C
566
587
(void )* (char * )dst ; // check that the memory is accessible
567
588
(void )* (const char * )src ; // check that the memory is accessible
568
589
(void )size ;
569
- //for(__CPROVER_size_t i=0; i<n ; i++) ((char *)dst)[i]=((const char *)src)[i];
570
- char src_n [n ];
571
- __CPROVER_array_copy (src_n , (char * )src );
572
- __CPROVER_array_replace ((char * )dst , src_n );
590
+
591
+ if (n > 0 )
592
+ {
593
+ (void )* (((char * )dst ) + n - 1 ); // check that the memory is accessible
594
+ (void )* (((const char * )src ) + n - 1 ); // check that the memory is accessible
595
+ //for(__CPROVER_size_t i=0; i<n ; i++) ((char *)dst)[i]=((const char *)src)[i];
596
+ char src_n [n ];
597
+ __CPROVER_array_copy (src_n , (char * )src );
598
+ __CPROVER_array_replace ((char * )dst , src_n );
599
+ }
573
600
#endif
574
601
return dst ;
575
602
}
@@ -603,11 +630,16 @@ void *memset(void *s, int c, size_t n)
603
630
__CPROVER_is_zero_string (s )= 0 ;
604
631
#else
605
632
(void )* (char * )s ; // check that the memory is accessible
606
- //char *sp=s;
607
- //for(__CPROVER_size_t i=0; i<n ; i++) sp[i]=c;
608
- unsigned char s_n [n ];
609
- __CPROVER_array_set (s_n , (unsigned char )c );
610
- __CPROVER_array_replace ((unsigned char * )s , s_n );
633
+
634
+ if (n > 0 )
635
+ {
636
+ (void )* (((char * )s ) + n - 1 ); // check that the memory is accessible
637
+ //char *sp=s;
638
+ //for(__CPROVER_size_t i=0; i<n ; i++) sp[i]=c;
639
+ unsigned char s_n [n ];
640
+ __CPROVER_array_set (s_n , (unsigned char )c );
641
+ __CPROVER_array_replace ((unsigned char * )s , s_n );
642
+ }
611
643
#endif
612
644
return s ;
613
645
}
@@ -631,13 +663,21 @@ void *__builtin_memset(void *s, int c, __CPROVER_size_t n)
631
663
__CPROVER_zero_string_length (s )= 0 ;
632
664
}
633
665
else
666
+ {
634
667
__CPROVER_is_zero_string (s )= 0 ;
668
+ }
635
669
#else
636
- //char *sp=s;
637
- //for(__CPROVER_size_t i=0; i<n ; i++) sp[i]=c;
638
- unsigned char s_n [n ];
639
- __CPROVER_array_set (s_n , (unsigned char )c );
640
- __CPROVER_array_replace ((unsigned char * )s , s_n );
670
+ (void )* (char * )s ; // check that the memory is accessible
671
+
672
+ if (n > 0 )
673
+ {
674
+ (void )* (((char * )s ) + n - 1 ); // check that the memory is accessible
675
+ //char *sp=s;
676
+ //for(__CPROVER_size_t i=0; i<n ; i++) sp[i]=c;
677
+ unsigned char s_n [n ];
678
+ __CPROVER_array_set (s_n , (unsigned char )c );
679
+ __CPROVER_array_replace ((unsigned char * )s , s_n );
680
+ }
641
681
#endif
642
682
return s ;
643
683
}
@@ -666,11 +706,16 @@ void *__builtin___memset_chk(void *s, int c, __CPROVER_size_t n, __CPROVER_size_
666
706
#else
667
707
(void )* (char * )s ; // check that the memory is accessible
668
708
(void )size ;
669
- //char *sp=s;
670
- //for(__CPROVER_size_t i=0; i<n ; i++) sp[i]=c;
671
- unsigned char s_n [n ];
672
- __CPROVER_array_set (s_n , (unsigned char )c );
673
- __CPROVER_array_replace ((unsigned char * )s , s_n );
709
+
710
+ if (n > 0 )
711
+ {
712
+ (void )* (((char * )s ) + n - 1 ); // check that the memory is accessible
713
+ //char *sp=s;
714
+ //for(__CPROVER_size_t i=0; i<n ; i++) sp[i]=c;
715
+ unsigned char s_n [n ];
716
+ __CPROVER_array_set (s_n , (unsigned char )c );
717
+ __CPROVER_array_replace ((unsigned char * )s , s_n );
718
+ }
674
719
#endif
675
720
return s ;
676
721
}
@@ -701,9 +746,15 @@ void *memmove(void *dest, const void *src, size_t n)
701
746
#else
702
747
(void )* (char * )dest ; // check that the memory is accessible
703
748
(void )* (const char * )src ; // check that the memory is accessible
704
- char src_n [n ];
705
- __CPROVER_array_copy (src_n , (char * )src );
706
- __CPROVER_array_replace ((char * )dest , src_n );
749
+
750
+ if (n > 0 )
751
+ {
752
+ (void )* (((char * )dest ) + n - 1 ); // check that the memory is accessible
753
+ (void )* (((const char * )src ) + n - 1 ); // check that the memory is accessible
754
+ char src_n [n ];
755
+ __CPROVER_array_copy (src_n , (char * )src );
756
+ __CPROVER_array_replace ((char * )dest , src_n );
757
+ }
707
758
#endif
708
759
return dest ;
709
760
}
@@ -731,12 +782,22 @@ void *__builtin___memmove_chk(void *dest, const void *src, size_t n, __CPROVER_s
731
782
__CPROVER_zero_string_length (dest )= __CPROVER_zero_string_length (src );
732
783
}
733
784
else
785
+ {
734
786
__CPROVER_is_zero_string (dest )= 0 ;
787
+ }
735
788
#else
789
+ (void )* (char * )dest ; // check that the memory is accessible
790
+ (void )* (const char * )src ; // check that the memory is accessible
736
791
(void )size ;
737
- char src_n [n ];
738
- __CPROVER_array_copy (src_n , (char * )src );
739
- __CPROVER_array_replace ((char * )dest , src_n );
792
+
793
+ if (n > 0 )
794
+ {
795
+ (void )* (((char * )dest ) + n - 1 ); // check that the memory is accessible
796
+ (void )* (((const char * )src ) + n - 1 ); // check that the memory is accessible
797
+ char src_n [n ];
798
+ __CPROVER_array_copy (src_n , (char * )src );
799
+ __CPROVER_array_replace ((char * )dest , src_n );
800
+ }
740
801
#endif
741
802
return dest ;
742
803
}
0 commit comments