]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
remove usage of bzero
authorMichael Tokarev <mjt@tls.msk.ru>
Mon, 18 Nov 2024 12:00:05 +0000 (15:00 +0300)
committerPavel Filipensky <pfilipensky@samba.org>
Thu, 2 Jan 2025 17:01:30 +0000 (17:01 +0000)
bzero() function has been deprecated for a long time.
In samba it is replaced with memset().  But samba also
provides common memory-zeroing macros, like ZERO_STRUCT().
In all places where bzero() is used, it actually meant to
zero a structure or an array.

So replace these bzero() calls with ZERO_STRUCT() or
ZERO_ARRAY() as appropriate, and remove bzero() replacement
and testing entirely.

While at it, also stop checking for presence of memset() -
this function is standard for a very long time, and the
only conditional where HAVE_MEMSET were used, was to
provide replacement for bzero() - in all other places
memset() is used unconditionally.

Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>
Reviewed-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Pavel Filipenský <pfilipensky@samba.org>
ctdb/server/ctdb_statistics.c
ctdb/server/ipalloc_common.c
ctdb/tools/ctdb.c
lib/replace/README
lib/replace/replace.h
lib/replace/tests/testsuite.c
lib/replace/wscript

index 4cf8f9e2726a1aa51a3634ae0057212c1cd72c1c..d804c8511cd41b44c6369e0c27856940f85b6b1f 100644 (file)
@@ -42,7 +42,7 @@ static void ctdb_statistics_update(struct tevent_context *ev,
        ctdb->statistics_history[0].statistics_current_time = timeval_current();
 
 
-       bzero(&ctdb->statistics_current, sizeof(struct ctdb_statistics));
+       ZERO_STRUCT(ctdb->statistics_current);
        ctdb->statistics_current.statistics_start_time = timeval_current();
 
        tevent_add_timer(ctdb->ev, ctdb,
@@ -52,13 +52,13 @@ static void ctdb_statistics_update(struct tevent_context *ev,
 
 int ctdb_statistics_init(struct ctdb_context *ctdb)
 {
-       bzero(&ctdb->statistics, sizeof(struct ctdb_statistics));
+       ZERO_STRUCT(ctdb->statistics);
        ctdb->statistics.statistics_start_time = timeval_current();
 
-       bzero(&ctdb->statistics_current, sizeof(struct ctdb_statistics));
+       ZERO_STRUCT(ctdb->statistics_current);
        ctdb->statistics_current.statistics_start_time = timeval_current();
 
-       bzero(ctdb->statistics_history, sizeof(ctdb->statistics_history));
+       ZERO_ARRAY(ctdb->statistics_history);
 
        tevent_add_timer(ctdb->ev, ctdb,
                         timeval_current_ofs(ctdb->tunable.stat_history_interval, 0),
index a5177d41dc6bd8a0657b0640f98d704db224bfc1..e9a9f8b85843cf153a3bec41987c5c50ddd098e8 100644 (file)
@@ -123,7 +123,7 @@ uint32_t *ip_key(ctdb_sock_addr *ip)
 {
        static uint32_t key[IP_KEYLEN];
 
-       bzero(key, sizeof(key));
+       ZERO_ARRAY(key);
 
        switch (ip->sa.sa_family) {
        case AF_INET:
index bf99e7bc526c8a21771af683afda657b47e268d0..44ab248391b450e8f9efe6f95b1afeb3118ce103 100644 (file)
@@ -5597,7 +5597,7 @@ static int control_checktcpport(TALLOC_CTX *mem_ctx, struct ctdb_context *ctdb,
                return errno;
        }
 
-       bzero(&sin, sizeof(sin));
+       ZERO_STRUCT(sin);
        sin.sin_family = AF_INET;
        sin.sin_port = htons(port);
        ret = bind(s, (struct sockaddr *)&sin, sizeof(sin));
index 6612eabd22a390b8747195953cd0b8eac947d090..d9155aa7b99ddffbd2ab717b1e4a8a8e35c3908f 100644 (file)
@@ -40,7 +40,6 @@ dlclose
 dlsym
 dlerror
 chroot
-bzero
 strerror
 errno
 mkdtemp
@@ -123,6 +122,5 @@ Optional C keywords:
 volatile
 
 Prerequisites:
-memset (for bzero)
 syslog (for vsyslog)
 mktemp (for mkstemp and mkdtemp)
index b4bc1327824597cf3fa84a22c315564c3bbc3cca..4923e1f301d6db8cedf98187473ccf016e9e9506 100644 (file)
@@ -414,10 +414,6 @@ int rep_ftruncate(int,off_t);
 int rep_initgroups(char *name, gid_t id);
 #endif
 
-#if !defined(HAVE_BZERO) && defined(HAVE_MEMSET)
-#define bzero(a,b) memset((a),'\0',(b))
-#endif
-
 #ifndef HAVE_DLERROR
 #define dlerror rep_dlerror
 char *rep_dlerror(void);
index 58624f11eb6559dcd41acc14cac9d34ad1069114..7c9195b4753adab6422c435d4f4a8f3e6dbc5539 100644 (file)
@@ -451,12 +451,6 @@ static int test_chroot(void)
        return true;
 }
 
-static int test_bzero(void)
-{
-       /* FIXME: bzero */
-       return true;
-}
-
 static int test_strerror(void)
 {
        /* FIXME */
@@ -1200,7 +1194,6 @@ bool torture_local_replace(struct torture_context *ctx)
        ret &= test_seekdir();
        ret &= test_dlopen();
        ret &= test_chroot();
-       ret &= test_bzero();
        ret &= test_strerror();
        ret &= test_errno();
        ret &= test_mkdtemp();
index f5114b69ffc541fc648cb1d5a226d5c028d20f25..9c0cb7047f11904d57eca6498acb3a25524fe880 100644 (file)
@@ -397,7 +397,7 @@ def configure(conf):
                     msg='Checking for fallthrough attribute')
 
     # these may be builtins, so we need the link=False strategy
-    conf.CHECK_FUNCS('strdup memmem printf memset memcpy memmove strcpy strncpy bzero', link=False)
+    conf.CHECK_FUNCS('strdup memmem printf memcpy memmove strcpy strncpy', link=False)
 
     # See https://bugzilla.samba.org/show_bug.cgi?id=1097
     #