From 091f53ce4efdad44d09e73fedd89965925d7e4bb Mon Sep 17 00:00:00 2001 From: Victor Julien Date: Fri, 24 Sep 2010 14:08:57 +0200 Subject: [PATCH] Fix retval of SCMemcmp for non-SIMD implementation. --- src/util-memcmp.c | 5 ++++- src/util-memcmp.h | 8 +++++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/util-memcmp.c b/src/util-memcmp.c index 5d9f4f9a94..39dc02456b 100644 --- a/src/util-memcmp.c +++ b/src/util-memcmp.c @@ -67,8 +67,11 @@ static int MemcmpTest04 (void) { uint8_t a[] = "abcd"; uint8_t b[] = "abcD"; - if (SCMemcmp(a, b, sizeof(a)-1) != 1) + int r = SCMemcmp(a, b, sizeof(a)-1); + if (r != 1) { + printf("%s != %s, but memcmp returned %d: ", a, b, r); return 0; + } return 1; } diff --git a/src/util-memcmp.h b/src/util-memcmp.h index 6883c44c60..ba44e078cd 100644 --- a/src/util-memcmp.h +++ b/src/util-memcmp.h @@ -21,6 +21,9 @@ * \author Victor Julien * * Memcmp implementations for SSE3, SSE4.1 and SSE4.2. + * + * Both SCMemcmp and SCMemcmpLowercase return 0 on a exact match, + * 1 on a failed match. */ #ifndef __UTIL_MEMCMP_H__ @@ -302,7 +305,10 @@ static inline int SCMemcmpLowercase(void *s1, void *s2, size_t len) { /* No SIMD support, fall back to plain memcmp and a home grown lowercase one */ -#define SCMemcmp memcmp +/* wrapper around memcmp to match the retvals of the SIMD implementations */ +#define SCMemcmp(a,b,c) ({ \ + memcmp((a), (b), (c)) ? 1 : 0; \ +}) static inline int SCMemcmpLowercase(void *s1, void *s2, size_t n) {