[mw-devel] [Git][arthur/mw][master] Replace all uses of bzero(3) as it is deprecated.
Justin Mitchell
arthur at sucs.org
Mon Jul 31 10:21:37 BST 2017
Justin Mitchell pushed to branch master at Justin Mitchell / mw
Commits:
5a100571 by Justin Mitchell at 2017-07-31T10:20:27+01:00
Replace all uses of bzero(3) as it is deprecated.
- - - - -
7 changed files:
- src/client/log.c
- src/server/poll-epoll.c
- src/server/poll-kqueue.c
- src/server/servsock.c
- src/socket.c
- src/webclient/comms.c
- src/webclient/mwstring.c
Changes:
=====================================
src/client/log.c
=====================================
--- a/src/client/log.c
+++ b/src/client/log.c
@@ -345,9 +345,8 @@ void catchdoing(const char *what)
/* block handling functions */
struct block_t * block_new(int size)
{
- struct block_t *new = malloc(sizeof(struct block_t));
- new->p_buffer = malloc(size);
- bzero(new->p_buffer, size);
+ struct block_t *new = calloc(1, sizeof(struct block_t));
+ new->p_buffer = calloc(1, size);
new->i_size = size;
new->i_used = 0;
new->p_cursor = new->p_buffer;
=====================================
src/server/poll-epoll.c
=====================================
--- a/src/server/poll-epoll.c
+++ b/src/server/poll-epoll.c
@@ -17,7 +17,7 @@ int poll_addconn(ipc_connection_t *conn)
struct epoll_event ev;
int ret;
- bzero(&ev, sizeof(ev));
+ memset(&ev, 0, sizeof(ev));
ev.events = EPOLLIN | EPOLLERR;
ev.data.ptr = conn;
ret = epoll_ctl(ep.pollfd, EPOLL_CTL_ADD, conn->fd, &ev);
@@ -35,7 +35,7 @@ void poll_delete(int fd)
{
struct epoll_event ev;
- bzero(&ev, sizeof(ev));
+ memset(&ev, 0, sizeof(ev));
epoll_ctl(ep.pollfd, EPOLL_CTL_DEL, fd, &ev);
}
@@ -43,7 +43,7 @@ int poll_with_writes(ipc_connection_t *conn)
{
struct epoll_event ev;
- bzero(&ev, sizeof(ev));
+ memset(&ev, 0, sizeof(ev));
ev.events = EPOLLIN | EPOLLOUT | EPOLLERR;
ev.data.ptr = conn;
return epoll_ctl(ep.pollfd, EPOLL_CTL_MOD, conn->fd, &ev);
@@ -53,7 +53,7 @@ int poll_without_writes(ipc_connection_t *conn)
{
struct epoll_event ev;
- bzero(&ev, sizeof(ev));
+ memset(&ev, 0, sizeof(ev));
ev.events = EPOLLIN | EPOLLERR;
ev.data.ptr = conn;
return epoll_ctl(ep.pollfd, EPOLL_CTL_MOD, conn->fd, &ev);
@@ -63,7 +63,7 @@ int poll_fd_without_writes(int fd)
{
struct epoll_event ev;
- bzero(&ev, sizeof(ev));
+ memset(&ev, 0, sizeof(ev));
ev.events = EPOLLIN | EPOLLERR;
ev.data.ptr = NULL;
return epoll_ctl(ep.pollfd, EPOLL_CTL_ADD, fd, &ev);
@@ -80,7 +80,7 @@ int poll_wait(int timeout_millis, int (*callback)(poll_event_t *, int, void *),
if (ret < 0)
return ret;
for (int i = 0; i < ret; i++) {
- bzero(&pevs[i], sizeof(pevs[i]));
+ memset(&pevs[i], 0, sizeof(pevs[i]));
pevs[i].data = evs[i].data.ptr;
pevs[i].is_error = (evs[i].events & (EPOLLERR | EPOLLHUP | EPOLLRDHUP));
pevs[i].is_read = (evs[i].events & (EPOLLIN | EPOLLPRI));
=====================================
src/server/poll-kqueue.c
=====================================
--- a/src/server/poll-kqueue.c
+++ b/src/server/poll-kqueue.c
@@ -91,7 +91,7 @@ int poll_wait(int timeout_millis, int (*callback)(poll_event_t *, int, void *),
if (ret == -1)
return ret;
for (int i = 0; i < ret; i++) {
- bzero(&pevs[i], sizeof(pevs[i]));
+ memset(&pevs[i], 0, sizeof(pevs[i]));
pevs[i].data = evs[i].udata;
pevs[i].is_error = (evs[i].flags & (EV_EOF | EV_ERROR));
pevs[i].is_read = (evs[i].filter == EVFILT_READ);
=====================================
src/server/servsock.c
=====================================
--- a/src/server/servsock.c
+++ b/src/server/servsock.c
@@ -125,7 +125,7 @@ void drop_connection(ipc_connection_t * conn)
free(oq);
}
}
- bzero(conn, sizeof(ipc_connection_t));
+ memset(conn, 0, sizeof(ipc_connection_t));
free(conn);
ipc_message_t * whoinfo = msg_wholist();
=====================================
src/socket.c
=====================================
--- a/src/socket.c
+++ b/src/socket.c
@@ -16,8 +16,7 @@
/* create an empty message */
ipc_message_t * ipcmsg_create(uint32_t type, uint32_t src)
{
- ipc_message_t *new = malloc(sizeof(ipc_message_t));
- bzero(new, sizeof(ipc_message_t));
+ ipc_message_t *new = calloc(1, sizeof(ipc_message_t));
new->head.src = src;
new->head.type = type;
return new;
@@ -57,7 +56,7 @@ void ipcmsg_destroy(ipc_message_t * msg)
if (msg->refcount > 0) return;
if (msg->body != NULL) free(msg->body);
- bzero(msg, sizeof(ipc_message_t));
+ memset(msg, 0, sizeof(ipc_message_t));
free(msg);
}
@@ -65,8 +64,7 @@ int msg_queue(ipc_message_t *msg, ipc_connection_t *conn)
{
int wasempty = list_empty(&conn->outq);
- outq_msg_t * new = malloc(sizeof(outq_msg_t));
- bzero(new, sizeof(outq_msg_t));
+ outq_msg_t * new = calloc(1, sizeof(outq_msg_t));
new->msg = msg;
new->msg->refcount++;
list_add_tail(&(new->list), &(conn->outq));
@@ -89,7 +87,7 @@ void ipcmsg_send(ipc_message_t *msg, ipc_connection_t *conn)
if (msg == NULL) { msg_queue(msg, conn); return; }
if (conn->fd == -1) { msg_queue(msg, conn); return; }
- bzero(&iov, sizeof(iov));
+ memset(&iov, 0, sizeof(iov));
iov[0].iov_base = &msg->head;
iov[0].iov_len = sizeof(msg->head);
iovused++;
@@ -122,8 +120,7 @@ void ipcconn_bad(ipc_connection_t * conn)
/* create an empty connection socket struct */
ipc_connection_t * ipcconn_create(void)
{
- ipc_connection_t * conn = malloc(sizeof(ipc_connection_t));
- bzero(conn, sizeof(ipc_connection_t));
+ ipc_connection_t * conn = calloc(1, sizeof(ipc_connection_t));
conn->fd = -1;
conn->state = IPCSTATE_ERROR;
INIT_LIST_HEAD(&(conn->outq));
@@ -149,7 +146,7 @@ int ipcconn_connect(const char * target)
snprintf(port, 6, "%d", IPCPORT_DEFAULT);
}
- bzero(&hint, sizeof(hint));
+ memset(&hint, 0, sizeof(hint));
hint.ai_family = AF_INET;
hint.ai_socktype = SOCK_STREAM;
hint.ai_protocol = IPPROTO_TCP;
=====================================
src/webclient/comms.c
=====================================
--- a/src/webclient/comms.c
+++ b/src/webclient/comms.c
@@ -591,7 +591,7 @@ void create_user(struct user *me, const char *username, const char *password)
salt[0] = 'a' + (rand() % 26);
salt[1] = 'a' + (rand() % 26);
salt[2] = 0;
- bzero(me, sizeof(*me));
+ memset(me, 0, sizeof(*me));
urec->colour=0;
urec->status |= (1<<6);
urec->special |= (1<<12);
=====================================
src/webclient/mwstring.c
=====================================
--- a/src/webclient/mwstring.c
+++ b/src/webclient/mwstring.c
@@ -6,10 +6,9 @@
mwstring *mws_new(int size)
{
- mwstring *new = malloc(sizeof(mwstring));
- new->body = malloc(size);
+ mwstring *new = calloc(1, sizeof(mwstring));
+ new->body = calloc(1, size);
new->len = size;
- bzero(new->body, new->len);
return new;
}
View it on GitLab: https://projects.sucs.org/arthur/mw/commit/5a10057156eecb050a76a30d8adfb9c536eb3719
---
View it on GitLab: https://projects.sucs.org/arthur/mw/commit/5a10057156eecb050a76a30d8adfb9c536eb3719
You're receiving this email because of your account on projects.sucs.org.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.sucs.org/pipermail/mw-devel/attachments/20170731/635cf41d/attachment-0001.html>
More information about the mw-devel
mailing list