Skip to content

Commit ab1387f

Browse files
authored
bzero -> sw_memset_zero (#3419)
1 parent 9b1db96 commit ab1387f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+113
-111
lines changed

core-tests/src/memory/ringbuffer.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ static void thread_write(void)
5757
uint32_t size, yield_count = 0, yield_total_count = 0;
5858
void *ptr;
5959
pkg send_pkg;
60-
bzero(&send_pkg, sizeof(send_pkg));
60+
sw_memset_zero(&send_pkg, sizeof(send_pkg));
6161

6262
int i;
6363
for (i = 0; i < WRITE_N; i++)

core-tests/src/network/socket.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ TEST(socket, swSocket_unix_sendto)
88
char sock2_path[] = "/tmp/udp_unix2.sock";
99
char test_data[] = "swoole";
1010

11-
bzero(&un1,sizeof(struct sockaddr_un));
12-
bzero(&un2,sizeof(struct sockaddr_un));
11+
sw_memset_zero(&un1,sizeof(struct sockaddr_un));
12+
sw_memset_zero(&un2,sizeof(struct sockaddr_un));
1313

1414
un1.sun_family = AF_UNIX;
1515
un2.sun_family = AF_UNIX;

core-tests/src/os/pipe.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ TEST(pipe, unixsock)
44
{
55
swPipe p;
66
char buf[1024];
7-
bzero(&p, sizeof(p));
7+
sw_memset_zero(&p, sizeof(p));
88
int ret = swPipeUnsock_create(&p, 1, SOCK_DGRAM);
99
ASSERT_EQ(ret, 0);
1010

@@ -46,7 +46,7 @@ TEST(pipe, base)
4646
ret = p.write(&p, (void *) SW_STRL("你好中国。\n"));
4747
ASSERT_GT(ret, 0);
4848

49-
bzero(data, 256);
49+
sw_memset_zero(data, 256);
5050
ret = p.read(&p, data, 255);
5151
ASSERT_GT(ret, 0);
5252
ASSERT_EQ(strcmp("hello world\n你好中国。\n", data), 0);

examples/ssl/client.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ int OpenConnection(const char *hostname, int port)
2828
}
2929

3030
sd = socket(PF_INET, SOCK_STREAM, 0);
31-
bzero(&addr, sizeof(addr));
31+
sw_memset_zero(&addr, sizeof(addr));
3232
addr.sin_family = AF_INET;
3333
addr.sin_port = htons(port);
3434
addr.sin_addr.s_addr = *(long*) (host->h_addr);

include/swoole.h

+2
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,8 @@ typedef unsigned long ulong_t;
246246
#endif
247247
#endif
248248

249+
#define sw_memset_zero(s, n) memset(s, '\0', n)
250+
249251
static sw_inline int sw_mem_equal(const void *v1, size_t s1, const void *v2, size_t s2)
250252
{
251253
return s1 == s2 && memcmp(v1, v2, s2) == 0;

src/core/base.cc

+6-6
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,9 @@ void swoole_init(void)
5858
return;
5959
}
6060

61-
bzero(&SwooleG, sizeof(SwooleG));
62-
bzero(&SwooleWG, sizeof(SwooleWG));
63-
bzero(sw_error, SW_ERROR_MSG_SIZE);
61+
sw_memset_zero(&SwooleG, sizeof(SwooleG));
62+
sw_memset_zero(&SwooleWG, sizeof(SwooleWG));
63+
sw_memset_zero(sw_error, SW_ERROR_MSG_SIZE);
6464

6565
SwooleG.running = 1;
6666
SwooleG.init = 1;
@@ -179,7 +179,7 @@ void swoole_clean(void)
179179
{
180180
SwooleG.memory_pool->destroy(SwooleG.memory_pool);
181181
}
182-
bzero(&SwooleG, sizeof(SwooleG));
182+
sw_memset_zero(&SwooleG, sizeof(SwooleG));
183183
}
184184

185185
pid_t swoole_fork(int flags)
@@ -253,7 +253,7 @@ pid_t swoole_fork(int flags)
253253
/**
254254
* reset global struct
255255
*/
256-
bzero(&SwooleWG, sizeof(SwooleWG));
256+
sw_memset_zero(&SwooleWG, sizeof(SwooleWG));
257257
SwooleG.pid = getpid();
258258
}
259259
return pid;
@@ -1267,7 +1267,7 @@ int swoole_getaddrinfo(swRequest_getaddrinfo *req)
12671267
struct addrinfo *ptr = nullptr;
12681268
struct addrinfo hints;
12691269

1270-
bzero(&hints, sizeof(hints));
1270+
sw_memset_zero(&hints, sizeof(hints));
12711271
hints.ai_family = req->family;
12721272
hints.ai_socktype = req->socktype;
12731273
hints.ai_protocol = req->protocol;

src/core/channel.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ swChannel* swChannel_new(size_t size, size_t maxlen, int flags)
5151
swChannel *object = (swChannel *) mem;
5252
mem = (char*) mem + sizeof(swChannel);
5353

54-
bzero(object, sizeof(swChannel));
54+
sw_memset_zero(object, sizeof(swChannel));
5555

5656
//overflow space
5757
object->size = size;

src/core/hashmap.cc

+3-3
Original file line numberDiff line numberDiff line change
@@ -89,11 +89,11 @@ swHashMap* swHashMap_new(uint32_t bucket_num, swHashMap_dtor dtor)
8989
return nullptr;
9090
}
9191

92-
bzero(hmap, sizeof(swHashMap));
92+
sw_memset_zero(hmap, sizeof(swHashMap));
9393
hmap->root = root;
9494
hmap->iterator = root;
9595

96-
bzero(root, sizeof(swHashMap_node));
96+
sw_memset_zero(root, sizeof(swHashMap_node));
9797

9898
root->hh.tbl = (UT_hash_table*) sw_malloc(sizeof(UT_hash_table));
9999
if (!(root->hh.tbl))
@@ -131,7 +131,7 @@ int swHashMap_add(swHashMap* hmap, const char *key, uint16_t key_len, void *data
131131
swWarn("malloc failed");
132132
return SW_ERR;
133133
}
134-
bzero(node, sizeof(swHashMap_node));
134+
sw_memset_zero(node, sizeof(swHashMap_node));
135135
swHashMap_node *root = hmap->root;
136136
node->key_str = sw_strndup(key, key_len);
137137
node->key_int = key_len;

src/core/timer.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ static int swReactorTimer_init(swReactor *reactor, swTimer *timer, long exec_mse
7070

7171
int swTimer_init(swTimer *timer, long msec)
7272
{
73-
bzero(timer, sizeof(swTimer));
73+
sw_memset_zero(timer, sizeof(swTimer));
7474
if (swTimer_now(&timer->basetime) < 0)
7575
{
7676
return SW_ERR;

src/coroutine/hook.cc

+14-14
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,7 @@ int swoole_coroutine_open(const char *pathname, int flags, mode_t mode)
302302
}
303303

304304
swAio_event ev;
305-
bzero(&ev, sizeof(ev));
305+
sw_memset_zero(&ev, sizeof(ev));
306306
ev.buf = (void*) pathname;
307307
ev.offset = mode;
308308
ev.flags = flags;
@@ -334,7 +334,7 @@ ssize_t swoole_coroutine_read(int sockfd, void *buf, size_t count)
334334
}
335335

336336
swAio_event ev;
337-
bzero(&ev, sizeof(ev));
337+
sw_memset_zero(&ev, sizeof(ev));
338338
ev.fd = sockfd;
339339
ev.buf = buf;
340340
ev.nbytes = count;
@@ -366,7 +366,7 @@ ssize_t swoole_coroutine_write(int sockfd, const void *buf, size_t count)
366366
}
367367

368368
swAio_event ev;
369-
bzero(&ev, sizeof(ev));
369+
sw_memset_zero(&ev, sizeof(ev));
370370
ev.fd = sockfd;
371371
ev.buf = (void*) buf;
372372
ev.nbytes = count;
@@ -392,7 +392,7 @@ off_t swoole_coroutine_lseek(int fd, off_t offset, int whence)
392392
}
393393

394394
swAio_event ev;
395-
bzero(&ev, sizeof(ev));
395+
sw_memset_zero(&ev, sizeof(ev));
396396
ev.fd = fd;
397397
ev.offset = offset;
398398
ev.flags = whence;
@@ -418,7 +418,7 @@ int swoole_coroutine_fstat(int fd, struct stat *statbuf)
418418
}
419419

420420
swAio_event ev;
421-
bzero(&ev, sizeof(ev));
421+
sw_memset_zero(&ev, sizeof(ev));
422422
ev.fd = fd;
423423
ev.buf = (void*) statbuf;
424424
ev.handler = handler_fstat;
@@ -443,7 +443,7 @@ int swoole_coroutine_unlink(const char *pathname)
443443
}
444444

445445
swAio_event ev;
446-
bzero(&ev, sizeof(ev));
446+
sw_memset_zero(&ev, sizeof(ev));
447447
ev.buf = (void*) pathname;
448448
ev.handler = handler_unlink;
449449
ev.callback = aio_onCompleted;
@@ -467,7 +467,7 @@ int swoole_coroutine_statvfs(const char *path, struct statvfs *buf)
467467
}
468468

469469
swAio_event ev;
470-
bzero(&ev, sizeof(ev));
470+
sw_memset_zero(&ev, sizeof(ev));
471471
ev.buf = (void*) path;
472472
ev.offset = (off_t) buf;
473473
ev.handler = handler_statvfs;
@@ -492,7 +492,7 @@ int swoole_coroutine_mkdir(const char *pathname, mode_t mode)
492492
}
493493

494494
swAio_event ev;
495-
bzero(&ev, sizeof(ev));
495+
sw_memset_zero(&ev, sizeof(ev));
496496
ev.buf = (void*) pathname;
497497
ev.offset = mode;
498498
ev.handler = handler_mkdir;
@@ -517,7 +517,7 @@ int swoole_coroutine_rmdir(const char *pathname)
517517
}
518518

519519
swAio_event ev;
520-
bzero(&ev, sizeof(ev));
520+
sw_memset_zero(&ev, sizeof(ev));
521521
ev.buf = (void*) pathname;
522522
ev.handler = handler_rmdir;
523523
ev.callback = aio_onCompleted;
@@ -541,7 +541,7 @@ int swoole_coroutine_rename(const char *oldpath, const char *newpath)
541541
}
542542

543543
swAio_event ev;
544-
bzero(&ev, sizeof(ev));
544+
sw_memset_zero(&ev, sizeof(ev));
545545
ev.buf = (void*) oldpath;
546546
ev.offset = (off_t) newpath;
547547
ev.handler = handler_rename;
@@ -566,7 +566,7 @@ int swoole_coroutine_access(const char *pathname, int mode)
566566
}
567567

568568
swAio_event ev;
569-
bzero(&ev, sizeof(ev));
569+
sw_memset_zero(&ev, sizeof(ev));
570570
ev.buf = (void*) pathname;
571571
ev.offset = mode;
572572
ev.handler = handler_access;
@@ -591,7 +591,7 @@ int swoole_coroutine_flock(int fd, int operation)
591591
}
592592

593593
swAio_event ev;
594-
bzero(&ev, sizeof(ev));
594+
sw_memset_zero(&ev, sizeof(ev));
595595
ev.fd = fd;
596596
ev.flags = operation;
597597
ev.handler = handler_flock;
@@ -631,7 +631,7 @@ DIR *swoole_coroutine_opendir(const char *name)
631631
}
632632

633633
swAio_event ev;
634-
bzero(&ev, sizeof(ev));
634+
sw_memset_zero(&ev, sizeof(ev));
635635
ev.buf = (void*) name;
636636
ev.handler = handler_opendir;
637637
ev.callback = aio_onCompleted;
@@ -655,7 +655,7 @@ struct dirent *swoole_coroutine_readdir(DIR *dirp)
655655
}
656656

657657
swAio_event ev;
658-
bzero(&ev, sizeof(ev));
658+
sw_memset_zero(&ev, sizeof(ev));
659659
ev.buf = (void*) dirp;
660660
ev.handler = handler_readdir;
661661
ev.callback = aio_onCompleted;

src/coroutine/system.cc

+5-5
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ swString *System::read_file(const char *file, bool lock)
113113
AsyncTask task;
114114

115115
swAio_event ev;
116-
bzero(&ev, sizeof(swAio_event));
116+
sw_memset_zero(&ev, sizeof(swAio_event));
117117

118118
task.co = Coroutine::get_current_safe();
119119
task.original_event = &ev;
@@ -146,7 +146,7 @@ ssize_t System::write_file(const char *file, char *buf, size_t length, bool lock
146146
AsyncTask task;
147147

148148
swAio_event ev;
149-
bzero(&ev, sizeof(swAio_event));
149+
sw_memset_zero(&ev, sizeof(swAio_event));
150150

151151
task.co = Coroutine::get_current_safe();
152152
task.original_event = &ev;
@@ -196,7 +196,7 @@ string System::gethostbyname(const string &hostname, int domain, double timeout)
196196
swAio_event ev;
197197
AsyncTask task;
198198

199-
bzero(&ev, sizeof(swAio_event));
199+
sw_memset_zero(&ev, sizeof(swAio_event));
200200
if (hostname.size() < SW_IP_MAX_LENGTH)
201201
{
202202
ev.nbytes = SW_IP_MAX_LENGTH + 1;
@@ -272,10 +272,10 @@ vector<string> System::getaddrinfo(const string &hostname, int family, int sockt
272272
assert(family == AF_INET || family == AF_INET6);
273273

274274
swAio_event ev;
275-
bzero(&ev, sizeof(swAio_event));
275+
sw_memset_zero(&ev, sizeof(swAio_event));
276276

277277
swRequest_getaddrinfo req;
278-
bzero(&req, sizeof(swRequest_getaddrinfo));
278+
sw_memset_zero(&req, sizeof(swRequest_getaddrinfo));
279279

280280
AsyncTask task;
281281

src/lock/atomic.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ static int swAtomicLock_trylock(swLock *lock);
2222

2323
int swAtomicLock_create(swLock *lock, int spin)
2424
{
25-
bzero(lock, sizeof(swLock));
25+
sw_memset_zero(lock, sizeof(swLock));
2626
lock->type = SW_ATOMLOCK;
2727
lock->object.atomlock.spin = spin;
2828
lock->lock = swAtomicLock_lock;

src/lock/file_lock.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ static int swFileLock_free(swLock *lock);
2727

2828
int swFileLock_create(swLock *lock, int fd)
2929
{
30-
bzero(lock, sizeof(swLock));
30+
sw_memset_zero(lock, sizeof(swLock));
3131
lock->type = SW_FILELOCK;
3232
lock->object.filelock.fd = fd;
3333
lock->lock_rd = swFileLock_lock_rd;

src/lock/mutex.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ static int swMutex_free(swLock *lock);
2424
int swMutex_create(swLock *lock, int use_in_process)
2525
{
2626
int ret;
27-
bzero(lock, sizeof(swLock));
27+
sw_memset_zero(lock, sizeof(swLock));
2828
lock->type = SW_MUTEX;
2929
pthread_mutexattr_init(&lock->object.mutex.attr);
3030
if (use_in_process == 1)

src/lock/rw_lock.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ static int swRWLock_free(swLock *lock);
2828
int swRWLock_create(swLock *lock, int use_in_process)
2929
{
3030
int ret;
31-
bzero(lock, sizeof(swLock));
31+
sw_memset_zero(lock, sizeof(swLock));
3232
lock->type = SW_RWLOCK;
3333
pthread_rwlockattr_init(&lock->object.rwlock.attr);
3434
if (use_in_process == 1)

src/lock/spin_lock.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ static int swSpinLock_free(swLock *lock);
2626
int swSpinLock_create(swLock *lock, int use_in_process)
2727
{
2828
int ret;
29-
bzero(lock, sizeof(swLock));
29+
sw_memset_zero(lock, sizeof(swLock));
3030
lock->type = SW_SPINLOCK;
3131
if ((ret = pthread_spin_init(&lock->object.spinlock.lock_t, use_in_process)) < 0)
3232
{

src/memory/buffer.cc

+2-2
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ swBuffer* swBuffer_new(uint32_t chunk_size)
2929
return nullptr;
3030
}
3131

32-
bzero(buffer, sizeof(swBuffer));
32+
sw_memset_zero(buffer, sizeof(swBuffer));
3333
buffer->chunk_size = chunk_size == 0 ? INT_MAX : chunk_size;
3434

3535
return buffer;
@@ -47,7 +47,7 @@ swBuffer_chunk *swBuffer_new_chunk(swBuffer *buffer, uint32_t type, uint32_t siz
4747
return nullptr;
4848
}
4949

50-
bzero(chunk, sizeof(swBuffer_chunk));
50+
sw_memset_zero(chunk, sizeof(swBuffer_chunk));
5151

5252
//require alloc memory
5353
if (type == SW_CHUNK_DATA && size > 0)

0 commit comments

Comments
 (0)