Make more functions friendly to Address Sanitizer

This commit is contained in:
Justine Tunney 2021-02-02 03:45:31 -08:00
parent 3ab76b2312
commit cbfd4ccd1e
70 changed files with 1267 additions and 291 deletions

View file

@ -23,7 +23,15 @@
#include "libc/testlib/ezbench.h"
#include "libc/testlib/testlib.h"
void *memccpy2(void *, const void *, int, size_t);
void *memccpy$pure(void *d, const void *s, int c, size_t n) {
size_t i;
unsigned char *x;
const unsigned char *y;
for (c &= 0xff, x = d, y = s, i = 0; i < n; ++i) {
if ((x[i] = y[i]) == c) return x + i + 1;
}
return NULL;
}
TEST(memccpy, testStringCopy) {
char buf[16];
@ -49,7 +57,7 @@ TEST(memccpy, memcpy) {
b2 = calloc(1, n);
b3 = calloc(1, n);
rngset(b1, n, rand64, -1);
e1 = tinymemccpy(b2, b1, 31337, n);
e1 = memccpy$pure(b2, b1, 31337, n);
e2 = memccpy(b3, b1, 31337, n);
n1 = e1 ? e1 - b2 : n;
n2 = e2 ? e2 - b3 : n;