From ecb1179b273a0cbadff434a31e835f2bf9b0792c Mon Sep 17 00:00:00 2001 From: Philippe Antoine Date: Thu, 2 Jul 2026 15:28:39 +0200 Subject: [PATCH] util: remove memrchr As its only usage got rustified --- configure.ac | 2 +- src/Makefile.am | 2 -- src/app-layer-htp-xff.c | 4 --- src/runmode-unittests.c | 2 -- src/util-memrchr.c | 77 ----------------------------------------- src/util-memrchr.h | 30 ---------------- 6 files changed, 1 insertion(+), 116 deletions(-) delete mode 100644 src/util-memrchr.c delete mode 100644 src/util-memrchr.h diff --git a/configure.ac b/configure.ac index 85416b18fc..f138079648 100644 --- a/configure.ac +++ b/configure.ac @@ -207,7 +207,7 @@ AC_FUNC_MMAP AC_FUNC_STRTOD - AC_CHECK_FUNCS([memmem memset memchr memrchr memmove]) + AC_CHECK_FUNCS([memmem memset memchr memmove]) AC_CHECK_FUNCS([strcasecmp strchr strrchr strdup strndup strncasecmp strtol strstr strpbrk strtoull strtoumax]) AC_CHECK_FUNCS([strerror]) AC_CHECK_FUNCS([gethostname inet_ntoa uname]) diff --git a/src/Makefile.am b/src/Makefile.am index cea03c08a8..4b5dd142e1 100755 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -540,7 +540,6 @@ noinst_HEADERS = \ util-mem.h \ util-memcmp.h \ util-memcpy.h \ - util-memrchr.h \ util-misc.h \ util-mpm-ac-ks.h \ util-mpm-ac-queue.h \ @@ -1098,7 +1097,6 @@ libsuricata_c_a_SOURCES = \ util-magic.c \ util-mem.c \ util-memcmp.c \ - util-memrchr.c \ util-misc.c \ util-mpm-ac-ks-small.c \ util-mpm-ac-ks.c \ diff --git a/src/app-layer-htp-xff.c b/src/app-layer-htp-xff.c index be15381698..4f628f72c8 100644 --- a/src/app-layer-htp-xff.c +++ b/src/app-layer-htp-xff.c @@ -29,10 +29,6 @@ #include "app-layer-htp.h" #include "app-layer-htp-xff.h" -#ifndef HAVE_MEMRCHR -#include "util-memrchr.h" -#endif - #include "util-misc.h" #include "util-unittest.h" diff --git a/src/runmode-unittests.c b/src/runmode-unittests.c index 3d31c884fa..d7b03bc21c 100644 --- a/src/runmode-unittests.c +++ b/src/runmode-unittests.c @@ -92,7 +92,6 @@ #include "util-proto-name.h" #include "util-macset.h" #include "util-flow-rate.h" -#include "util-memrchr.h" #include "util-mpm-ac.h" #include "util-mpm-hs.h" @@ -209,7 +208,6 @@ static void RegisterUnittests(void) DetectPortTests(); DetectEngineAlertRegisterTests(); SCAtomicRegisterTests(); - MemrchrRegisterTests(); AppLayerUnittestsRegister(); StreamingBufferRegisterTests(); MacSetRegisterTests(); diff --git a/src/util-memrchr.c b/src/util-memrchr.c deleted file mode 100644 index c490481b57..0000000000 --- a/src/util-memrchr.c +++ /dev/null @@ -1,77 +0,0 @@ -/* Copyright (C) 2007-2013 Open Information Security Foundation - * - * You can copy, redistribute or modify this Program under the terms of - * the GNU General Public License version 2 as published by the Free - * Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * version 2 along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - * 02110-1301, USA. - */ - -/** - * \file - * - * \author Victor Julien - * - */ - -#include "suricata-common.h" -#include "util-unittest.h" -#include "util-memrchr.h" - -#if !defined(HAVE_MEMRCHR) || defined(UNITTESTS) -static void *SCMemrchrFallback(const void *s, int c, size_t n) -{ - const unsigned char *p = (const unsigned char *)s + n; - const unsigned char uc = (unsigned char)c; - - while (p > (const unsigned char *)s) { - p--; - if (*p == uc) - return (void *)p; - } - return NULL; -} -#endif - -#ifndef HAVE_MEMRCHR -void *memrchr(const void *s, int c, size_t n) -{ - return SCMemrchrFallback(s, c, n); -} -#endif /* HAVE_MEMRCHR */ - -#ifdef UNITTESTS -static int MemrchrTest01 (void) -{ - char buf[] = { 'x', 'y', 'z' }; - char one_byte[] = { 'q' }; - char dup[] = { 'a', 'b', 'a' }; - unsigned char high_byte[] = { 0x80, 'x', 0x80 }; - - FAIL_IF(SCMemrchrFallback(buf, 'x', sizeof(buf)) != &buf[0]); - FAIL_IF(SCMemrchrFallback(buf, 'z', sizeof(buf)) != &buf[2]); - FAIL_IF(SCMemrchrFallback(buf, 'y', sizeof(buf)) != &buf[1]); - FAIL_IF(SCMemrchrFallback(buf, 'a', sizeof(buf)) != NULL); - FAIL_IF(SCMemrchrFallback(one_byte, 'q', sizeof(one_byte)) != &one_byte[0]); - FAIL_IF(SCMemrchrFallback(one_byte, 'q', 0) != NULL); - FAIL_IF(SCMemrchrFallback(dup, 'a', sizeof(dup)) != &dup[2]); - FAIL_IF(SCMemrchrFallback(high_byte, 0x80, sizeof(high_byte)) != &high_byte[2]); - - PASS; -} -#endif - -void MemrchrRegisterTests(void) -{ -#ifdef UNITTESTS - UtRegisterTest("MemrchrTest01", MemrchrTest01); -#endif -} diff --git a/src/util-memrchr.h b/src/util-memrchr.h deleted file mode 100644 index 0a5ddfb85d..0000000000 --- a/src/util-memrchr.h +++ /dev/null @@ -1,30 +0,0 @@ -/* Copyright (C) 2007-2010 Open Information Security Foundation - * - * You can copy, redistribute or modify this Program under the terms of - * the GNU General Public License version 2 as published by the Free - * Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * version 2 along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - * 02110-1301, USA. - */ - -/** - * \file - * - */ - -#ifndef SURICATA_UTIL_MEMRCHR_H -#define SURICATA_UTIL_MEMRCHR_H - -void *memrchr(const void *s, int c, size_t n); - -void MemrchrRegisterTests(void); - -#endif /* SURICATA_UTIL_MEMRCHR_H */