There was a problem with strncpy and strncmp. Made bound_ptr_add and bound_ptr_indir a little bit faster. Fix statistic counter types. Change long into long long.
Unified · Split
| @@ -165,35 +165,35 @@ static int never_fatal = 0; · 164 unmodified lines | |||
| 165 | static int no_checking = 0; | 165 | static int no_checking = 0; |
| 166 | 166 | ||
| 167 | #ifdef BOUND_STATISTIC | 167 | #ifdef BOUND_STATISTIC |
| 168 | static unsigned long bound_ptr_add_count; | 168 | static unsigned long long bound_ptr_add_count; |
| 169 | static unsigned long bound_ptr_indir1_count; | 169 | static unsigned long long bound_ptr_indir1_count; |
| 170 | static unsigned long bound_ptr_indir2_count; | 170 | static unsigned long long bound_ptr_indir2_count; |
| 171 | static unsigned long bound_ptr_indir4_count; | 171 | static unsigned long long bound_ptr_indir4_count; |
| 172 | static unsigned long bound_ptr_indir8_count; | 172 | static unsigned long long bound_ptr_indir8_count; |
| 173 | static unsigned long bound_ptr_indir12_count; | 173 | static unsigned long long bound_ptr_indir12_count; |
| 174 | static unsigned long bound_ptr_indir16_count; | 174 | static unsigned long long bound_ptr_indir16_count; |
| 175 | static unsigned long bound_local_new_count; | 175 | static unsigned long long bound_local_new_count; |
| 176 | static unsigned long bound_local_delete_count; | 176 | static unsigned long long bound_local_delete_count; |
| 177 | static unsigned long bound_malloc_count; | 177 | static unsigned long long bound_malloc_count; |
| 178 | static unsigned long bound_calloc_count; | 178 | static unsigned long long bound_calloc_count; |
| 179 | static unsigned long bound_realloc_count; | 179 | static unsigned long long bound_realloc_count; |
| 180 | static unsigned long bound_free_count; | 180 | static unsigned long long bound_free_count; |
| 181 | static unsigned long bound_memalign_count; | 181 | static unsigned long long bound_memalign_count; |
| 182 | static unsigned long bound_mmap_count; | 182 | static unsigned long long bound_mmap_count; |
| 183 | static unsigned long bound_munmap_count; | 183 | static unsigned long long bound_munmap_count; |
| 184 | static unsigned long bound_alloca_count; | 184 | static unsigned long long bound_alloca_count; |
| 185 | static unsigned long bound_mempcy_count; | 185 | static unsigned long long bound_mempcy_count; |
| 186 | static unsigned long bound_memcmp_count; | 186 | static unsigned long long bound_memcmp_count; |
| 187 | static unsigned long bound_memmove_count; | 187 | static unsigned long long bound_memmove_count; |
| 188 | static unsigned long bound_memset_count; | 188 | static unsigned long long bound_memset_count; |
| 189 | static unsigned long bound_strlen_count; | 189 | static unsigned long long bound_strlen_count; |
| 190 | static unsigned long bound_strcpy_count; | 190 | static unsigned long long bound_strcpy_count; |
| 191 | static unsigned long bound_strncpy_count; | 191 | static unsigned long long bound_strncpy_count; |
| 192 | static unsigned long bound_strcmp_count; | 192 | static unsigned long long bound_strcmp_count; |
| 193 | static unsigned long bound_strncmp_count; | 193 | static unsigned long long bound_strncmp_count; |
| 194 | static unsigned long bound_strcat_count; | 194 | static unsigned long long bound_strcat_count; |
| 195 | static unsigned long bound_strchr_count; | 195 | static unsigned long long bound_strchr_count; |
| 196 | static unsigned long bound_strdup_count; | 196 | static unsigned long long bound_strdup_count; |
| 197 | #define INCR_COUNT(x) x++ | 197 | #define INCR_COUNT(x) x++ |
| 198 | #else | 198 | #else |
| 199 | #define INCR_COUNT(x) | 199 | #define INCR_COUNT(x) |
| @@ -235,8 +235,12 @@ void * FASTCALL __bound_ptr_add(void *p, size_t offset) · 35 unmodified lines | |||
| 235 | WAIT_SEM (); | 235 | WAIT_SEM (); |
| 236 | INCR_COUNT(bound_ptr_add_count); | 236 | INCR_COUNT(bound_ptr_add_count); |
| 237 | if (tree) { | 237 | if (tree) { |
| 238 | tree = splay (addr, tree); | ||
| 239 | addr -= tree->start; | 238 | addr -= tree->start; |
| 239 | if (addr >= tree->size) { | ||
| 240 | addr = (size_t)p; | ||
| 241 | tree = splay (addr, tree); | ||
| 242 | addr -= tree->start; | ||
| 243 | } | ||
| 240 | if (addr >= tree->size) { | 244 | if (addr >= tree->size) { |
| 241 | addr = (size_t)p; | 245 | addr = (size_t)p; |
| 242 | tree = splay_end (addr, tree); | 246 | tree = splay_end (addr, tree); |
| @@ -273,8 +277,12 @@ void * FASTCALL __bound_ptr_indir ## dsize (void *p, size_t offset) \ · 30 unmodified lines | |||
| 273 | WAIT_SEM (); \ | 277 | WAIT_SEM (); \ |
| 274 | INCR_COUNT(bound_ptr_indir ## dsize ## _count); \ | 278 | INCR_COUNT(bound_ptr_indir ## dsize ## _count); \ |
| 275 | if (tree) { \ | 279 | if (tree) { \ |
| 276 | tree = splay (addr, tree); \ | ||
| 277 | addr -= tree->start; \ | 280 | addr -= tree->start; \ |
| 281 | if (addr >= tree->size) { \ | ||
| 282 | addr = (size_t)p; \ | ||
| 283 | tree = splay (addr, tree); \ | ||
| 284 | addr -= tree->start; \ | ||
| 285 | } \ | ||
| 278 | if (addr >= tree->size) { \ | 286 | if (addr >= tree->size) { \ |
| 279 | addr = (size_t)p; \ | 287 | addr = (size_t)p; \ |
| 280 | tree = splay_end (addr, tree); \ | 288 | tree = splay_end (addr, tree); \ |
| @@ -968,12 +976,14 @@ char *__bound_strcpy(char *dst, const char *src) · 687 unmodified lines | |||
| 968 | 976 | ||
| 969 | char *__bound_strncpy(char *dst, const char *src, size_t n) | 977 | char *__bound_strncpy(char *dst, const char *src, size_t n) |
| 970 | { | 978 | { |
| 971 | size_t len; | 979 | size_t len = n; |
| 972 | void *p; | 980 | const char *p = src; |
| 973 | 981 | ||
| 982 | while (len-- && *p++); | ||
| 983 | len = p - src; | ||
| 974 | INCR_COUNT(bound_strncpy_count); | 984 | INCR_COUNT(bound_strncpy_count); |
| 975 | __bound_check(dst, n); | 985 | __bound_check(dst, len); |
| 976 | __bound_check(src, n); | 986 | __bound_check(src, len); |
| 977 | return strncpy (dst, src, n); | 987 | return strncpy (dst, src, n); |
| 978 | } | 988 | } |
| 979 | 989 | ||
| @@ -994,10 +1004,23 @@ int __bound_strcmp(const char *s1, const char *s2) · 14 unmodified lines | |||
| 994 | 1004 | ||
| 995 | int __bound_strncmp(const char *s1, const char *s2, size_t n) | 1005 | int __bound_strncmp(const char *s1, const char *s2, size_t n) |
| 996 | { | 1006 | { |
| 1007 | const unsigned char *u1 = (const unsigned char *) s1; | ||
| 1008 | const unsigned char *u2 = (const unsigned char *) s2; | ||
| 1009 | int retval = 0; | ||
| 1010 | |||
| 997 | INCR_COUNT(bound_strncmp_count); | 1011 | INCR_COUNT(bound_strncmp_count); |
| 998 | __bound_check(s1, n); | 1012 | do { |
| 999 | __bound_check(s2, n); | 1013 | if ((ssize_t) --n == -1) |
| 1000 | return strncmp(s1, s2, n); | 1014 | break; |
| 1015 | else if (*u1 != *u2) { | ||
| 1016 | retval = *u1 - *u2; | ||
| 1017 | break; | ||
| 1018 | } | ||
| 1019 | u2++; | ||
| 1020 | } while (*u1++); | ||
| 1021 | __bound_check(s1, ((const char *)u1 - s1) + 1); | ||
| 1022 | __bound_check(s2, ((const char *)u1 - s1) + 1); | ||
| 1023 | return retval; | ||
| 1001 | } | 1024 | } |
| 1002 | 1025 | ||
| 1003 | char *__bound_strcat(char *dest, const char *src) | 1026 | char *__bound_strcat(char *dest, const char *src) |