summaryrefslogtreecommitdiff
path: root/libhfuzz/memorycmp.c
diff options
context:
space:
mode:
Diffstat (limited to 'libhfuzz/memorycmp.c')
-rw-r--r--libhfuzz/memorycmp.c16
1 files changed, 9 insertions, 7 deletions
diff --git a/libhfuzz/memorycmp.c b/libhfuzz/memorycmp.c
index b955314d..4a42ed95 100644
--- a/libhfuzz/memorycmp.c
+++ b/libhfuzz/memorycmp.c
@@ -2,7 +2,6 @@
#include <inttypes.h>
#include <stdbool.h>
#include <stdint.h>
-#include <string.h>
#include <unistd.h>
#include "libhfcommon/common.h"
@@ -67,13 +66,13 @@ static inline int HF_strncasecmp(const char* s1, const char* s2, size_t n, uintp
}
static inline char* HF_strstr(const char* haystack, const char* needle, uintptr_t addr) {
- size_t needle_len = strlen(needle);
+ size_t needle_len = __builtin_strlen(needle);
if (needle_len == 0) {
return (char*)haystack;
}
const char* h = haystack;
- for (; (h = strchr(h, needle[0])) != NULL; h++) {
+ for (; (h = __builtin_strchr(h, needle[0])) != NULL; h++) {
if (HF_strncmp(h, needle, needle_len, addr) == 0) {
return (char*)h;
}
@@ -82,7 +81,7 @@ static inline char* HF_strstr(const char* haystack, const char* needle, uintptr_
}
static inline char* HF_strcasestr(const char* haystack, const char* needle, uintptr_t addr) {
- size_t needle_len = strlen(needle);
+ size_t needle_len = __builtin_strlen(needle);
for (size_t i = 0; haystack[i]; i++) {
if (HF_strncasecmp(&haystack[i], needle, needle_len, addr) == 0) {
return (char*)(&haystack[i]);
@@ -128,10 +127,13 @@ static inline void* HF_memmem(const void* haystack, size_t haystacklen, const vo
}
static inline char* HF_strcpy(char* dest, const char* src, uintptr_t addr) {
- size_t len = strlen(src);
+ size_t len = __builtin_strlen(src);
+ if (len > 0) {
+ uint32_t level = (sizeof(len) * 8) - __builtin_clzl(len);
+ instrumentUpdateCmpMap(addr, level);
+ }
- instrumentUpdateCmpMap(addr, len);
- return memcpy(dest, src, len + 1);
+ return __builtin_memcpy(dest, src, len + 1);
}
/* Define a weak function x, as well as __wrap_x pointing to x */