From abf5e8824a9566ab74685445eff9b176ead5c7d9 Mon Sep 17 00:00:00 2001 From: rim Date: Sun, 28 Apr 2024 04:19:01 +0300 Subject: [PATCH] Remove syntax shugar: mem_set(), mem_bzero(), zalloc(), zallocarray(), mem_new(), mem_znew(), mallocarray(). --- include/al/hw.h | 2 +- include/al/os.h | 2 +- include/crypto/hash/gost3411-2012.h | 2 +- include/crypto/hash/md5.h | 2 +- include/crypto/hash/sha1.h | 2 +- include/crypto/hash/sha2.h | 2 +- include/math/big_num.h | 2 +- include/net/host_address.h | 10 +++++----- include/net/hostname_list.h | 8 +++++--- include/proto/dns.h | 2 +- include/proto/radius.h | 2 +- include/utils/hash_bucket.h | 2 +- include/utils/mem_utils.h | 29 ++++------------------------- lib.project | 2 -- src/net/socket.c | 17 ++++++++--------- src/net/socket_address.c | 8 ++++---- src/net/socket_options.c | 10 ++++------ src/net/utils.c | 2 +- src/proto/bt_tracker.c | 8 ++++---- src/proto/dns_resolv.c | 15 ++++++++------- src/proto/http.c | 4 ++-- src/proto/http_client.c | 12 ++++++------ src/proto/http_server.c | 19 ++++++++++--------- src/proto/http_server_auth.c | 4 ++-- src/proto/radius_client.c | 27 +++++++++++++-------------- src/proto/sap_rcvr.c | 6 +++--- src/proto/upnp_ssdp.c | 16 ++++++++-------- src/threadpool/threadpool.c | 26 +++++++++++++------------- src/threadpool/threadpool_msg_sys.c | 8 ++++---- src/threadpool/threadpool_task.c | 7 +++---- src/utils/bt_encode.c | 4 ++-- src/utils/buf_str.c | 8 ++++---- src/utils/cmd_line_daemon.c | 2 +- src/utils/data_cache.c | 9 ++++----- src/utils/info.c | 2 +- src/utils/ini.c | 6 +++--- src/utils/ring_buffer.c | 4 ++-- src/utils/sys.c | 2 +- src/utils/sys_res_limits_xml.c | 2 +- src/utils/xml.c | 4 ++-- tests/base64/main.c | 2 +- tests/ecdsa/main.c | 2 +- tests/threadpool/main.c | 2 +- 43 files changed, 141 insertions(+), 166 deletions(-) diff --git a/include/al/hw.h b/include/al/hw.h index c9e2d9c..4fe9c77 100644 --- a/include/al/hw.h +++ b/include/al/hw.h @@ -38,7 +38,7 @@ #include #include -#include /* bcopy, bzero, memcpy, memmove, memset, strerror... */ +#include /* memcpy, memmove, memset, strerror... */ #include /* close, write, sysconf */ #include /* open, fcntl */ #include diff --git a/include/al/os.h b/include/al/os.h index b847b46..cc3fc55 100644 --- a/include/al/os.h +++ b/include/al/os.h @@ -39,7 +39,7 @@ #include #include #include /* open, fcntl */ -#include /* bcopy, bzero, memcpy, memmove, memset, strnlen, strerror... */ +#include /* memcpy, memmove, memset, strnlen, strerror... */ #include /* explicit_bzero */ #include /* close, write, sysconf */ #include /* malloc, realloc */ diff --git a/include/crypto/hash/gost3411-2012.h b/include/crypto/hash/gost3411-2012.h index e18778a..82d7aad 100644 --- a/include/crypto/hash/gost3411-2012.h +++ b/include/crypto/hash/gost3411-2012.h @@ -39,7 +39,7 @@ #include #include -#include /* bcopy, bzero, memcpy, memmove, memset, strerror... */ +#include /* memcpy, memmove, memset, strerror... */ #include #ifdef __SSE2__ # include diff --git a/include/crypto/hash/md5.h b/include/crypto/hash/md5.h index 30825ff..f4764fe 100644 --- a/include/crypto/hash/md5.h +++ b/include/crypto/hash/md5.h @@ -36,7 +36,7 @@ #include #include -#include /* bcopy, bzero, memcpy, memmove, memset, strerror... */ +#include /* memcpy, memmove, memset, strerror... */ #include #ifndef nitems /* SIZEOF() */ diff --git a/include/crypto/hash/sha1.h b/include/crypto/hash/sha1.h index 86e76bc..1653067 100644 --- a/include/crypto/hash/sha1.h +++ b/include/crypto/hash/sha1.h @@ -66,7 +66,7 @@ #include #include -#include /* bcopy, bzero, memcpy, memmove, memset, strerror... */ +#include /* memcpy, memmove, memset, strerror... */ #include #ifdef __SSE2__ # include diff --git a/include/crypto/hash/sha2.h b/include/crypto/hash/sha2.h index 8af92f6..c760311 100644 --- a/include/crypto/hash/sha2.h +++ b/include/crypto/hash/sha2.h @@ -36,7 +36,7 @@ #include #include -#include /* bcopy, bzero, memcpy, memmove, memset, strerror... */ +#include /* memcpy, memmove, memset, strerror... */ #include #if defined(__SHA__) && defined(__SSSE3__) && defined(__SSE4_1__) # include diff --git a/include/math/big_num.h b/include/math/big_num.h index 5293003..2133697 100644 --- a/include/math/big_num.h +++ b/include/math/big_num.h @@ -50,7 +50,7 @@ #else # include # include -# include /* bcopy, bzero, memcpy, memmove, memset, strnlen, strerror... */ +# include /* memcpy, memmove, memset, strnlen, strerror... */ # include /* snprintf, fprintf */ # ifndef __unused # define __unused __attribute__((__unused__)) diff --git a/include/net/host_address.h b/include/net/host_address.h index 38fc5ef..a6c6215 100644 --- a/include/net/host_address.h +++ b/include/net/host_address.h @@ -36,7 +36,7 @@ #include #include #include -#include /* bcopy, bzero, memcpy, memmove, memset, strerror... */ +#include /* memcpy, memmove, memset, strerror... */ #include /* malloc, exit */ #include "utils/macro.h" @@ -75,7 +75,7 @@ host_addr_alloc(const uint8_t *name, size_t name_size, uint16_t def_port) { name_size = (size_t)(ptm_end - name - 1); } - haddr = zalloc((sizeof(host_addr_t) + name_size + sizeof(void*))); + haddr = calloc(1, (sizeof(host_addr_t) + name_size + sizeof(void*))); if (NULL == haddr) return (haddr); haddr->name = (uint8_t*)(haddr + 1); @@ -94,10 +94,10 @@ host_addr_clone(host_addr_p src) { if (NULL == src) return (NULL); - haddr = zallocarray(src->allocated, sizeof(sockaddr_storage_t)); + haddr = calloc(src->allocated, sizeof(sockaddr_storage_t)); if (NULL == haddr) return (haddr); - haddr->addrs = zalloc((sizeof(host_addr_t) + src->name_size + sizeof(void*))); + haddr->addrs = calloc(1, (sizeof(host_addr_t) + src->name_size + sizeof(void*))); if (NULL == haddr->addrs) { free(haddr); return (NULL); @@ -200,7 +200,7 @@ host_addr_resolv(host_addr_p haddr) { if (NULL == haddr) return (EINVAL); - mem_bzero(&hints, sizeof(hints)); + memset(&hints, 0x00, sizeof(hints)); hints.ai_family = PF_UNSPEC; hints.ai_flags = AI_NUMERICSERV; u162str(haddr->port, servname, sizeof(servname), NULL); /* Should not fail. */ diff --git a/include/net/hostname_list.h b/include/net/hostname_list.h index 856e533..c07a530 100644 --- a/include/net/hostname_list.h +++ b/include/net/hostname_list.h @@ -33,6 +33,8 @@ #include #include +#include /* memcpy, memmove, memset, strerror... */ +#include /* explicit_bzero */ #include "utils/mem_utils.h" #define HOSTNAME_PREALLOC 8 @@ -56,7 +58,7 @@ hostname_list_init(hostname_list_p hn_lst) { if (NULL == hn_lst) return (EINVAL); - mem_bzero(hn_lst, sizeof(hostname_list_t)); + explicit_bzero(hn_lst, sizeof(hostname_list_t)); return (0); } @@ -84,7 +86,7 @@ static inline hostname_list_p hostname_list_alloc(void) { hostname_list_p hn_lst; - hn_lst = mem_znew(hostname_list_t); + hn_lst = calloc(1, sizeof(hostname_list_t)); if (NULL == hn_lst) return (hn_lst); if (0 != hostname_list_init(hn_lst)) { @@ -103,7 +105,7 @@ hostname_list_clone(hostname_list_p hn_lst) { hn_new = mem_dup(hn_lst, sizeof(hostname_list_t)); if (NULL == hn_new) return (hn_new); - hn_new->names = zallocarray(hn_new->allocated, sizeof(hostname_p)); + hn_new->names = calloc(hn_new->allocated, sizeof(hostname_p)); if (NULL == hn_new->names) { free(hn_new); return (NULL); diff --git a/include/proto/dns.h b/include/proto/dns.h index 4d2d960..8ec6f40 100644 --- a/include/proto/dns.h +++ b/include/proto/dns.h @@ -34,7 +34,7 @@ #include #include -#include /* bcopy, bzero, memcpy, memmove, memset, strnlen, strerror... */ +#include /* memcpy, memmove, memset, strnlen, strerror... */ #include /* ntohs(), htons(), ntohl(), htonl() */ #include "utils/mem_utils.h" diff --git a/include/proto/radius.h b/include/proto/radius.h index 1cfc1c9..e9ec8b2 100644 --- a/include/proto/radius.h +++ b/include/proto/radius.h @@ -44,7 +44,7 @@ #include #include -#include /* bcopy, bzero, memcpy, memmove, memset, strnlen, strerror... */ +#include /* memcpy, memmove, memset, strnlen, strerror... */ #include #include /* ntohs(), htons() */ #include diff --git a/include/utils/hash_bucket.h b/include/utils/hash_bucket.h index d001720..1276ac8 100644 --- a/include/utils/hash_bucket.h +++ b/include/utils/hash_bucket.h @@ -62,7 +62,7 @@ #else /* User space */ # include # include -# include /* bcopy, bzero, memcpy, memmove, memset, strerror... */ +# include /* memcpy, memmove, memset, strerror... */ # include /* malloc, exit */ # define HB_ALLOC(size) malloc(size) diff --git a/include/utils/mem_utils.h b/include/utils/mem_utils.h index d40dd89..d566536 100644 --- a/include/utils/mem_utils.h +++ b/include/utils/mem_utils.h @@ -1,5 +1,5 @@ /*- - * Copyright (c) 2004 - 2020 Rozhuk Ivan + * Copyright (c) 2004-2024 Rozhuk Ivan * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -478,18 +478,6 @@ mem_cmpin(const void *buf1, const size_t buf1_size, //////////////////////////////////////////////////////////////////////// /////////////////// Memory management wrappers. //////////////////////// //////////////////////////////////////////////////////////////////////// -/* Secure version of memset(). */ -static inline void * -mem_set(void *buf, const size_t size, const uint8_t c) { - - if (NULL == buf || 0 == size) - return (buf); - return (memset_volatile(buf, c, size)); -} - -#define mem_bzero(__buf, __size) mem_set((__buf), (size_t)(__size), 0x00) - - static inline void * mem_dup2(const void *buf, const size_t size, const size_t pad_size) { void *ret; @@ -499,7 +487,7 @@ mem_dup2(const void *buf, const size_t size, const size_t pad_size) { if (NULL == ret) return (ret); memcpy(ret, buf, size); - mem_bzero((((uint8_t*)ret) + size), (alloc_sz - size)); + memset((((uint8_t*)ret) + size), 0x00, (alloc_sz - size)); return (ret); } @@ -507,15 +495,6 @@ mem_dup2(const void *buf, const size_t size, const size_t pad_size) { #define mem_dup(__buf, __size) mem_dup2((__buf), (__size), 0) -/* Allocate and zero memory. */ -#define zalloc(__size) calloc(1, (size_t)(__size)) -#define zallocarray(__nmemb, __size) calloc((__nmemb), (size_t)(__size)) - -#define mem_new(__type) (__type*)malloc(sizeof(__type)) -#define mem_znew(__type) (__type*)zalloc(sizeof(__type)) - -#define mallocarray(__nmemb, __size) reallocarray(NULL, (__nmemb), (size_t)(__size)) - static inline int realloc_items(void **items, const size_t item_size, size_t *allocated, const size_t alloc_blk_cnt, const size_t count) { @@ -534,7 +513,7 @@ realloc_items(void **items, const size_t item_size, if (NULL == items_new) /* Realloc fail! */ return (ENOMEM); if (allocated_new > allocated_prev) { /* Init new mem. */ - mem_bzero((items_new + (allocated_prev * item_size)), + memset((items_new + (allocated_prev * item_size)), 0x00, ((allocated_new - allocated_prev) * item_size)); } (*items) = items_new; @@ -591,7 +570,7 @@ mapalloc_fd(uintptr_t fd, const size_t size) { //munmap(mem, size); //return (NULL); } - mem_bzero(buf, size); + memset(buf, 0x00, size); return (buf); } diff --git a/lib.project b/lib.project index c48bbd4..5931ea0 100644 --- a/lib.project +++ b/lib.project @@ -30,8 +30,6 @@ - - diff --git a/src/net/socket.c b/src/net/socket.c index 075c3d8..5e4a5d6 100644 --- a/src/net/socket.c +++ b/src/net/socket.c @@ -54,12 +54,11 @@ #include #include /* close, write, sysconf */ -#include /* bcopy, bzero, memcpy, memmove, memset, strerror... */ +#include /* memcpy, memmove, memset, strerror... */ #include /* snprintf, fprintf */ #include #include "utils/macro.h" -#include "utils/mem_utils.h" #include "utils/num2str.h" #include "al/os.h" @@ -188,7 +187,7 @@ skt_get_addr_family(uintptr_t skt, sa_family_t *family) { if (NULL == family) return (EINVAL); - mem_bzero(&ssaddr, sizeof(ssaddr)); + memset(&ssaddr, 0x00, sizeof(ssaddr)); addrlen = sizeof(ssaddr); if (0 != getsockname((int)skt, (sockaddr_p)&ssaddr, &addrlen)) return (errno); @@ -260,7 +259,7 @@ skt_mc_join(uintptr_t skt, int join, uint32_t if_index, return (EAFNOSUPPORT); /* Join/leave to multicast group. */ - mem_bzero(&mc_group, sizeof(mc_group)); + memset(&mc_group, 0x00, sizeof(mc_group)); mc_group.gr_interface = if_index; sa_copy(mc_addr, &mc_group.gr_group); if (0 != setsockopt((int)skt, @@ -288,7 +287,7 @@ skt_mc_join_ifname(uintptr_t skt, int join, const char *ifname, } #ifdef SIOCGIFINDEX - mem_bzero(&ifr, sizeof(ifr)); + memset(&ifr, 0x00, sizeof(ifr)); memcpy(ifr.ifr_name, ifname, ifname_size); ifr.ifr_name[ifname_size] = 0; if (-1 == ioctl((int)skt, SIOCGIFINDEX, &ifr)) @@ -544,7 +543,7 @@ skt_recvfrom(uintptr_t skt, void *buf, size_t buf_size, int flags, ]; /* Initialize msghdr for receiving packets. */ - //mem_bzero(&rcvcmsgbuf, sizeof(struct cmsghdr)); + //memset(&rcvcmsgbuf, 0x00, sizeof(struct cmsghdr)); rcviov[0].iov_base = buf; rcviov[0].iov_len = buf_size; mhdr.msg_name = from; /* dst addr. */ @@ -721,7 +720,7 @@ skt_sync_resolv(const char *hname, uint16_t port, int ai_family, if (NULL == hname) return (EINVAL); - mem_bzero(&hints, sizeof(hints)); + memset(&hints, 0x00, sizeof(hints)); hints.ai_family = ai_family; hints.ai_flags = AI_NUMERICSERV; u162str(port, servname, sizeof(servname), NULL); /* Should not fail. */ @@ -753,7 +752,7 @@ skt_sync_resolv_connect(const char *hname, uint16_t port, if (NULL == hname || NULL == skt_ret) return (EINVAL); - mem_bzero(&hints, sizeof(hints)); + memset(&hints, 0x00, sizeof(hints)); hints.ai_family = domain; hints.ai_flags = AI_NUMERICSERV; hints.ai_socktype = type; @@ -846,7 +845,7 @@ skt_tcp_stat_text(uintptr_t skt, const char *tabs, return (EINVAL); optlen = sizeof(info); - mem_bzero(&info, sizeof(info)); + memset(&info, 0x00, sizeof(info)); if (0 != getsockopt((int)skt, IPPROTO_TCP, TCP_INFO, &info, &optlen)) return (errno); if (10 < info.tcpi_state) { diff --git a/src/net/socket_address.c b/src/net/socket_address.c index 8684bdd..315ec5d 100644 --- a/src/net/socket_address.c +++ b/src/net/socket_address.c @@ -37,7 +37,7 @@ #include #include #include -#include /* bcopy, bzero, memcpy, memmove, memset, strerror... */ +#include /* memcpy, memmove, memset, strerror... */ #include "utils/macro.h" #include "utils/mem_utils.h" @@ -69,7 +69,7 @@ sa_init(sockaddr_storage_p addr, const sa_family_t family, switch (family) { case AF_UNIX: - mem_bzero(addr, sizeof(sockaddr_un_t)); + memset(addr, 0x00, sizeof(sockaddr_un_t)); #ifdef BSD /* BSD specific code. */ ((sockaddr_un_p)addr)->sun_len = sizeof(sockaddr_un_t); #endif @@ -77,7 +77,7 @@ sa_init(sockaddr_storage_p addr, const sa_family_t family, //addr->sun_path[] = 0; break; case AF_INET: - mem_bzero(addr, sizeof(sockaddr_in_t)); + memset(addr, 0x00, sizeof(sockaddr_in_t)); #ifdef BSD /* BSD specific code. */ ((sockaddr_in_p)addr)->sin_len = sizeof(sockaddr_in_t); #endif @@ -86,7 +86,7 @@ sa_init(sockaddr_storage_p addr, const sa_family_t family, //addr->sin_addr.s_addr = 0; break; case AF_INET6: - mem_bzero(addr, sizeof(sockaddr_in6_t)); + memset(addr, 0x00, sizeof(sockaddr_in6_t)); #ifdef BSD /* BSD specific code. */ ((sockaddr_in6_p)addr)->sin6_len = sizeof(sockaddr_in6_t); #endif diff --git a/src/net/socket_options.c b/src/net/socket_options.c index 5adb081..5abb667 100644 --- a/src/net/socket_options.c +++ b/src/net/socket_options.c @@ -41,15 +41,13 @@ #include #include /* close, write, sysconf */ -#include /* bcopy, bzero, memcpy, memmove, memset, strerror... */ +#include /* memcpy, memmove, memset, strerror... */ #include /* snprintf, fprintf */ #include #include "utils/macro.h" -#include "utils/mem_utils.h" - -#include "utils/sys.h" #include "al/os.h" +#include "utils/sys.h" #include "net/socket_address.h" #include "net/socket.h" #include "net/socket_options.h" @@ -226,7 +224,7 @@ skt_opts_xml_load(const uint8_t *buf, const size_t buf_size, (const uint8_t*)"AcceptFilterName", NULL)) { if (0 != data_size && sizeof(opts->tcp_acc_filter.af_name) > data_size) { - mem_bzero(&opts->tcp_acc_filter, + memset(&opts->tcp_acc_filter, 0x00, sizeof(struct accept_filter_arg)); memcpy(opts->tcp_acc_filter.af_name, data, data_size); opts->mask |= SO_F_ACC_FILTER; @@ -321,7 +319,7 @@ skt_opts_init(const uint32_t mask, const uint32_t bit_vals, if (NULL == opts) return; - mem_bzero(opts, sizeof(skt_opts_t)); + memset(opts, 0x00, sizeof(skt_opts_t)); opts->mask = (SO_F_BIT_VALS_MASK & mask); opts->bit_vals = bit_vals; opts->backlog = INT_MAX; diff --git a/src/net/utils.c b/src/net/utils.c index bd4e085..dccb72f 100644 --- a/src/net/utils.c +++ b/src/net/utils.c @@ -38,7 +38,7 @@ #include #include #include /* snprintf, fprintf */ -#include /* bcopy, bzero, memcpy, memmove, memset, strerror... */ +#include /* memcpy, memmove, memset, strerror... */ #include "utils/macro.h" #include "utils/mem_utils.h" diff --git a/src/proto/bt_tracker.c b/src/proto/bt_tracker.c index 64547a4..5d8319e 100644 --- a/src/proto/bt_tracker.c +++ b/src/proto/bt_tracker.c @@ -1,5 +1,5 @@ /*- - * Copyright (c) 2011 - 2020 Rozhuk Ivan + * Copyright (c) 2011-2024 Rozhuk Ivan * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -31,7 +31,7 @@ #include #include #include -#include /* bcopy, bzero, memcpy, memmove, memset, strerror... */ +#include /* memcpy, memmove, memset, strerror... */ #include #include "utils/mem_utils.h" @@ -45,7 +45,7 @@ bt_tr_ann_ans_p bt_tr_ann_ans_alloc(void) { - return (mem_znew(bt_tr_ann_ans_t)); + return (calloc(1, sizeof(bt_tr_ann_ans_t))); } @@ -152,7 +152,7 @@ bt_tr_ann_ans_decode(uint8_t *buf, size_t buf_size, bt_tr_ann_ans_p *ret_data) { val->val.s, 0); break; default: /* unknown/error */ - //mem_bzero(&tr_ans->ext_ip, sizeof(bt_tr_ss_addr_t)); + //memset(&tr_ans->ext_ip, 0x00, sizeof(bt_tr_ss_addr_t)); break; } } diff --git a/src/proto/dns_resolv.c b/src/proto/dns_resolv.c index b0b6ded..18e7541 100644 --- a/src/proto/dns_resolv.c +++ b/src/proto/dns_resolv.c @@ -40,7 +40,8 @@ #include #include #include /* close, write, sysconf */ -#include /* bcopy, bzero, memcpy, memmove, memset, strerror... */ +#include /* memcpy, memmove, memset, strerror... */ +#include /* explicit_bzero */ #include #include /* snprintf, fprintf */ #include @@ -271,7 +272,7 @@ dns_rslvr_cache_entry_alloc(uint8_t *name, size_t name_size, SYSLOG_EX(LOG_ERR, "name = %s, name_size = %zu", name, name_size); return (EINVAL); } - cache_entry = zalloc((sizeof(dns_rslvr_cache_entry_t) + name_size + sizeof(void*))); + cache_entry = calloc(1, (sizeof(dns_rslvr_cache_entry_t) + name_size + sizeof(void*))); if (NULL == cache_entry) return (ENOMEM); cache_entry->entry.data = cache_entry; @@ -371,7 +372,7 @@ dns_rslvr_cache_entry_data_add(dns_rslvr_cache_entry_p cache_entry, void *data, cache_entry->data_allocated = data_count; } memcpy(cache_entry->pdata, data, data_count); - mem_bzero((cache_entry->pdata + data_count), 2); + explicit_bzero((cache_entry->pdata + data_count), 2); goto data_upd_done; } /* IP addrs set. */ @@ -484,7 +485,7 @@ dns_rslvr_task_alloc(dns_rslvr_p rslvr, dns_resolv_cb cb_func, void *arg, } if (0 != rslvr->tasks_tmr[task_id].ident) return (EAGAIN); /* No free task slot. */ - task = mem_znew(dns_rslvr_task_t); + task = calloc(1, sizeof(dns_rslvr_task_t)); if (NULL == task) return (ENOMEM); rslvr->tasks_index = task_id; @@ -561,10 +562,10 @@ dns_resolver_create(tp_p tp, const sockaddr_storage_t *dns_addrs, NULL == dns_rslvr_ret) return (EINVAL); - rslvr = mem_znew(dns_rslvr_t); + rslvr = calloc(1, sizeof(dns_rslvr_t)); if (NULL == rslvr) return (ENOMEM); - rslvr->dns_addrs = zallocarray(dns_addrs_count, sizeof(sockaddr_storage_t)); + rslvr->dns_addrs = calloc(dns_addrs_count, sizeof(sockaddr_storage_t)); if (NULL == rslvr->dns_addrs) { error = ENOMEM; goto err_out; @@ -584,7 +585,7 @@ dns_resolver_create(tp_p tp, const sockaddr_storage_t *dns_addrs, if (0 != error) goto err_out; - mem_bzero(rslvr->dns_addrs, + memset(rslvr->dns_addrs, 0x00, (sizeof(sockaddr_storage_t) * dns_addrs_count)); rslvr->dns_addrs_count = dns_addrs_count; for (i = 0; i < dns_addrs_count; i ++) { diff --git a/src/proto/http.c b/src/proto/http.c index c6abe7c..ab4e163 100644 --- a/src/proto/http.c +++ b/src/proto/http.c @@ -35,7 +35,7 @@ #include //#include //#include /* snprintf, fprintf */ -#include /* bcopy, bzero, memcpy, memmove, memset, strerror... */ +#include /* memcpy, memmove, memset, strerror... */ #include #include "utils/macro.h" @@ -462,7 +462,7 @@ http_parse_req_line(const uint8_t *http_hdr, size_t hdr_size, if ('A' > (*http_hdr) || 'Z' < (*http_hdr)) return (EBADMSG); - mem_bzero(req_data, sizeof(http_req_line_data_t)); + memset(req_data, 0x00, sizeof(http_req_line_data_t)); /* Look for end of req line. */ pspace = mem_find_cstr(http_hdr, hdr_size, CRLF); if (NULL == pspace) { diff --git a/src/proto/http_client.c b/src/proto/http_client.c index 29634fb..f5d4eb9 100644 --- a/src/proto/http_client.c +++ b/src/proto/http_client.c @@ -42,7 +42,7 @@ #include /* malloc, exit */ #include /* close, write, sysconf */ -#include /* bcopy, bzero, memcpy, memmove, memset, strerror... */ +#include /* memcpy, memmove, memset, strerror... */ #include /* snprintf, fprintf */ #include #include @@ -117,7 +117,7 @@ http_cli_def_settings(int add_os_ver, const char *app_ver, int add_lib_ver, if (NULL == s_ret) return; /* Init. */ - mem_bzero(s_ret, sizeof(http_cli_settings_t)); + memset(s_ret, 0x00, sizeof(http_cli_settings_t)); io_net_skt_opts_init(HTTP_CLI_S_SKT_OPTS_INT_MASK, HTTP_CLI_S_SKT_OPTS_INT_VALS, &s_ret->skt_opts); s_ret->skt_opts.mask |= SO_F_NONBLOCK; @@ -189,7 +189,7 @@ http_cli_create(http_cli_cb ccb, http_cli_settings_p s, void *udata, } } /* Create. */ - cli = mem_znew(http_cli_t); + cli = calloc(1, sizeof(http_cli_t)); if (NULL == cli) { error = ENOMEM; goto err_out; @@ -271,7 +271,7 @@ http_cli_conn_create(http_cli_p cli, thrpt_p thrpt, http_cli_cb ccb, if (NULL == cli || NULL == cli_conn_ret) return (EINVAL); - cli_conn = mem_znew(http_cli_conn_t); + cli_conn = calloc(1, sizeof(http_cli_conn_t)); if (NULL == cli_conn) return (errno); @@ -1324,7 +1324,7 @@ http_srv_snd(http_cli_p cli, uint32_t status_code, /* Send data... */ /* Try "zero copy" send first. */ - mem_bzero(&mhdr, sizeof(mhdr)); + memset(&mhdr, 0x00, sizeof(mhdr)); mhdr.msg_iov = iov; mhdr.msg_iovlen ++; iov[0].iov_base = hdrs; @@ -1473,7 +1473,7 @@ http_cli_snd_done_cb(io_task_p iotask __unused, int error, io_buf_p buf __unused tm = (cli->rcv_buf->used - (cli->req.data - cli->rcv_buf->data)); memmove(cli->rcv_buf->data, cli->req.data, tm); /* Re init client. */ - mem_bzero(&cli->req, sizeof(http_srv_req_t)); + memset(&cli->req, 0x00, sizeof(http_srv_req_t)); cli->resp_p_flags = 0; /* Receive next http request. */ IO_BUF_BUSY_SIZE_SET(cli->rcv_buf, tm); diff --git a/src/proto/http_server.c b/src/proto/http_server.c index 4552c86..bc8c13e 100644 --- a/src/proto/http_server.c +++ b/src/proto/http_server.c @@ -37,7 +37,8 @@ #include #include /* malloc, exit */ #include /* close, write, sysconf */ -#include /* bcopy, bzero, memcpy, memmove, memset, strerror... */ +#include /* memcpy, memmove, memset, strerror... */ +#include /* explicit_bzero */ #include /* snprintf, fprintf */ #include #include @@ -141,7 +142,7 @@ http_srv_def_settings(int add_os_ver, const char *app_ver, int add_lib_ver, if (NULL == s_ret) return; /* Init. */ - mem_bzero(s_ret, sizeof(http_srv_settings_t)); + memset(s_ret, 0x00, sizeof(http_srv_settings_t)); skt_opts_init(HTTP_SRV_S_SKT_OPTS_INT_MASK, HTTP_SRV_S_SKT_OPTS_INT_VALS, &s_ret->skt_opts); s_ret->skt_opts.mask |= SO_F_NONBLOCK; @@ -201,7 +202,7 @@ http_srv_bind_def_settings(skt_opts_p skt_opts, http_srv_bind_settings_p s_ret) if (NULL == s_ret) return; - mem_bzero(s_ret, sizeof(http_srv_bind_settings_t)); + memset(s_ret, 0x00, sizeof(http_srv_bind_settings_t)); /* default settings */ memcpy(&s_ret->skt_opts, skt_opts, sizeof(skt_opts_t)); } @@ -401,7 +402,7 @@ http_srv_create(tp_p tp, http_srv_on_conn_cb on_conn, } } /* Create. */ - srv = mem_znew(http_srv_t); + srv = calloc(1, sizeof(http_srv_t)); if (NULL == srv) { error = ENOMEM; goto err_out; @@ -593,7 +594,7 @@ http_srv_bind_add(http_srv_p srv, http_srv_bind_settings_p s, if (NULL == srv || NULL == s) return (EINVAL); - bnd = mem_znew(http_srv_bind_t); + bnd = calloc(1, sizeof(http_srv_bind_t)); if (NULL == bnd) return (ENOMEM); bnd->srv = srv; @@ -720,7 +721,7 @@ http_srv_cli_alloc(http_srv_bind_p bnd, tpt_p tpt, uintptr_t skt, SYSLOGD_EX(LOG_DEBUG, "..."); - cli = mem_znew(http_srv_cli_t); + cli = calloc(1, sizeof(http_srv_cli_t)); if (NULL == cli) return (cli); bnd->srv->stat.connections ++; @@ -785,8 +786,8 @@ http_srv_cli_next_req(http_srv_cli_p cli) { /* Update used buf size. */ IO_BUF_BUSY_SIZE_SET(cli->rcv_buf, tm); /* Re init client. */ - mem_bzero(&cli->req, sizeof(http_srv_req_t)); - mem_bzero(&cli->resp, sizeof(http_srv_resp_t)); + explicit_bzero(&cli->req, sizeof(http_srv_req_t)); + explicit_bzero(&cli->resp, sizeof(http_srv_resp_t)); } tp_task_p @@ -1748,7 +1749,7 @@ http_srv_snd(http_srv_cli_p cli) { /* Send data... */ /* Try "zero copy" send first. */ - mem_bzero(&mhdr, sizeof(mhdr)); + memset(&mhdr, 0x00, sizeof(mhdr)); mhdr.msg_iov = iov; mhdr.msg_iovlen ++; iov[0].iov_base = hdrs; diff --git a/src/proto/http_server_auth.c b/src/proto/http_server_auth.c index d01f525..b3bd7ef 100644 --- a/src/proto/http_server_auth.c +++ b/src/proto/http_server_auth.c @@ -38,7 +38,7 @@ #include #include /* malloc, exit */ -#include /* bcopy, bzero, memcpy, memmove, memset, strerror... */ +#include /* memcpy, memmove, memset, strerror... */ #include /* snprintf, fprintf */ #include @@ -325,7 +325,7 @@ http_srv_auth_start(http_srv_cli_p cli, auth_pl_p plugin, return (500); if (http_srv_auth_on_req_rcv_cb == http_srv_cli_get_on_req_rcv(cli)) return (508); - auth_ctx = mem_znew(http_srv_cli_auth_ctx_t); + auth_ctx = calloc(1, sizeof(http_srv_cli_auth_ctx_t)); if (NULL == auth_ctx) return (500); auth_ctx->plugin = plugin; diff --git a/src/proto/radius_client.c b/src/proto/radius_client.c index 277fca0..6c85a4c 100644 --- a/src/proto/radius_client.c +++ b/src/proto/radius_client.c @@ -32,13 +32,12 @@ #include #include #include /* close, write, sysconf */ -#include /* bcopy, bzero, memcpy, memmove, memset, strerror... */ +#include /* memcpy, memmove, memset, strerror... */ #include #include #include /* snprintf, fprintf */ #include -#include "utils/mem_utils.h" #include "math/crc32.h" #include "proto/radius.h" @@ -50,7 +49,7 @@ #include "utils/buf_str.h" #include "proto/radius_client.h" #ifdef RADIUS_CLIENT_XML_CONFIG -#include "utils/xml.h" +# include "utils/xml.h" #endif @@ -159,7 +158,7 @@ static int radius_client_recv_cb(tp_task_p ioquery, int error, void radius_client_def_settings(radius_cli_settings_p s) { - mem_bzero(s, sizeof(radius_cli_settings_t)); + memset(s, 0x00, sizeof(radius_cli_settings_t)); s->servers_max = RADIUS_CLIENT_S_DEF_SERVERS_MAX; s->thr_queue_max = RADIUS_CLIENT_S_DEF_THR_QUEUE_MAX; s->thr_sockets_min = RADIUS_CLIENT_S_DEF_THR_SOCKETS_MIN; @@ -171,7 +170,7 @@ radius_client_def_settings(radius_cli_settings_p s) { void radius_client_server_def_settings(radius_cli_srv_settings_p s) { - mem_bzero(s, sizeof(radius_cli_srv_settings_t)); + memset(s, 0x00, sizeof(radius_cli_srv_settings_t)); s->retrans_time_init = RADIUS_CLIENT_SRV_S_DEF_IRT; s->retrans_time_max = RADIUS_CLIENT_SRV_S_DEF_MRT; s->retrans_duration_max = RADIUS_CLIENT_SRV_S_DEF_MRD; @@ -345,7 +344,7 @@ radius_client_create(tp_p tp, radius_cli_settings_p s, if (NULL == tp || NULL == s || NULL == rad_cli_ret) return (EINVAL); - rad_cli = mem_znew(radius_cli_t); + rad_cli = calloc(1, sizeof(radius_cli_t)); if (NULL == rad_cli) return (ENOMEM); rad_cli->tp = tp; @@ -361,7 +360,7 @@ radius_client_create(tp_p tp, radius_cli_settings_p s, rad_cli->s.servers_max &= ~((size_t)(RADIUS_CLIENT_ALLOC_CNT - 1)); /* Per threads sockets. */ rad_cli->thr_count = tp_thread_count_max_get(tp); - rad_cli->thr = zallocarray(rad_cli->thr_count, sizeof(radius_cli_thr_t)); + rad_cli->thr = calloc(rad_cli->thr_count, sizeof(radius_cli_thr_t)); if (NULL == rad_cli->thr) { error = ENOMEM; goto err_out; @@ -369,9 +368,9 @@ radius_client_create(tp_p tp, radius_cli_settings_p s, for (i = 0; i < rad_cli->thr_count; i ++) { rad_cli->thr[i].tpt = tp_thread_get(tp, i); rad_cli->thr[i].rad_cli = rad_cli; - rad_cli->thr[i].skts4.skt = zallocarray(rad_cli->s.thr_sockets_max, + rad_cli->thr[i].skts4.skt = calloc(rad_cli->s.thr_sockets_max, sizeof(radius_cli_skt_p)); - rad_cli->thr[i].skts6.skt = zallocarray(rad_cli->s.thr_sockets_max, + rad_cli->thr[i].skts6.skt = calloc(rad_cli->s.thr_sockets_max, sizeof(radius_cli_skt_p)); if (NULL == rad_cli->thr[i].skts4.skt || NULL == rad_cli->thr[i].skts6.skt) { @@ -382,7 +381,7 @@ radius_client_create(tp_p tp, radius_cli_settings_p s, MTX_INIT(&rad_cli->cli_srv_mtx); //rad_cli->cli_srv_count = 0; //rad_cli->cli_srv_allocated = 0; - rad_cli->srv = zallocarray(rad_cli->s.servers_max, sizeof(radius_cli_srv_t)); + rad_cli->srv = calloc(rad_cli->s.servers_max, sizeof(radius_cli_srv_t)); if (NULL == rad_cli->srv) { error = ENOMEM; goto err_out; @@ -486,7 +485,7 @@ radius_client_server_remove(radius_cli_p rad_cli, radius_cli_srv_p srv) { memmove(&rad_cli->srv[i], &rad_cli->srv[(i + 1)], (sizeof(radius_cli_srv_p) * (rad_cli->cli_srv_count - (i + 1)))); rad_cli->cli_srv_count --; - mem_bzero(&rad_cli->srv[(rad_cli->cli_srv_count - 1)], + memset(&rad_cli->srv[(rad_cli->cli_srv_count - 1)], 0x00, sizeof(radius_cli_srv_t)); break; } @@ -507,7 +506,7 @@ radius_client_server_remove_by_addr(radius_cli_p rad_cli, memmove(&rad_cli->srv[i], &rad_cli->srv[(i + 1)], (sizeof(radius_cli_srv_p) * (rad_cli->cli_srv_count - (i + 1)))); rad_cli->cli_srv_count --; - mem_bzero(&rad_cli->srv[(rad_cli->cli_srv_count - 1)], + memset(&rad_cli->srv[(rad_cli->cli_srv_count - 1)], 0x00, sizeof(radius_cli_srv_t)); break; } @@ -531,7 +530,7 @@ radius_client_socket_alloc(uint16_t family, radius_cli_thr_p thr) { skts = ((AF_INET == family) ? &thr->skts4 : &thr->skts6); if (skts->skt_count >= thr->rad_cli->s.thr_sockets_max) return (E2BIG); - skt = mem_znew(radius_cli_skt_t); + skt = calloc(1, sizeof(radius_cli_skt_t)); if (NULL == skt) return (ENOMEM); error = skt_create(family, SOCK_DGRAM, IPPROTO_UDP, @@ -623,7 +622,7 @@ radius_client_query_alloc(radius_cli_p rad_cli, tpt_p tpt, size_t query_id, if (RADIUS_PKT_HDR_ID_MAX_COUNT <= query_id && RADIUS_CLIENT_QUERY_ID_AUTO != query_id) return (EINVAL); - query = mem_znew(radius_cli_query_t); + query = calloc(1, sizeof(radius_cli_query_t)); if (NULL == query) return (ENOMEM); query->rad_cli = rad_cli; diff --git a/src/proto/sap_rcvr.c b/src/proto/sap_rcvr.c index 3433062..61ee243 100644 --- a/src/proto/sap_rcvr.c +++ b/src/proto/sap_rcvr.c @@ -31,7 +31,7 @@ #include #include #include -#include /* bcopy, bzero, memcpy, memmove, memset, strerror... */ +#include /* memcpy, memmove, memset, strerror... */ #include #include @@ -139,7 +139,7 @@ sdp_lite_alloc(const uint8_t *id, uint16_t id_size, uint16_t name_size) { if (NULL == id || 0 == id_size) return (NULL); - sdpl = zalloc((sizeof(sdp_lite_t) + id_size + sizeof(void*) + name_size + sizeof(void*))); + sdpl = calloc(1, (sizeof(sdp_lite_t) + id_size + sizeof(void*) + name_size + sizeof(void*))); if (NULL == sdpl) return (sdpl); sdpl->id = (uint8_t*)(sdpl + 1); @@ -171,7 +171,7 @@ sap_receiver_create(tp_p thp, uint32_t skt_recv_buf_size, if (NULL == thp || NULL == sap_rcvr_ret) return (EINVAL); - srcvr = mem_znew(sap_rcvr_t); + srcvr = calloc(1, sizeof(sap_rcvr_t)); if (NULL == srcvr) return (errno); error = skt_bind_ap(AF_INET, NULL, SAP_PORT, diff --git a/src/proto/upnp_ssdp.c b/src/proto/upnp_ssdp.c index 6316b86..364e87f 100644 --- a/src/proto/upnp_ssdp.c +++ b/src/proto/upnp_ssdp.c @@ -36,7 +36,7 @@ #include #include /* malloc, exit */ #include /* close, write, sysconf */ -#include /* bcopy, bzero, memcpy, memmove, memset, strerror... */ +#include /* memcpy, memmove, memset, strerror... */ #include /* snprintf, fprintf */ #include #include @@ -237,7 +237,7 @@ upnp_ssdp_def_settings(upnp_ssdp_settings_p s_ret) { if (NULL == s_ret) return; - mem_bzero(s_ret, sizeof(upnp_ssdp_settings_t)); + memset(s_ret, 0x00, sizeof(upnp_ssdp_settings_t)); /* Default settings. */ s_ret->skt_opts.mask |= UPNP_SSDP_S_DEF_SKT_OPTS_MASK; s_ret->skt_opts.bit_vals |= UPNP_SSDP_S_DEF_SKT_OPTS_VALS; @@ -285,7 +285,7 @@ upnp_ssdp_create(tp_p tp, upnp_ssdp_settings_p s, upnp_ssdp_p *ussdp_ret) { memcpy(&s_def, s, sizeof(s_def)); } - ssdp = mem_znew(upnp_ssdp_t); + ssdp = calloc(1, sizeof(upnp_ssdp_t)); if (NULL == ssdp) return (ENOMEM); s = &s_def; @@ -419,7 +419,7 @@ upnp_ssdp_dev_add(upnp_ssdp_p ssdp, const char *uuid, } nt_size = (4 + domain_name_size + 8 + type_size + 16); tot_size = (sizeof(upnp_ssdp_dev_t) + UPNP_NT_UUID_SIZE + domain_name_size + type_size + nt_size + 8); - dev = zalloc(tot_size); + dev = calloc(1, tot_size); if (NULL == dev) return (ENOMEM); /* Defaults. */ @@ -561,7 +561,7 @@ upnp_ssdp_svc_add(upnp_ssdp_dev_p dev, } nt_size = (4 + domain_name_size + 9 + type_size + 16); tot_size = (sizeof(upnp_ssdp_svc_t) + domain_name_size + type_size + nt_size + 8); - svc = zalloc(tot_size); + svc = calloc(1, tot_size); if (NULL == svc) return (ENOMEM); svc->domain_name = (uint8_t*)(svc + 1); @@ -628,7 +628,7 @@ upnp_ssdp_dev_if_add(upnp_ssdp_p ssdp, upnp_ssdp_dev_p dev, if (0 != error) return (error); } - dev_if = zalloc((sizeof(upnp_ssdp_dev_t) + url4_size + url6_size + 8)); + dev_if = calloc(1, (sizeof(upnp_ssdp_dev_t) + url4_size + url6_size + 8)); if (NULL == dev_if) return (ENOMEM); dev_if->s_if = s_if; @@ -733,7 +733,7 @@ upnp_ssdp_if_add(upnp_ssdp_p ssdp, const char *if_name, size_t if_name_size, if_index = if_nametoindex(ifname); if (0 == if_index) return (ESPIPE); - s_if = mem_znew(upnp_ssdp_if_t); + s_if = calloc(1, sizeof(upnp_ssdp_if_t)); if (NULL == s_if) return (ENOMEM); s_if->if_index = if_index; @@ -1261,7 +1261,7 @@ upnp_ssdp_send(upnp_ssdp_p ssdp, upnp_ssdp_if_p s_if, sockaddr_storage_p addr, i return (0); /* IPv4 disabled. */ skt = tp_task_ident_get(ssdp->mc_rcvr_v4); if (NULL != s_if) { - mem_bzero(&ipmrn, sizeof(ipmrn)); + memset(&ipmrn, 0x00, sizeof(ipmrn)); ipmrn.imr_ifindex = (int)s_if->if_index; if (0 != setsockopt((int)skt, IPPROTO_IP, IP_MULTICAST_IF, &ipmrn, sizeof(ipmrn))) { diff --git a/src/threadpool/threadpool.c b/src/threadpool/threadpool.c index 2367890..6d78050 100644 --- a/src/threadpool/threadpool.c +++ b/src/threadpool/threadpool.c @@ -52,7 +52,8 @@ #include /* malloc, exit */ #include /* snprintf, fprintf */ #include /* close, write, sysconf */ -#include /* bcopy, bzero, memcpy, memmove, memset, strerror... */ +#include /* memcpy, memmove, memset, strerror... */ +#include /* explicit_bzero */ #include #include #include @@ -61,7 +62,6 @@ #include "utils/macro.h" #include "al/os.h" -#include "utils/mem_utils.h" #include "threadpool/threadpool.h" #include "threadpool/threadpool_msg_sys.h" @@ -378,7 +378,7 @@ tpt_ev_q_del(uint16_t event, tp_udata_p tp_udata) { &tpt->ev_changelist[(i + 1)], (sizeof(struct kevent) * (ev_nchanges - i))); // move items, except last } - mem_bzero(&tpt->ev_changelist[(ev_nchanges + 1)], + memset(&tpt->ev_changelist[(ev_nchanges + 1)], 0x00, sizeof(struct kevent));// zeroize last } tpt->ev_nchanges = ev_nchanges; @@ -425,7 +425,7 @@ tpt_loop(tpt_p tpt) { pvt = tpt->tp->pvt; tpt->ev_nchanges = 0; - mem_bzero(&ke_timeout, sizeof(ke_timeout)); + memset(&ke_timeout, 0x00, sizeof(ke_timeout)); /* Main loop. */ while (TP_THREAD_STATE_RUNNING == tpt->state) { @@ -433,7 +433,7 @@ tpt_loop(tpt_p tpt) { cnt = kevent((int)tpt->io_fd, tpt->ev_changelist, tpt->ev_nchanges, &kev, 1, NULL /* Infinite wait. */); if (0 != tpt->ev_nchanges) { - mem_bzero(tpt->ev_changelist, + memset(tpt->ev_changelist, 0x00, (sizeof(struct kevent) * (size_t)tpt->ev_nchanges)); tpt->ev_nchanges = 0; } @@ -561,7 +561,7 @@ tpt_data_event_init(tpt_p tpt) { if (NULL != tpt->tp->pvt && tpt != tpt->tp->pvt) { /* Add pool virtual thread to normal thread. */ - mem_bzero(&ev, sizeof(tp_event_t)); + memset(&ev, 0x00, sizeof(tp_event_t)); ev.event = TP_EV_READ; /* ev.flags = TP_F_EXCLUSIVE; Should be here, but it is not * implemented on BSD and does not work with epoll() fd on linux. */ @@ -644,7 +644,7 @@ tpt_ev_post(int op, tp_event_p ev, tp_udata_p tp_udata) { if (0 == tfd) return (ENOENT); tp_udata->tpdata |= TPDATA_F_DISABLED; - mem_bzero(&new_tmr, sizeof(new_tmr)); + memset(&new_tmr, 0x00, sizeof(new_tmr)); if (-1 == timerfd_settime(tfd, 0, &new_tmr, NULL)) { error = errno; goto err_out_timer; @@ -695,7 +695,7 @@ tpt_ev_post(int op, tp_event_p ev, tp_udata_p tp_udata) { break; } if (0 != ((TP_F_ONESHOT | TP_F_DISPATCH) & ev->flags)) { /* Onetime. */ - mem_bzero(&new_tmr.it_interval, sizeof(struct timespec)); + memset(&new_tmr.it_interval, 0x00, sizeof(struct timespec)); } else { /* Periodic. */ new_tmr.it_interval = new_tmr.it_value; /* memcpy(). */ } @@ -895,7 +895,7 @@ tp_settings_def(tp_settings_p s_ret) { if (NULL == s_ret) return; /* Init. */ - mem_bzero(s_ret, sizeof(tp_settings_t)); + memset(s_ret, 0x00, sizeof(tp_settings_t)); /* Default settings. */ s_ret->flags = TP_S_DEF_FLAGS; @@ -990,7 +990,7 @@ tp_create(tp_settings_p s, tp_p *ptp) { if (0 == s->threads_max) { s->threads_max = cpu_count; } - tp = (tp_p)zalloc((sizeof(tp_t) + ((s->threads_max + 1) * sizeof(tp_thread_t)))); + tp = (tp_p)calloc(1, (sizeof(tp_t) + ((s->threads_max + 1) * sizeof(tp_thread_t)))); if (NULL == tp) return (ENOMEM); fd_max_count = (uintptr_t)getdtablesize(); @@ -1218,7 +1218,7 @@ tp_thread_proc(void *data) { syslog(LOG_INFO, "%s thread exited...", thr_name); pthread_setspecific(tp_tls_key_tpt, NULL); pthread_self_name_set(NULL); - mem_bzero(&tpt->pt_id, sizeof(pthread_t)); + memset(&tpt->pt_id, 0x00, sizeof(pthread_t)); tpt->state = TP_THREAD_STATE_STOP; /* Reset state on exit. */ tpt->tp->threads_cnt --; @@ -1349,7 +1349,7 @@ tpt_data_init(tp_p tp, int cpu_id, size_t thread_num, tpt_p tpt) { if (NULL == tp || NULL == tpt) return (EINVAL); - mem_bzero(tpt, sizeof(tp_thread_t)); + memset(tpt, 0x00, sizeof(tp_thread_t)); tpt->tp = tp; tpt->cpu_id = cpu_id; tpt->thread_num = thread_num; @@ -1368,7 +1368,7 @@ tpt_data_uninit(tpt_p tpt) { return; tpt_data_event_destroy(tpt); close((int)tpt->io_fd); - mem_bzero(tpt, sizeof(tp_thread_t)); + explicit_bzero(tpt, sizeof(tp_thread_t)); } diff --git a/src/threadpool/threadpool_msg_sys.c b/src/threadpool/threadpool_msg_sys.c index d50b01e..48c2919 100644 --- a/src/threadpool/threadpool_msg_sys.c +++ b/src/threadpool/threadpool_msg_sys.c @@ -34,7 +34,7 @@ #include #include /* malloc, exit */ #include /* close, write, sysconf */ -#include /* bcopy, bzero, memcpy, memmove, memset, strerror... */ +#include /* memcpy, memmove, memset, strerror... */ #include #include @@ -242,7 +242,7 @@ tpt_msg_queue_create(tpt_p tpt, const uint32_t flags) { /* Init threads message int error; tpt_msg_queue_p msg_queue; - msg_queue = mem_znew(tpt_msg_queue_t); + msg_queue = calloc(1, sizeof(tpt_msg_queue_t)); if (NULL == msg_queue) return (NULL); if (-1 == pipe2(msg_queue->fd, @@ -498,7 +498,7 @@ tpt_msg_cbsend(tp_p tp, tpt_p src, uint32_t flags, } return (0); /* Sended / error on send. */ } - msg_data = mem_znew(tpt_msg_data_t); + msg_data = calloc(1, sizeof(tpt_msg_data_t)); if (NULL == msg_data) return (ENOMEM); msg_data->msg_cb = msg_cb; @@ -545,7 +545,7 @@ tpt_msg_async_op_alloc(tpt_p dst, tpt_msg_async_op_cb op_cb) { if (NULL == op_cb) return (NULL); - aop = mem_znew(tpt_msg_async_op_t); + aop = calloc(1, sizeof(tpt_msg_async_op_t)); if (NULL == aop) return (NULL); if (NULL == dst) { diff --git a/src/threadpool/threadpool_task.c b/src/threadpool/threadpool_task.c index 958c8d3..0ecbb75 100644 --- a/src/threadpool/threadpool_task.c +++ b/src/threadpool/threadpool_task.c @@ -36,11 +36,10 @@ #include /* readv, preadv, writev, pwritev */ #include #include /* close, write, sysconf */ -#include /* bcopy, bzero, memcpy, memmove, memset, strerror... */ +#include /* memcpy, memmove, memset, strerror... */ #include #include "utils/macro.h" -#include "utils/mem_utils.h" #include "net/socket.h" #include "threadpool/threadpool_task.h" @@ -77,7 +76,7 @@ tp_task_create(tpt_p tpt, uintptr_t ident, tp_cb tp_cb_func, if (NULL == tpt || NULL == tp_cb_func || NULL == tptask_ret) return (EINVAL); - tptask = mem_znew(tp_task_t); + tptask = calloc(1, sizeof(tp_task_t)); if (NULL == tptask) return (ENOMEM); tptask->tp_data.cb_func = tp_cb_func; @@ -923,7 +922,7 @@ tp_task_bind_accept_multi_create(tp_p tp, } #endif - tptasks = zallocarray(max_threads, sizeof(tp_task_p)); + tptasks = calloc(max_threads, sizeof(tp_task_p)); if (NULL == tptasks) return (ENOMEM); diff --git a/src/utils/bt_encode.c b/src/utils/bt_encode.c index 58f3b61..ddae11a 100644 --- a/src/utils/bt_encode.c +++ b/src/utils/bt_encode.c @@ -38,7 +38,7 @@ #include #include #include -#include /* bcopy, bzero, memcpy, memmove, memset, strerror... */ +#include /* memcpy, memmove, memset, strerror... */ #include #include "utils/mem_utils.h" @@ -55,7 +55,7 @@ bt_en_node_p bt_en_alloc(uint8_t type, uint8_t *raw, size_t raw_size) { bt_en_node_p ret; - ret = mem_znew(bt_en_node_t); + ret = calloc(1, sizeof(bt_en_node_t)); if (NULL == ret) return (NULL); ret->type = type; diff --git a/src/utils/buf_str.c b/src/utils/buf_str.c index 3abf72e..cb108ed 100644 --- a/src/utils/buf_str.c +++ b/src/utils/buf_str.c @@ -33,7 +33,7 @@ #include #include #include /* snprintf, fprintf */ -#include /* bcopy, bzero, memcpy, memmove, memset, strnlen, strerror... */ +#include /* memcpy, memmove, memset, strnlen, strerror... */ #include /* malloc, exit */ #include "utils/mem_utils.h" @@ -283,7 +283,7 @@ cvt_hex2bin(const uint8_t *hex, size_t hex_size, int auto_out_size, cnt = 0; } if (0 != auto_out_size) { - mem_bzero(bin, (size_t)(bin_max - bin)); + memset(bin, 0x00, (size_t)(bin_max - bin)); bin = bin_max; } if (NULL != bin_size_ret) { @@ -311,7 +311,7 @@ cvt_bin2hex(const uint8_t *bin, size_t bin_size, int auto_out_size, } else { tm = (hex_size & ~((size_t)1)); } - mem_set(hex, tm, '0'); + memset(hex, '0', tm); hex += tm; goto ok_exit; } @@ -330,7 +330,7 @@ cvt_bin2hex(const uint8_t *bin, size_t bin_size, int auto_out_size, } if (0 == auto_out_size) { /* Zeroize end. */ tm = ((hex_size - tm) & ~((size_t)1)); - mem_set(hex, tm, '0'); + memset(hex, '0', tm); hex += tm; } ok_exit: diff --git a/src/utils/cmd_line_daemon.c b/src/utils/cmd_line_daemon.c index 0b1f809..f7abf18 100644 --- a/src/utils/cmd_line_daemon.c +++ b/src/utils/cmd_line_daemon.c @@ -35,7 +35,7 @@ #include #include #include /* snprintf, fprintf */ -#include /* bcopy, bzero, memcpy, memmove, memset, strnlen, strerror... */ +#include /* memcpy, memmove, memset, strnlen, strerror... */ #include /* malloc, exit */ #include diff --git a/src/utils/data_cache.c b/src/utils/data_cache.c index 418b6b6..fb2c026 100644 --- a/src/utils/data_cache.c +++ b/src/utils/data_cache.c @@ -1,5 +1,5 @@ /*- - * Copyright (c) 2012 - 2020 Rozhuk Ivan + * Copyright (c) 2012-2024 Rozhuk Ivan * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -34,11 +34,10 @@ #include #include #include -#include /* bcopy, bzero, memcpy, memmove, memset, strerror... */ +#include /* memcpy, memmove, memset, strerror... */ #include /* malloc, exit */ #include "utils/macro.h" -#include "utils/mem_utils.h" #include "utils/data_cache.h" @@ -76,7 +75,7 @@ data_cache_create(data_cache_p *dcache, data_cache_alloc_data_func alloc_data_fn if (NULL == dcache) return (EINVAL); - dcache_ret = mem_znew(data_cache_t); + dcache_ret = calloc(1, sizeof(data_cache_t)); if (NULL == dcache_ret) return (ENOMEM); dcache_ret->alloc_data_fn = alloc_data_fn; @@ -257,7 +256,7 @@ data_cache_item_add(data_cache_p dcache, const uint8_t *key, size_t key_size, ////mtx_unlock(&bucket->rw_lock); /* Not found. */ - dc_item_ret = mem_znew(data_cache_item_t); + dc_item_ret = calloc(1, sizeof(data_cache_item_t)); if (NULL == dc_item_ret) return (ENOMEM); dc_item_ret->data = dcache->alloc_data_fn(key, key_size); diff --git a/src/utils/info.c b/src/utils/info.c index 874508f..1146695 100644 --- a/src/utils/info.c +++ b/src/utils/info.c @@ -36,7 +36,7 @@ #include /* malloc, exit */ #include /* snprintf, fprintf */ #include /* close, write, sysconf */ -#include /* bcopy, bzero, memcpy, memmove, memset, strerror... */ +#include /* memcpy, memmove, memset, strerror... */ #include #include #ifdef BSD /* BSD specific code. */ diff --git a/src/utils/ini.c b/src/utils/ini.c index 48d9e1b..510acbe 100644 --- a/src/utils/ini.c +++ b/src/utils/ini.c @@ -32,7 +32,7 @@ #include #include #include -#include /* bcopy, bzero, memcpy, memmove, memset, strerror... */ +#include /* memcpy, memmove, memset, strerror... */ #include /* malloc, exit */ #include "utils/mem_utils.h" @@ -76,7 +76,7 @@ ini_line_alloc__int(const size_t size) { /* Alloc and store data from line. */ tm = (sizeof(ini_line_t) + size + INI_LINE_ALLOC_PADDING); - line = zalloc(tm); + line = calloc(1, tm); if (NULL == line) return (NULL); line->data = (uint8_t*)(line + 1); @@ -93,7 +93,7 @@ ini_create(ini_p *ini_ret) { if (NULL == ini_ret) return (EINVAL); - ini = mem_znew(ini_t); + ini = calloc(1, sizeof(ini_t)); if (NULL == ini) { (*ini_ret) = NULL; return (errno); diff --git a/src/utils/ring_buffer.c b/src/utils/ring_buffer.c index 7801839..1b9e1d7 100644 --- a/src/utils/ring_buffer.c +++ b/src/utils/ring_buffer.c @@ -39,7 +39,7 @@ #include #include /* malloc, exit */ #include /* close, write, sysconf */ -#include /* bcopy, bzero, memcpy, memmove, memset, strerror... */ +#include /* memcpy, memmove, memset, strerror... */ #include #include "utils/macro.h" @@ -358,7 +358,7 @@ r_buf_alloc(uintptr_t fd, size_t size, size_t min_block_size) { if (0 == size || 0 == min_block_size) /* Prevent division by zero. */ return (NULL); - r_buf = mem_znew(r_buf_t); + r_buf = calloc(1, sizeof(r_buf_t)); if (NULL == r_buf) return (NULL); page_size = (size_t)sysconf(_SC_PAGE_SIZE); diff --git a/src/utils/sys.c b/src/utils/sys.c index 46ccf95..8a7214a 100644 --- a/src/utils/sys.c +++ b/src/utils/sys.c @@ -38,7 +38,7 @@ #include #include /* open, fcntl */ #include /* snprintf, fprintf */ -#include /* bcopy, bzero, memcpy, memmove, memset, strnlen, strerror... */ +#include /* memcpy, memmove, memset, strnlen, strerror... */ #include /* close, write, sysconf */ #include /* malloc, exit */ #include diff --git a/src/utils/sys_res_limits_xml.c b/src/utils/sys_res_limits_xml.c index dad5834..e0d4e5b 100644 --- a/src/utils/sys_res_limits_xml.c +++ b/src/utils/sys_res_limits_xml.c @@ -34,7 +34,7 @@ #include #include #include /* snprintf, fprintf */ -#include /* bcopy, bzero, memcpy, memmove, memset, strnlen, strerror... */ +#include /* memcpy, memmove, memset, strnlen, strerror... */ #include /* malloc, exit */ #ifdef HAVE_RTPRIO # include diff --git a/src/utils/xml.c b/src/utils/xml.c index 0903032..ba227bf 100644 --- a/src/utils/xml.c +++ b/src/utils/xml.c @@ -32,7 +32,7 @@ #include #include //#include -#include /* bcopy, bzero, memcpy, memmove, memset, strerror... */ +#include /* memcpy, memmove, memset, strerror... */ #include /* va_start, va_arg */ #include @@ -532,7 +532,7 @@ xml_get_val_ns_arr(const uint8_t *xml_data, size_t xml_data_size, NULL == tag_arr || NULL == tag_arr_cnt || NULL == ret_ns_size) return (EINVAL); - mem_bzero(ret_ns_size, (sizeof(size_t) * tag_arr_count)); + memset(ret_ns_size, 0x00, (sizeof(size_t) * tag_arr_count)); if (NULL != next_pos && xml_data <= (*next_pos) && (xml_data + xml_data_size) > (*next_pos)) { TagEnd = (*next_pos); diff --git a/tests/base64/main.c b/tests/base64/main.c index af62357..94a0c91 100644 --- a/tests/base64/main.c +++ b/tests/base64/main.c @@ -32,7 +32,7 @@ #include #include /* snprintf, fprintf */ -#include /* bcopy, bzero, memcpy, memmove, memset, strerror... */ +#include /* memcpy, memmove, memset, strerror... */ #include diff --git a/tests/ecdsa/main.c b/tests/ecdsa/main.c index db1228f..d6c18d5 100644 --- a/tests/ecdsa/main.c +++ b/tests/ecdsa/main.c @@ -34,7 +34,7 @@ #include /* malloc, exit */ #include /* snprintf, fprintf */ #include /* close, write, sysconf */ -#include /* bcopy, bzero, memcpy, memmove, memset, strerror... */ +#include /* memcpy, memmove, memset, strerror... */ #include diff --git a/tests/threadpool/main.c b/tests/threadpool/main.c index dcb93ac..f18a27b 100644 --- a/tests/threadpool/main.c +++ b/tests/threadpool/main.c @@ -39,7 +39,7 @@ #include /* malloc, exit */ #include /* snprintf, fprintf */ #include /* close, write, sysconf */ -#include /* bcopy, bzero, memcpy, memmove, memset, strerror... */ +#include /* memcpy, memmove, memset, strerror... */ #include #include #include