From: Michael Wallner Date: Fri, 23 Oct 2020 18:56:24 +0000 (+0200) Subject: simplify falsy comparisons X-Git-Tag: 1.1.0-beta1~165 X-Git-Url: https://git.m6w6.name/?p=m6w6%2Flibmemcached;a=commitdiff_plain;h=cb40bfe8923a2b06160a965d95b45ca0ea3421ab simplify falsy comparisons --- diff --git a/src/bin/common/utilities.cc b/src/bin/common/utilities.cc index ce7bd3d8..b0a0f1b1 100644 --- a/src/bin/common/utilities.cc +++ b/src/bin/common/utilities.cc @@ -187,7 +187,7 @@ void initialize_sockets(void) { /* Define the function for all platforms to avoid #ifdefs in each program */ #if defined(_WIN32) WSADATA wsaData; - if (WSAStartup(MAKEWORD(2, 0), &wsaData) != 0) { + if (WSAStartup(MAKEWORD(2, 0), &wsaData)) { fprintf(stderr, "Socket Initialization Error. Program aborted\n"); exit(EXIT_FAILURE); } diff --git a/src/bin/memaslap.c b/src/bin/memaslap.c index a5481bb8..6dd6ee62 100644 --- a/src/bin/memaslap.c +++ b/src/bin/memaslap.c @@ -117,7 +117,7 @@ static void ms_help_command(const char *command_name, const char *description) { printf(" -%c, --%s%c\n", long_options[x].val, long_options[x].name, long_options[x].has_arg ? '=' : ' '); - if ((help_message = (char *) ms_lookup_help(long_options[x].val)) != NULL) { + if ((help_message = (char *) ms_lookup_help(long_options[x].val))) { printf(" %s\n", help_message); } } @@ -323,7 +323,7 @@ static int64_t ms_parse_size() { optarg[strlen(optarg) - 1] = '\0'; errno = 0; ret = strtoll(optarg, (char **) NULL, 10); - if (errno != 0) { + if (errno) { fprintf(stderr, "strtoll(optarg,..): %s\n", strerror(errno)); exit(1); } @@ -383,7 +383,7 @@ static void ms_options_parse(int argc, char *argv[]) { case OPT_CONCURRENCY: /* --concurrency or -c */ errno = 0; ms_setting.nconns = (uint32_t) strtoul(optarg, (char **) NULL, 10); - if (ms_setting.nconns <= 0 || errno != 0) { + if (ms_setting.nconns <= 0 || errno) { fprintf(stderr, "Concurrency must be greater than 0.:-)\n"); exit(1); } @@ -392,7 +392,7 @@ static void ms_options_parse(int argc, char *argv[]) { case OPT_EXECUTE_NUMBER: /* --execute_number or -x */ errno = 0; ms_setting.exec_num = (int) strtol(optarg, (char **) NULL, 10); - if (ms_setting.exec_num <= 0 || errno != 0) { + if (ms_setting.exec_num <= 0 || errno) { fprintf(stderr, "Execute number must be greater than 0.:-)\n"); exit(1); } @@ -401,7 +401,7 @@ static void ms_options_parse(int argc, char *argv[]) { case OPT_THREAD_NUMBER: /* --threads or -T */ errno = 0; ms_setting.nthreads = (uint32_t) strtoul(optarg, (char **) NULL, 10); - if (ms_setting.nthreads <= 0 || errno != 0) { + if (ms_setting.nthreads <= 0 || errno) { fprintf(stderr, "Threads number must be greater than 0.:-)\n"); exit(1); } @@ -410,7 +410,7 @@ static void ms_options_parse(int argc, char *argv[]) { case OPT_FIXED_LTH: /* --fixed_size or -X */ errno = 0; ms_setting.fixed_value_size = (size_t) strtoull(optarg, (char **) NULL, 10); - if ((ms_setting.fixed_value_size <= 0 || errno != 0) + if ((ms_setting.fixed_value_size <= 0 || errno) || (ms_setting.fixed_value_size > MAX_VALUE_SIZE)) { fprintf(stderr, "Value size must be between 0 and 1M.:-)\n"); @@ -431,7 +431,7 @@ static void ms_options_parse(int argc, char *argv[]) { case OPT_GETS_DIVISION: /* --division or -d */ errno = 0; ms_setting.mult_key_num = (int) strtol(optarg, (char **) NULL, 10); - if (ms_setting.mult_key_num <= 0 || errno != 0) { + if (ms_setting.mult_key_num <= 0 || errno) { fprintf(stderr, "Multi-get key number must be greater than 0.:-)\n"); exit(1); } @@ -513,7 +513,7 @@ static void ms_options_parse(int argc, char *argv[]) { case OPT_SOCK_PER_CONN: /* --conn_sock or -n */ errno = 0; ms_setting.sock_per_conn = (uint32_t) strtoul(optarg, (char **) NULL, 10); - if (ms_setting.sock_per_conn <= 0 || errno != 0) { + if (ms_setting.sock_per_conn <= 0 || errno) { fprintf(stderr, "Number of socks of each concurrency " "must be greater than 0.:-)\n"); @@ -550,7 +550,7 @@ static void ms_options_parse(int argc, char *argv[]) { case OPT_REP_WRITE_SRV: /* --rep_write or -p */ errno = 0; ms_setting.rep_write_srv = (uint32_t) strtoul(optarg, (char **) NULL, 10); - if (ms_setting.rep_write_srv <= 0 || errno != 0) { + if (ms_setting.rep_write_srv <= 0 || errno) { fprintf(stderr, "Number of replication writing server must be greater " "than 0.:-)\n"); @@ -580,12 +580,12 @@ static int ms_check_para() { } } - if (ms_setting.nconns % (uint32_t) ms_setting.nthreads != 0) { + if (ms_setting.nconns % (uint32_t) ms_setting.nthreads) { fprintf(stderr, "Concurrency must be the multiples of threads count.\n"); return -1; } - if (ms_setting.win_size % UNIT_ITEMS_COUNT != 0) { + if (ms_setting.win_size % UNIT_ITEMS_COUNT) { fprintf(stderr, "Window size must be the multiples of 1024.\n\n"); return -1; } diff --git a/src/bin/memaslap/ms_conn.c b/src/bin/memaslap/ms_conn.c index dade7090..49b50121 100644 --- a/src/bin/memaslap/ms_conn.c +++ b/src/bin/memaslap/ms_conn.c @@ -224,9 +224,9 @@ static int ms_conn_udp_init(ms_conn_t *c, const bool is_udp) { c->udppkt = (ms_udppkt_t *) malloc(MAX_UDP_PACKET * sizeof(ms_udppkt_t)); if ((c->rudpbuf == NULL) || (c->udppkt == NULL)) { - if (c->rudpbuf != NULL) + if (c->rudpbuf) free(c->rudpbuf); - if (c->udppkt != NULL) + if (c->udppkt) free(c->udppkt); fprintf(stderr, "malloc()\n"); return -1; @@ -249,7 +249,7 @@ static int ms_conn_udp_init(ms_conn_t *c, const bool is_udp) { */ static int ms_conn_init(ms_conn_t *c, const int init_state, const int read_buffer_size, const bool is_udp) { - assert(c != NULL); + assert(c); c->rbuf = c->wbuf = 0; c->iov = 0; @@ -282,17 +282,17 @@ static int ms_conn_init(ms_conn_t *c, const int init_state, const int read_buffe || (c->tcpsfd == NULL) || ((ms_setting.mult_key_num > 1) && (c->mlget_task.mlget_item == NULL))) { - if (c->rbuf != NULL) + if (c->rbuf) free(c->rbuf); - if (c->wbuf != NULL) + if (c->wbuf) free(c->wbuf); - if (c->iov != NULL) + if (c->iov) free(c->iov); - if (c->msglist != NULL) + if (c->msglist) free(c->msglist); - if (c->mlget_task.mlget_item != NULL) + if (c->mlget_task.mlget_item) free(c->mlget_task.mlget_item); - if (c->tcpsfd != NULL) + if (c->tcpsfd) free(c->tcpsfd); fprintf(stderr, "malloc()\n"); return -1; @@ -328,7 +328,7 @@ static int ms_conn_init(ms_conn_t *c, const int init_state, const int read_buffe } /* initialize udp */ - if (ms_conn_udp_init(c, is_udp) != 0) { + if (ms_conn_udp_init(c, is_udp)) { return -1; } @@ -421,8 +421,8 @@ static int ms_conn_sock_init(ms_conn_t *c) { int ret_sfd; uint32_t srv_idx = 0; - assert(c != NULL); - assert(c->tcpsfd != NULL); + assert(c); + assert(c->tcpsfd); for (i = 0; i < c->total_sfds; i++) { ret_sfd = 0; @@ -436,7 +436,7 @@ static int ms_conn_sock_init(ms_conn_t *c) { if (ms_network_connect(c, ms_setting.servers[srv_idx].srv_host_name, ms_setting.servers[srv_idx].srv_port, ms_setting.udp, &ret_sfd) - != 0) +) { break; } @@ -457,7 +457,7 @@ static int ms_conn_sock_init(ms_conn_t *c) { ret_sfd = 0; if (ms_network_connect(c, ms_setting.servers[srv_idx].srv_host_name, ms_setting.servers[srv_idx].srv_port, true, &ret_sfd) - != 0) +) { c->udpsfd = 0; } else { @@ -474,7 +474,7 @@ static int ms_conn_sock_init(ms_conn_t *c) { } } - if (c->udpsfd != 0) { + if (c->udpsfd) { close(c->udpsfd); } @@ -516,19 +516,19 @@ static int ms_conn_event_init(ms_conn_t *c) { * @return int, if success, return EXIT_SUCCESS, else return -1 */ int ms_setup_conn(ms_conn_t *c) { - if (ms_item_win_init(c) != 0) { + if (ms_item_win_init(c)) { return -1; } - if (ms_conn_init(c, conn_write, DATA_BUFFER_SIZE, ms_setting.udp) != 0) { + if (ms_conn_init(c, conn_write, DATA_BUFFER_SIZE, ms_setting.udp)) { return -1; } - if (ms_conn_sock_init(c) != 0) { + if (ms_conn_sock_init(c)) { return -1; } - if (ms_conn_event_init(c) != 0) { + if (ms_conn_event_init(c)) { return -1; } @@ -542,26 +542,26 @@ int ms_setup_conn(ms_conn_t *c) { */ void ms_conn_free(ms_conn_t *c) { ms_thread_t *ms_thread = pthread_getspecific(ms_thread_key); - if (c != NULL) { - if (c->hdrbuf != NULL) + if (c) { + if (c->hdrbuf) free(c->hdrbuf); - if (c->msglist != NULL) + if (c->msglist) free(c->msglist); - if (c->rbuf != NULL) + if (c->rbuf) free(c->rbuf); - if (c->wbuf != NULL) + if (c->wbuf) free(c->wbuf); - if (c->iov != NULL) + if (c->iov) free(c->iov); - if (c->mlget_task.mlget_item != NULL) + if (c->mlget_task.mlget_item) free(c->mlget_task.mlget_item); - if (c->rudpbuf != NULL) + if (c->rudpbuf) free(c->rudpbuf); - if (c->udppkt != NULL) + if (c->udppkt) free(c->udppkt); - if (c->item_win != NULL) + if (c->item_win) free(c->item_win); - if (c->tcpsfd != NULL) + if (c->tcpsfd) free(c->tcpsfd); if (--ms_thread->nactive_conn == 0) { @@ -577,7 +577,7 @@ void ms_conn_free(ms_conn_t *c) { */ static void ms_conn_close(ms_conn_t *c) { ms_thread_t *ms_thread = pthread_getspecific(ms_thread_key); - assert(c != NULL); + assert(c); /* delete the event, the socket and the connection */ event_del(&c->event); @@ -639,7 +639,7 @@ static void ms_maximize_sndbuf(const int sfd) { unsigned int old_size; /* Start with the default size. */ - if (getsockopt(sfd, SOL_SOCKET, SO_SNDBUF, &old_size, &intsize) != 0) { + if (getsockopt(sfd, SOL_SOCKET, SO_SNDBUF, &old_size, &intsize)) { fprintf(stderr, "getsockopt(SO_SNDBUF)\n"); return; } @@ -706,7 +706,7 @@ static int ms_network_connect(ms_conn_t *c, char *srv_host_name, const int srv_p snprintf(port_buf, NI_MAXSERV, "%d", srv_port); error = getaddrinfo(srv_host_name, port_buf, &hints, &ai); - if (error != 0) { + if (error) { if (error != EAI_SYSTEM) fprintf(stderr, "getaddrinfo(): %s.\n", gai_strerror(error)); else @@ -748,7 +748,7 @@ static int ms_network_connect(ms_conn_t *c, char *srv_host_name, const int srv_p return -1; } - if (ret_sfd != NULL) { + if (ret_sfd) { *ret_sfd = sfd; } @@ -795,7 +795,7 @@ static int ms_reconn(ms_conn_t *c) { uint32_t i = 0; for (i = 0; i < c->total_sfds; i++) { - if (c->tcpsfd[i] != 0) { + if (c->tcpsfd[i]) { break; } } @@ -856,7 +856,7 @@ int ms_reconn_socks(ms_conn_t *c) { uint32_t srv_conn_cnt = 0; struct timeval cur_time; - assert(c != NULL); + assert(c); if ((c->total_sfds == 1) || (c->total_sfds == c->alive_sfds)) { return EXIT_SUCCESS; @@ -917,7 +917,7 @@ int ms_reconn_socks(ms_conn_t *c) { * Usage example: * * while(ms_tokenize_command(command, ncommand, tokens, max_tokens) > 0) { - * for(int ix = 0; tokens[ix].length != 0; ix++) { + * for(int ix = 0; tokens[ix].length; ix++) { * ... * } * ncommand = tokens[ix].value - command; @@ -934,7 +934,7 @@ static int ms_tokenize_command(char *command, token_t *tokens, const int max_tok char *s, *e; int ntokens = 0; - assert(command != NULL && tokens != NULL && max_tokens > 1); + assert(command && tokens && max_tokens > 1); for (s = e = command; ntokens < max_tokens - 1; ++e) { if (*e == ' ') { @@ -973,7 +973,7 @@ static int ms_ascii_process_line(ms_conn_t *c, char *command) { int64_t value_len; char *buffer = command; - assert(c != NULL); + assert(c); /** * for command get, we store the returned value into local buffer @@ -987,7 +987,7 @@ static int ms_ascii_process_line(ms_conn_t *c, char *command) { ms_tokenize_command(command, tokens, MAX_TOKENS); errno = 0; value_len = strtol(tokens[VALUELEN_TOKEN].value, NULL, 10); - if (errno != 0) { + if (errno) { printf("<%d ERROR %s\n", c->sfd, strerror(errno)); } memcpy(&c->currcmd.key_prefix, tokens[KEY_TOKEN].value, sizeof(c->currcmd.key_prefix)); @@ -1081,7 +1081,7 @@ static int ms_ascii_process_line(ms_conn_t *c, char *command) { * @param timeout, whether it's timeout */ void ms_reset_conn(ms_conn_t *c, bool timeout) { - assert(c != NULL); + assert(c); if (c->udp) { if ((c->packets > 0) && (c->packets < MAX_UDP_PACKET)) { @@ -1124,7 +1124,7 @@ static int ms_try_read_line(ms_conn_t *c) { return EXIT_SUCCESS; } else { #ifdef NEED_ALIGN - if (((long) (c->rcurr)) % 8 != 0) { + if (((long) (c->rcurr)) % 8) { /* must realign input buffer */ memmove(c->rbuf, c->rcurr, c->rbytes); c->rcurr = c->rbuf; @@ -1161,7 +1161,7 @@ static int ms_try_read_line(ms_conn_t *c) { } else { char *el, *cont; - assert(c != NULL); + assert(c); assert(c->rcurr <= (c->rbuf + c->rsize)); if (c->rbytes == 0) @@ -1216,8 +1216,8 @@ static int ms_sort_udp_packet(ms_conn_t *c, char *buf, int rbytes) { unsigned char *header = NULL; /* no enough data */ - assert(c != NULL); - assert(buf != NULL); + assert(c); + assert(buf); assert(c->rudpbytes >= UDP_HEADER_SIZE); /* calculate received packets count */ @@ -1262,7 +1262,7 @@ static int ms_sort_udp_packet(ms_conn_t *c, char *buf, int rbytes) { for (int i = c->ordcurr; i < c->recvpkt; i++) { /* there is some data to copy */ - if ((c->udppkt[i].data != NULL) && (c->udppkt[i].copybytes < c->udppkt[i].rbytes)) { + if ((c->udppkt[i].data) && (c->udppkt[i].copybytes < c->udppkt[i].rbytes)) { header = c->udppkt[i].header; len = c->udppkt[i].rbytes - c->udppkt[i].copybytes; if (len > rbytes - wbytes) { @@ -1402,13 +1402,13 @@ static int ms_try_read_network(ms_conn_t *c) { int res; int64_t avail; - assert(c != NULL); + assert(c); if ((c->rcurr != c->rbuf) && (!c->readval || (c->rvbytes > c->rsize - (c->rcurr - c->rbuf)) || (c->readval && (c->rcurr - c->rbuf > c->rbytes)))) { - if (c->rbytes != 0) /* otherwise there's nothing to copy */ + if (c->rbytes) /* otherwise there's nothing to copy */ memmove(c->rbuf, c->rcurr, (size_t) c->rbytes); c->rcurr = c->rbuf; } @@ -1514,7 +1514,7 @@ static void ms_verify_value(ms_conn_t *c, ms_mlget_task_item_t *mlget_item, char } } } else { - if ((c->curr_task.item->value_size != vlen) || (memcmp(orignval, value, (size_t) vlen) != 0)) + if ((c->curr_task.item->value_size != vlen) || (memcmp(orignval, value, (size_t) vlen))) { atomic_add_size(&ms_stats.vef_failed, 1); @@ -1538,7 +1538,7 @@ static void ms_verify_value(ms_conn_t *c, ms_mlget_task_item_t *mlget_item, char c->curr_task.finish_verify = true; - if (mlget_item != NULL) { + if (mlget_item) { mlget_item->finish_verify = true; } } @@ -1551,7 +1551,7 @@ static void ms_verify_value(ms_conn_t *c, ms_mlget_task_item_t *mlget_item, char * @param c, pointer of the concurrency */ static void ms_ascii_complete_nread(ms_conn_t *c) { - assert(c != NULL); + assert(c); assert(c->rbytes >= c->rvbytes); assert(c->protocol == ascii_prot); if (c->rvbytes > 2) { @@ -1604,7 +1604,7 @@ static void ms_ascii_complete_nread(ms_conn_t *c) { * @param c, pointer of the concurrency */ static void ms_bin_complete_nread(ms_conn_t *c) { - assert(c != NULL); + assert(c); assert(c->rbytes >= c->rvbytes); assert(c->protocol == binary_prot); @@ -1669,7 +1669,7 @@ static void ms_bin_complete_nread(ms_conn_t *c) { * @param c, pointer of the concurrency */ static void ms_complete_nread(ms_conn_t *c) { - assert(c != NULL); + assert(c); assert(c->rbytes >= c->rvbytes); assert(c->protocol == ascii_prot || c->protocol == binary_prot); @@ -1690,7 +1690,7 @@ static void ms_complete_nread(ms_conn_t *c) { static int ms_add_msghdr(ms_conn_t *c) { struct msghdr *msg; - assert(c != NULL); + assert(c); if (c->msgsize == c->msgused) { msg = realloc(c->msglist, (size_t) c->msgsize * 2 * sizeof(struct msghdr)); @@ -1736,7 +1736,7 @@ static int ms_add_msghdr(ms_conn_t *c) { * @return int, if success, return EXIT_SUCCESS, else return -1 */ static int ms_ensure_iov_space(ms_conn_t *c) { - assert(c != NULL); + assert(c); if (c->iovused >= c->iovsize) { int i, iovnum; @@ -1773,7 +1773,7 @@ static int ms_add_iov(ms_conn_t *c, const void *buf, int len) { int leftover; bool limit_to_mtu; - assert(c != NULL); + assert(c); do { m = &c->msglist[c->msgused - 1]; @@ -1792,7 +1792,7 @@ static int ms_add_iov(ms_conn_t *c, const void *buf, int len) { } #endif - if (ms_ensure_iov_space(c) != 0) + if (ms_ensure_iov_space(c)) return -1; /* If the fragment is too big to fit in the datagram, split it up */ @@ -1829,7 +1829,7 @@ static int ms_build_udp_headers(ms_conn_t *c) { int i; unsigned char *hdr; - assert(c != NULL); + assert(c); c->request_id = ms_get_udp_request_id(); @@ -1881,7 +1881,7 @@ static int ms_build_udp_headers(ms_conn_t *c) { * TRANSMIT_HARD_ERROR Can't write (c->state is set to conn_closing) */ static int ms_transmit(ms_conn_t *c) { - assert(c != NULL); + assert(c); if ((c->msgcurr < c->msgused) && (c->msglist[c->msgcurr].msg_iovlen == 0)) { /* Finished writing the current msg; advance to the next. */ @@ -1943,7 +1943,7 @@ static int ms_transmit(ms_conn_t *c) { * @param c, pointer of the concurrency */ static void ms_conn_shrink(ms_conn_t *c) { - assert(c != NULL); + assert(c); if (c->udp) return; @@ -2004,7 +2004,7 @@ static void ms_conn_shrink(ms_conn_t *c) { * @param state, connection state */ static void ms_conn_set_state(ms_conn_t *c, int state) { - assert(c != NULL); + assert(c); if (state != c->state) { if (state == conn_read) { @@ -2025,7 +2025,7 @@ static void ms_conn_set_state(ms_conn_t *c, int state) { * @return bool, if success, return true, else return false */ static bool ms_update_event(ms_conn_t *c, const int new_flags) { - assert(c != NULL); + assert(c); struct event_base *base = c->event.ev_base; if ((c->ev_flags == new_flags) && (ms_setting.rep_write_srv == 0) @@ -2109,7 +2109,7 @@ static void ms_update_start_time(ms_conn_t *c) { static void ms_drive_machine(ms_conn_t *c) { bool stop = false; - assert(c != NULL); + assert(c); while (!stop) { switch (c->state) { @@ -2120,12 +2120,12 @@ static void ms_drive_machine(ms_conn_t *c) { break; } } else { - if (ms_try_read_line(c) != 0) { + if (ms_try_read_line(c)) { break; } } - if (ms_try_read_network(c) != 0) { + if (ms_try_read_network(c)) { break; } @@ -2159,7 +2159,7 @@ static void ms_drive_machine(ms_conn_t *c) { break; } - if (!c->ctnwrite && (ms_exec_task(c) != 0)) { + if (!c->ctnwrite && (ms_exec_task(c))) { ms_conn_set_state(c, conn_closing); break; } @@ -2228,7 +2228,7 @@ static void ms_drive_machine(ms_conn_t *c) { if (ms_setting.reconnect && (!ms_global.time_out || ((ms_setting.run_time == 0) && (c->remain_exec_num > 0)))) { - if (ms_reconn(c) != 0) { + if (ms_reconn(c)) { ms_conn_close(c); stop = true; break; @@ -2267,7 +2267,7 @@ static void ms_drive_machine(ms_conn_t *c) { void ms_event_handler(const int fd, const short which, void *arg) { ms_conn_t *c = (ms_conn_t *) arg; - assert(c != NULL); + assert(c); c->which = which; @@ -2353,7 +2353,7 @@ static uint32_t ms_get_next_sock_index(ms_conn_t *c) { * @return int, if success, return EXIT_SUCCESS, else return -1 */ static int ms_update_conn_sock_event(ms_conn_t *c) { - assert(c != NULL); + assert(c); switch (c->currcmd.cmd) { case CMD_SET: @@ -2389,7 +2389,7 @@ static int ms_update_conn_sock_event(ms_conn_t *c) { } c->sfd = c->tcpsfd[c->cur_idx]; - assert(c->sfd != 0); + assert(c->sfd); c->change_sfd = true; } @@ -2433,14 +2433,14 @@ static int ms_build_ascii_write_buf_set(ms_conn_t *c, ms_task_item_t *item) { value_offset = item->value_offset; } - if ((ms_add_iov(c, "set ", 4) != 0) - || (ms_add_iov(c, (char *) &item->key_prefix, (int) KEY_PREFIX_SIZE) != 0) + if ((ms_add_iov(c, "set ", 4)) + || (ms_add_iov(c, (char *) &item->key_prefix, (int) KEY_PREFIX_SIZE)) || (ms_add_iov(c, &ms_setting.char_block[item->key_suffix_offset], item->key_size - (int) KEY_PREFIX_SIZE) - != 0) - || (ms_add_iov(c, buffer, write_len) != 0) - || (ms_add_iov(c, &ms_setting.char_block[value_offset], item->value_size) != 0) - || (ms_add_iov(c, "\r\n", 2) != 0) || (c->udp && (ms_build_udp_headers(c) != 0))) +) + || (ms_add_iov(c, buffer, write_len)) + || (ms_add_iov(c, &ms_setting.char_block[value_offset], item->value_size)) + || (ms_add_iov(c, "\r\n", 2)) || (c->udp && (ms_build_udp_headers(c)))) { return -1; } @@ -2458,31 +2458,31 @@ static int ms_build_ascii_write_buf_set(ms_conn_t *c, ms_task_item_t *item) { * @return int, if success, return EXIT_SUCCESS, else return -1 */ int ms_mcd_set(ms_conn_t *c, ms_task_item_t *item) { - assert(c != NULL); + assert(c); c->currcmd.cmd = CMD_SET; c->currcmd.isfinish = false; c->currcmd.retstat = MCD_FAILURE; - if (ms_update_conn_sock_event(c) != 0) { + if (ms_update_conn_sock_event(c)) { return -1; } c->msgcurr = 0; c->msgused = 0; c->iovused = 0; - if (ms_add_msghdr(c) != 0) { + if (ms_add_msghdr(c)) { fprintf(stderr, "Out of memory preparing request."); return -1; } /* binary protocol */ if (c->protocol == binary_prot) { - if (ms_build_bin_write_buf_set(c, item) != 0) { + if (ms_build_bin_write_buf_set(c, item)) { return -1; } } else { - if (ms_build_ascii_write_buf_set(c, item) != 0) { + if (ms_build_ascii_write_buf_set(c, item)) { return -1; } } @@ -2504,12 +2504,12 @@ int ms_mcd_set(ms_conn_t *c, ms_task_item_t *item) { * @return int, if success, return EXIT_SUCCESS, else return -1 */ static int ms_build_ascii_write_buf_get(ms_conn_t *c, ms_task_item_t *item) { - if ((ms_add_iov(c, "get ", 4) != 0) - || (ms_add_iov(c, (char *) &item->key_prefix, (int) KEY_PREFIX_SIZE) != 0) + if ((ms_add_iov(c, "get ", 4)) + || (ms_add_iov(c, (char *) &item->key_prefix, (int) KEY_PREFIX_SIZE)) || (ms_add_iov(c, &ms_setting.char_block[item->key_suffix_offset], item->key_size - (int) KEY_PREFIX_SIZE) - != 0) - || (ms_add_iov(c, "\r\n", 2) != 0) || (c->udp && (ms_build_udp_headers(c) != 0))) +) + || (ms_add_iov(c, "\r\n", 2)) || (c->udp && (ms_build_udp_headers(c)))) { return -1; } @@ -2527,31 +2527,31 @@ static int ms_build_ascii_write_buf_get(ms_conn_t *c, ms_task_item_t *item) { * @return int, if success, return EXIT_SUCCESS, else return -1 */ int ms_mcd_get(ms_conn_t *c, ms_task_item_t *item) { - assert(c != NULL); + assert(c); c->currcmd.cmd = CMD_GET; c->currcmd.isfinish = false; c->currcmd.retstat = MCD_FAILURE; - if (ms_update_conn_sock_event(c) != 0) { + if (ms_update_conn_sock_event(c)) { return -1; } c->msgcurr = 0; c->msgused = 0; c->iovused = 0; - if (ms_add_msghdr(c) != 0) { + if (ms_add_msghdr(c)) { fprintf(stderr, "Out of memory preparing request."); return -1; } /* binary protocol */ if (c->protocol == binary_prot) { - if (ms_build_bin_write_buf_get(c, item) != 0) { + if (ms_build_bin_write_buf_get(c, item)) { return -1; } } else { - if (ms_build_ascii_write_buf_get(c, item) != 0) { + if (ms_build_ascii_write_buf_get(c, item)) { return -1; } } @@ -2572,24 +2572,24 @@ int ms_mcd_get(ms_conn_t *c, ms_task_item_t *item) { static int ms_build_ascii_write_buf_mlget(ms_conn_t *c) { ms_task_item_t *item; - if (ms_add_iov(c, "get", 3) != 0) { + if (ms_add_iov(c, "get", 3)) { return -1; } for (int i = 0; i < c->mlget_task.mlget_num; i++) { item = c->mlget_task.mlget_item[i].item; - assert(item != NULL); - if ((ms_add_iov(c, " ", 1) != 0) - || (ms_add_iov(c, (char *) &item->key_prefix, (int) KEY_PREFIX_SIZE) != 0) + assert(item); + if ((ms_add_iov(c, " ", 1)) + || (ms_add_iov(c, (char *) &item->key_prefix, (int) KEY_PREFIX_SIZE)) || (ms_add_iov(c, &ms_setting.char_block[item->key_suffix_offset], item->key_size - (int) KEY_PREFIX_SIZE) - != 0)) +)) { return -1; } } - if ((ms_add_iov(c, "\r\n", 2) != 0) || (c->udp && (ms_build_udp_headers(c) != 0))) { + if ((ms_add_iov(c, "\r\n", 2)) || (c->udp && (ms_build_udp_headers(c)))) { return -1; } @@ -2606,32 +2606,32 @@ static int ms_build_ascii_write_buf_mlget(ms_conn_t *c) { int ms_mcd_mlget(ms_conn_t *c) { ms_task_item_t *item; - assert(c != NULL); + assert(c); assert(c->mlget_task.mlget_num >= 1); c->currcmd.cmd = CMD_GET; c->currcmd.isfinish = false; c->currcmd.retstat = MCD_FAILURE; - if (ms_update_conn_sock_event(c) != 0) { + if (ms_update_conn_sock_event(c)) { return -1; } c->msgcurr = 0; c->msgused = 0; c->iovused = 0; - if (ms_add_msghdr(c) != 0) { + if (ms_add_msghdr(c)) { fprintf(stderr, "Out of memory preparing request."); return -1; } /* binary protocol */ if (c->protocol == binary_prot) { - if (ms_build_bin_write_buf_mlget(c) != 0) { + if (ms_build_bin_write_buf_mlget(c)) { return -1; } } else { - if (ms_build_ascii_write_buf_mlget(c) != 0) { + if (ms_build_ascii_write_buf_mlget(c)) { return -1; } } @@ -2661,7 +2661,7 @@ int ms_mcd_mlget(ms_conn_t *c) { static int ms_bin_process_response(ms_conn_t *c) { const char *errstr = NULL; - assert(c != NULL); + assert(c); uint32_t bodylen = c->binary_header.response.bodylen; uint8_t opcode = c->binary_header.response.opcode; @@ -2723,7 +2723,7 @@ static int ms_bin_process_response(ms_conn_t *c) { break; } /* switch */ - if (errstr != NULL) { + if (errstr) { fprintf(stderr, "%s\n", errstr); } } @@ -2746,7 +2746,7 @@ static void ms_add_bin_header(ms_conn_t *c, uint8_t opcode, uint8_t hdr_len, uin uint32_t body_len) { protocol_binary_request_header *header; - assert(c != NULL); + assert(c); header = (protocol_binary_request_header *) c->wcurr; @@ -2850,7 +2850,7 @@ static int ms_build_bin_write_buf_mlget(ms_conn_t *c) { for (int i = 0; i < c->mlget_task.mlget_num; i++) { item = c->mlget_task.mlget_item[i].item; - assert(item != NULL); + assert(item); ms_add_bin_header(c, PROTOCOL_BINARY_CMD_GET, 0, (uint16_t) item->key_size, (uint32_t) item->key_size); diff --git a/src/bin/memaslap/ms_setting.c b/src/bin/memaslap/ms_setting.c index 76101ba0..9d328ddc 100644 --- a/src/bin/memaslap/ms_setting.c +++ b/src/bin/memaslap/ms_setting.c @@ -130,7 +130,7 @@ static ssize_t getline(char **line, size_t *line_size, FILE *fp) { break; } (*line)[cur_len] = '\0'; - if (cur_len != 0) + if (cur_len) return (ssize_t) cur_len; return result; } @@ -236,7 +236,7 @@ ms_conf_type_t ms_get_conf_type(char *line) { * @return if success, return EXIT_FAILURE, else return EXIT_SUCCESS */ static int ms_is_line_data(char *line) { - assert(line != NULL); + assert(line); char *begin_ptr = line; @@ -454,7 +454,7 @@ static void ms_parse_cfg_file(char *cfg_file) { fclose(f); - if (line != NULL) { + if (line) { free(line); } } /* ms_parse_cfg_file */ @@ -626,7 +626,7 @@ static void ms_build_distr() { offset = 0; /* initialize value distribution */ - if (ms_setting.fixed_value_size != 0) { + if (ms_setting.fixed_value_size) { for (int i = 0; i < units * UNIT_ITEMS_COUNT; i++) { ms_setting.distr[i].value_size = ms_setting.fixed_value_size; } @@ -797,7 +797,7 @@ static void ms_setting_slapmode_init_post() { ms_parse_cfg_file(ms_setting.cfg_file); /* run time mode */ - if ((ms_setting.exec_num == 0) && (ms_setting.run_time != 0)) { + if ((ms_setting.exec_num == 0) && (ms_setting.run_time)) { ms_setting.exec_num = (int64_t) MAX_EXEC_NUM; } else { /* execute number mode */ @@ -870,31 +870,31 @@ void ms_setting_init_post() { * clean up the global setting structure */ void ms_setting_cleanup() { - if (ms_setting.distr != NULL) { + if (ms_setting.distr) { free(ms_setting.distr); } - if (ms_setting.char_block != NULL) { + if (ms_setting.char_block) { free(ms_setting.char_block); } - if (ms_setting.srv_str != NULL) { + if (ms_setting.srv_str) { free(ms_setting.srv_str); } - if (ms_setting.cfg_file != NULL) { + if (ms_setting.cfg_file) { free(ms_setting.cfg_file); } - if (ms_setting.servers != NULL) { + if (ms_setting.servers) { free(ms_setting.servers); } - if (ms_setting.key_distr != NULL) { + if (ms_setting.key_distr) { free(ms_setting.key_distr); } - if (ms_setting.value_distr != NULL) { + if (ms_setting.value_distr) { free(ms_setting.value_distr); } } /* ms_setting_cleanup */ diff --git a/src/bin/memaslap/ms_stats.c b/src/bin/memaslap/ms_stats.c index 0b35f51f..dce5ed8b 100644 --- a/src/bin/memaslap/ms_stats.c +++ b/src/bin/memaslap/ms_stats.c @@ -98,7 +98,7 @@ void ms_record_event(ms_stat_t *stat, uint64_t total_time, int get_miss) { stat->dist[ms_local_log2(total_time)]++; stat->squares += (double) (total_time * total_time); - if (total_time != 0) { + if (total_time) { stat->log_product += log((double) total_time); } } /* ms_record_event */ @@ -133,7 +133,7 @@ void ms_dump_stats(ms_stat_t *stat) { for (uint32_t i = 0; i < array_size(stat->dist); i++) { events += stat->dist[i]; - if (stat->dist[i] != 0) { + if (stat->dist[i]) { max_non_zero = (int) i; } } @@ -156,8 +156,8 @@ void ms_dump_stats(ms_stat_t *stat) { printf(" Log2 Dist:"); for (int i = 0; i <= max_non_zero - 4; i += 4) { - if ((stat->dist[i + 0] != 0) || (stat->dist[i + 1] != 0) || (stat->dist[i + 2] != 0) - || (stat->dist[i + 3] != 0)) + if ((stat->dist[i + 0]) || (stat->dist[i + 1]) || (stat->dist[i + 2]) + || (stat->dist[i + 3])) { min_non_zero = i; break; diff --git a/src/bin/memaslap/ms_task.c b/src/bin/memaslap/ms_task.c index 89754ec6..63d7fed8 100644 --- a/src/bin/memaslap/ms_task.c +++ b/src/bin/memaslap/ms_task.c @@ -263,7 +263,7 @@ static void ms_kick_out_item(ms_task_item_t *item) { static bool ms_need_overwrite_item(ms_task_t *task) { ms_task_item_t *item = task->item; - assert(item != NULL); + assert(item); assert(task->cmd == CMD_SET); /** @@ -291,7 +291,7 @@ static bool ms_need_overwrite_item(ms_task_t *task) { static bool ms_adjust_opt(ms_conn_t *c, ms_task_t *task) { ms_task_item_t *item = task->item; - assert(item != NULL); + assert(item); if (task->cmd == CMD_SET) { /* If did set operation too fast, skip some */ @@ -369,7 +369,7 @@ static bool ms_adjust_opt(ms_conn_t *c, ms_task_t *task) { static void ms_task_data_verify_init(ms_task_t *task) { ms_task_item_t *item = task->item; - assert(item != NULL); + assert(item); assert(task->cmd == CMD_GET); /** @@ -397,7 +397,7 @@ static void ms_task_data_verify_init(ms_task_t *task) { static void ms_task_expire_verify_init(ms_task_t *task) { ms_task_item_t *item = task->item; - assert(item != NULL); + assert(item); assert(task->cmd == CMD_GET); assert(item->exp_time > 0); @@ -614,7 +614,7 @@ static void ms_update_multi_get_result(ms_conn_t *c) { if (c == NULL) { return; } - assert(c != NULL); + assert(c); for (int i = 0; i < c->mlget_task.mlget_num; i++) { mlget_item = &c->mlget_task.mlget_item[i]; @@ -698,8 +698,8 @@ static void ms_update_single_get_result(ms_conn_t *c, ms_task_item_t *item) { if ((c == NULL) || (item == NULL)) { return; } - assert(c != NULL); - assert(item != NULL); + assert(c); + assert(item); orignval = &ms_setting.char_block[item->value_offset]; orignkey = &ms_setting.char_block[item->key_suffix_offset]; @@ -772,8 +772,8 @@ static void ms_update_set_result(ms_conn_t *c, ms_task_item_t *item) { if ((c == NULL) || (item == NULL)) { return; } - assert(c != NULL); - assert(item != NULL); + assert(c); + assert(item); if (c->precmd.cmd == CMD_SET) { switch (c->precmd.retstat) { @@ -810,7 +810,7 @@ static void ms_update_stat_result(ms_conn_t *c) { if (c == NULL) { return; } - assert(c != NULL); + assert(c); gettimeofday(&c->end_time, NULL); uint64_t time_diff = (uint64_t) ms_time_diff(&c->start_time, &c->end_time); @@ -850,13 +850,13 @@ static void ms_update_task_result(ms_conn_t *c) { if (c == NULL) { return; } - assert(c != NULL); + assert(c); item = ms_get_cur_opt_item(c); if (item == NULL) { return; } - assert(item != NULL); + assert(item); ms_update_set_result(c, item); @@ -918,7 +918,7 @@ int ms_exec_task(struct conn *c) { if (!ms_global.finish_warmup) { ms_warmup_server(c); } else { - if (ms_run_getset_task(c) != 0) { + if (ms_run_getset_task(c)) { return -1; } } diff --git a/src/bin/memaslap/ms_thread.c b/src/bin/memaslap/ms_thread.c index b06aa526..cfd46de3 100644 --- a/src/bin/memaslap/ms_thread.c +++ b/src/bin/memaslap/ms_thread.c @@ -188,7 +188,7 @@ static int ms_setup_thread(ms_thread_ctx_t *thread_ctx) { for (uint32_t i = 0; i < thread_ctx->nconns; i++) { ms_thread->conn[i].conn_idx = i; - if (ms_setup_conn(&ms_thread->conn[i]) != 0) { + if (ms_setup_conn(&ms_thread->conn[i])) { /* only output this error once */ if (atomic_add_32_nv(&cnt, 1) == 0) { fprintf(stderr, "Initializing connection failed.\n"); @@ -220,7 +220,7 @@ static void *ms_worker_libevent(void *arg) { ms_set_thread_cpu_affinity(thread_ctx->thd_idx % ms_setting.ncpu); } - if (ms_setup_thread(thread_ctx) != 0) { + if (ms_setup_thread(thread_ctx)) { exit(1); } @@ -251,7 +251,7 @@ static void ms_create_worker(void *(*func)(void *), void *arg) { pthread_attr_init(&attr); - if ((ret = pthread_create(&thread, &attr, func, arg)) != 0) { + if ((ret = pthread_create(&thread, &attr, func, arg))) { fprintf(stderr, "Can't create thread: %s.\n", strerror(ret)); exit(1); } @@ -292,7 +292,7 @@ void ms_thread_init() { /* cleanup some resource of threads when all the threads exit */ void ms_thread_cleanup() { - if (ms_thread_ctx != NULL) { + if (ms_thread_ctx) { free(ms_thread_ctx); } pthread_key_delete(ms_thread_key); diff --git a/src/bin/memcapable.cc b/src/bin/memcapable.cc index 7b3b7c92..f8dfb0f8 100644 --- a/src/bin/memcapable.cc +++ b/src/bin/memcapable.cc @@ -106,7 +106,7 @@ static struct addrinfo *lookuphost(const char *hostname, const char *port) { hints.ai_socktype = SOCK_STREAM; int error = getaddrinfo(hostname, port, &hints, &ai); - if (error != 0) { + if (error) { if (error != EAI_SYSTEM) { fprintf(stderr, "getaddrinfo(): %s\n", gai_strerror(error)); } else { @@ -157,7 +157,7 @@ static memcached_socket_t set_noblock(void) { static memcached_socket_t connect_server(const char *hostname, const char *port) { struct addrinfo *ai = lookuphost(hostname, port); sock = INVALID_SOCKET; - if (ai != NULL) { + if (ai) { if ((sock = socket(ai->ai_family, ai->ai_socktype, ai->ai_protocol)) != INVALID_SOCKET) { if (connect(sock, ai->ai_addr, ai->ai_addrlen) == SOCKET_ERROR) { fprintf(stderr, "Failed to connect socket: %s\n", strerror(get_socket_errno())); @@ -362,7 +362,7 @@ static void storage_command(command *cmd, uint8_t cc, const void *key, size_t ke off_t key_offset = sizeof(protocol_binary_request_no_extras) + 8; memcpy(cmd->bytes + key_offset, key, keylen); - if (dta != NULL) + if (dta) memcpy(cmd->bytes + key_offset + keylen, dta, dtalen); } @@ -387,10 +387,10 @@ static void raw_command(command *cmd, uint8_t cc, const void *key, size_t keylen off_t key_offset = sizeof(protocol_binary_request_no_extras); - if (key != NULL) + if (key) memcpy(cmd->bytes + key_offset, key, keylen); - if (dta != NULL) + if (dta) memcpy(cmd->bytes + key_offset + keylen, dta, dtalen); } @@ -407,7 +407,7 @@ static void flush_command(command *cmd, uint8_t cc, uint32_t exptime, bool use_e cmd->flush.message.header.request.opcode = cc; cmd->flush.message.header.request.opaque = 0xdeadbeef; - if (exptime != 0 || use_extra) { + if (exptime || use_extra) { cmd->flush.message.header.request.extlen = 4; cmd->flush.message.body.expiration = htonl(exptime); cmd->flush.message.header.request.bodylen = 4; @@ -480,7 +480,7 @@ static enum test_return do_validate_response_header(response *rsp, uint8_t cc, u verify(rsp->plain.message.header.response.keylen == 0); verify(rsp->plain.message.header.response.extlen == 0); verify(rsp->plain.message.header.response.bodylen == 0); - verify(rsp->plain.message.header.response.cas != 0); + verify(rsp->plain.message.header.response.cas); break; case PROTOCOL_BINARY_CMD_FLUSH: case PROTOCOL_BINARY_CMD_NOOP: @@ -497,7 +497,7 @@ static enum test_return do_validate_response_header(response *rsp, uint8_t cc, u verify(rsp->plain.message.header.response.keylen == 0); verify(rsp->plain.message.header.response.extlen == 0); verify(rsp->plain.message.header.response.bodylen == 8); - verify(rsp->plain.message.header.response.cas != 0); + verify(rsp->plain.message.header.response.cas); break; case PROTOCOL_BINARY_CMD_STAT: @@ -509,7 +509,7 @@ static enum test_return do_validate_response_header(response *rsp, uint8_t cc, u case PROTOCOL_BINARY_CMD_VERSION: verify(rsp->plain.message.header.response.keylen == 0); verify(rsp->plain.message.header.response.extlen == 0); - verify(rsp->plain.message.header.response.bodylen != 0); + verify(rsp->plain.message.header.response.bodylen); verify(rsp->plain.message.header.response.cas == 0); break; @@ -517,14 +517,14 @@ static enum test_return do_validate_response_header(response *rsp, uint8_t cc, u case PROTOCOL_BINARY_CMD_GETQ: verify(rsp->plain.message.header.response.keylen == 0); verify(rsp->plain.message.header.response.extlen == 4); - verify(rsp->plain.message.header.response.cas != 0); + verify(rsp->plain.message.header.response.cas); break; case PROTOCOL_BINARY_CMD_GETK: case PROTOCOL_BINARY_CMD_GETKQ: - verify(rsp->plain.message.header.response.keylen != 0); + verify(rsp->plain.message.header.response.keylen); verify(rsp->plain.message.header.response.extlen == 4); - verify(rsp->plain.message.header.response.cas != 0); + verify(rsp->plain.message.header.response.cas); break; default: @@ -1036,7 +1036,7 @@ static enum test_return test_binary_stat(void) { execute(recv_packet(&rsp)); verify( validate_response_header(&rsp, PROTOCOL_BINARY_CMD_STAT, PROTOCOL_BINARY_RESPONSE_SUCCESS)); - } while (rsp.plain.message.header.response.keylen != 0); + } while (rsp.plain.message.header.response.keylen); return TEST_PASS; } @@ -1066,7 +1066,7 @@ static enum test_return receive_line(char *buffer, size_t size) { static enum test_return receive_response(const char *msg) { char buffer[80]; execute(receive_line(buffer, sizeof(buffer))); - if (strcmp(msg, buffer) != 0) { + if (strcmp(msg, buffer)) { fprintf(stderr, "[%s]\n", buffer); } verify(strcmp(msg, buffer) == 0); @@ -1209,12 +1209,12 @@ static enum test_return ascii_get_unknown_value(char **key, char **value, ssize_ execute(receive_line(buffer, sizeof(buffer))); verify(strncmp(buffer, "VALUE ", 6) == 0); char *end = strchr(buffer + 6, ' '); - verify(end != NULL); + verify(end); if (end) { *end = '\0'; } *key = strdup(buffer + 6); - verify(*key != NULL); + verify(*key); char *ptr = end + 1; errno = 0; @@ -1222,17 +1222,17 @@ static enum test_return ascii_get_unknown_value(char **key, char **value, ssize_ verify(errno == 0); verify(ptr != end); verify(val == 0); - verify(end != NULL); + verify(end); errno = 0; *ndata = (ssize_t) strtoul(end, &end, 10); /* size */ verify(errno == 0); verify(ptr != end); - verify(end != NULL); + verify(end); while (end and *end != '\n' and isspace(*end)) ++end; verify(end and *end == '\n'); *value = static_cast(malloc((size_t) *ndata)); - verify(*value != NULL); + verify(*value); execute(retry_read(*value, (size_t) *ndata)); @@ -1258,14 +1258,14 @@ static enum test_return ascii_get_value(const char *key, const char *value) { verify(errno == 0); verify(ptr != end); verify(val == 0); - verify(end != NULL); + verify(end); errno = 0; val = strtoul(end, &end, 10); /* size */ verify(errno == 0); verify(ptr != end); verify(val == datasize); - verify(end != NULL); + verify(end); while (end and *end != '\n' and isspace(*end)) { ++end; } @@ -1283,7 +1283,7 @@ static enum test_return ascii_get_value(const char *key, const char *value) { static enum test_return ascii_get_item(const char *key, const char *value, bool exist) { char buffer[1024]; size_t datasize = 0; - if (value != NULL) { + if (value) { datasize = strlen(value); } @@ -1317,21 +1317,21 @@ static enum test_return ascii_gets_value(const char *key, const char *value, uns verify(errno == 0); verify(ptr != end); verify(val == 0); - verify(end != NULL); + verify(end); errno = 0; val = strtoul(end, &end, 10); /* size */ verify(errno == 0); verify(ptr != end); verify(val == datasize); - verify(end != NULL); + verify(end); errno = 0; *cas = strtoul(end, &end, 10); /* cas */ verify(errno == 0); verify(ptr != end); verify(val == datasize); - verify(end != NULL); + verify(end); while (end and *end != '\n' and isspace(*end)) { ++end; @@ -1351,7 +1351,7 @@ static enum test_return ascii_gets_item(const char *key, const char *value, bool unsigned long *cas) { char buffer[1024]; size_t datasize = 0; - if (value != NULL) { + if (value) { datasize = strlen(value); } @@ -1727,7 +1727,7 @@ static enum test_return test_ascii_stat(void) { char buffer[1024]; do { execute(receive_line(buffer, sizeof(buffer))); - } while (strcmp(buffer, "END\r\n") != 0); + } while (strcmp(buffer, "END\r\n")); return TEST_PASS_RECONNECT; } @@ -1890,8 +1890,8 @@ int main(int argc, char **argv) { return EXIT_FAILURE; } - for (int ii = 0; testcases[ii].description != NULL; ++ii) { - if (testname != NULL && strcmp(testcases[ii].description, testname) != 0) { + for (int ii = 0; testcases[ii].description; ++ii) { + if (testname && strcmp(testcases[ii].description, testname)) { continue; } @@ -1907,7 +1907,7 @@ int main(int argc, char **argv) { if (prompt) { fprintf(stdout, "\nPress when you are ready? "); char buffer[80] = {0}; - if (fgets(buffer, sizeof(buffer), stdin) != NULL) { + if (fgets(buffer, sizeof(buffer), stdin)) { if (strncmp(buffer, "skip", 4) == 0) { fprintf(stdout, "%-40s%s\n", testcases[ii].description, status_msg[TEST_SKIP]); fflush(stdout); diff --git a/src/bin/memcp.cc b/src/bin/memcp.cc index feb4dcd1..8ab28928 100644 --- a/src/bin/memcp.cc +++ b/src/bin/memcp.cc @@ -62,7 +62,7 @@ static long strtol_wrapper(const char *nptr, int base, bool *error) { /* Check for various possible errors */ - if ((errno == ERANGE and (val == LONG_MAX or val == LONG_MIN)) or (errno != 0 && val == 0)) { + if ((errno == ERANGE and (val == LONG_MAX or val == LONG_MIN)) or (errno && val == 0)) { *error = true; return 0; } diff --git a/src/bin/memerror.cc b/src/bin/memerror.cc index 2580550f..14a70c29 100644 --- a/src/bin/memerror.cc +++ b/src/bin/memerror.cc @@ -47,7 +47,7 @@ int main(int argc, char *argv[]) { char *nptr; unsigned long value = strtoul(argv[optind], &nptr, 10); - if ((errno != 0) or (nptr == argv[optind] and value == 0) + if ((errno) or (nptr == argv[optind] and value == 0) or (value == ULONG_MAX and errno == ERANGE) or (value == 0 and errno == EINVAL)) { std::cerr << "strtoul() was unable to parse given value" << std::endl; diff --git a/src/bin/memflush.cc b/src/bin/memflush.cc index b87521c3..d577a166 100644 --- a/src/bin/memflush.cc +++ b/src/bin/memflush.cc @@ -149,7 +149,7 @@ void options_parse(int argc, char *argv[]) { case OPT_EXPIRE: /* --expire */ errno = 0; opt_expire = (time_t) strtoll(optarg, (char **) NULL, 10); - if (errno != 0) { + if (errno) { std::cerr << "Incorrect value passed to --expire: `" << optarg << "`" << std::endl; exit(EXIT_FAILURE); } diff --git a/src/bin/memping.cc b/src/bin/memping.cc index ba9c1ab2..902954c7 100644 --- a/src/bin/memping.cc +++ b/src/bin/memping.cc @@ -146,7 +146,7 @@ void options_parse(int argc, char *argv[]) { case OPT_EXPIRE: /* --expire */ errno = 0; opt_expire = time_t(strtoll(optarg, (char **) NULL, 10)); - if (errno != 0) { + if (errno) { std::cerr << "Incorrect value passed to --expire: `" << optarg << "`" << std::endl; exit(EXIT_FAILURE); } diff --git a/src/bin/memrm.cc b/src/bin/memrm.cc index c2b4a36f..d2e84e23 100644 --- a/src/bin/memrm.cc +++ b/src/bin/memrm.cc @@ -190,7 +190,7 @@ static void options_parse(int argc, char *argv[]) { case OPT_EXPIRE: /* --expire */ errno = 0; opt_expire = (time_t) strtoll(optarg, (char **) NULL, 10); - if (errno != 0) { + if (errno) { std::cerr << "Incorrect value passed to --expire: `" << optarg << "`" << std::endl; exit(EXIT_FAILURE); } diff --git a/src/bin/memslap.cc b/src/bin/memslap.cc index a8ecf2d1..621217e2 100644 --- a/src/bin/memslap.cc +++ b/src/bin/memslap.cc @@ -285,7 +285,7 @@ void scheduler(memcached_server_st *servers, conclusions_st *conclusion) { } /* now you create the thread */ - if (pthread_create(threads + x, NULL, run_task, (void *) context) != 0) { + if (pthread_create(threads + x, NULL, run_task, (void *) context)) { fprintf(stderr, "Could not create thread\n"); exit(1); } @@ -408,7 +408,7 @@ void options_parse(int argc, char *argv[]) { case OPT_SLAP_CONCURRENCY: errno = 0; opt_concurrency = (unsigned int) strtoul(optarg, (char **) NULL, 10); - if (errno != 0) { + if (errno) { fprintf(stderr, "Invalid value for concurrency: %s\n", optarg); exit(EXIT_FAILURE); } @@ -417,7 +417,7 @@ void options_parse(int argc, char *argv[]) { case OPT_SLAP_EXECUTE_NUMBER: errno = 0; opt_execute_number = (unsigned int) strtoul(optarg, (char **) NULL, 10); - if (errno != 0) { + if (errno) { fprintf(stderr, "Invalid value for execute: %s\n", optarg); exit(EXIT_FAILURE); } @@ -426,7 +426,7 @@ void options_parse(int argc, char *argv[]) { case OPT_SLAP_INITIAL_LOAD: errno = 0; opt_createial_load = (unsigned int) strtoul(optarg, (char **) NULL, 10); - if (errno != 0) { + if (errno) { fprintf(stderr, "Invalid value for initial load: %s\n", optarg); exit(EXIT_FAILURE); } diff --git a/src/bin/memtouch.cc b/src/bin/memtouch.cc index e160e6a3..dbb9ad5c 100644 --- a/src/bin/memtouch.cc +++ b/src/bin/memtouch.cc @@ -200,7 +200,7 @@ void options_parse(int argc, char *argv[]) { case OPT_EXPIRE: errno = 0; expiration = time_t(strtoul(optarg, (char **) NULL, 10)); - if (errno != 0) { + if (errno) { fprintf(stderr, "Invalid value for --expire: %s\n", optarg); exit(EXIT_FAILURE); } diff --git a/src/libmemcached/connect.cc b/src/libmemcached/connect.cc index 3648a242..3803b23e 100644 --- a/src/libmemcached/connect.cc +++ b/src/libmemcached/connect.cc @@ -101,7 +101,7 @@ static memcached_return_t connect_poll(memcached_instance_st *server, const int } // If Zero, my hero, we just fail to a generic MEMCACHED_TIMEOUT error - if (err != 0) { + if (err) { return memcached_set_errno( *server, err, MEMCACHED_AT, memcached_literal_param("getsockopt() found the error from poll() after connect() " @@ -170,7 +170,7 @@ static memcached_return_t set_hostinfo(memcached_instance_st *server) { char str_port[MEMCACHED_NI_MAXSERV] = {0}; errno = 0; int length = snprintf(str_port, MEMCACHED_NI_MAXSERV, "%u", uint32_t(server->port())); - if (length >= MEMCACHED_NI_MAXSERV or length <= 0 or errno != 0) { + if (length >= MEMCACHED_NI_MAXSERV or length <= 0 or errno) { return memcached_set_error(*server, MEMCACHED_MEMORY_ALLOCATION_FAILURE, MEMCACHED_AT, memcached_literal_param("snprintf(NI_MAXSERV)")); } @@ -263,7 +263,7 @@ static bool set_socket_options(memcached_instance_st *server) { #ifdef HAVE_FCNTL // If SOCK_CLOEXEC exists then we don't need to call the following if (SOCK_CLOEXEC == 0) { - if (FD_CLOEXEC != 0) { + if (FD_CLOEXEC) { int flags; do { flags = fcntl(server->fd, F_GETFD, 0); @@ -397,11 +397,11 @@ static memcached_return_t unix_socket_connect(memcached_instance_st *server) { do { int type = SOCK_STREAM; - if (SOCK_CLOEXEC != 0) { + if (SOCK_CLOEXEC) { type |= SOCK_CLOEXEC; } - if (SOCK_NONBLOCK != 0) { + if (SOCK_NONBLOCK) { type |= SOCK_NONBLOCK; } @@ -482,11 +482,11 @@ static memcached_return_t network_connect(memcached_instance_st *server) { /* Create the socket */ while (server->address_info_next and server->fd == INVALID_SOCKET) { int type = server->address_info_next->ai_socktype; - if (SOCK_CLOEXEC != 0) { + if (SOCK_CLOEXEC) { type |= SOCK_CLOEXEC; } - if (SOCK_NONBLOCK != 0) { + if (SOCK_NONBLOCK) { type |= SOCK_NONBLOCK; } diff --git a/src/libmemcached/csl/context.cc b/src/libmemcached/csl/context.cc index ca32d75f..556b5a18 100644 --- a/src/libmemcached/csl/context.cc +++ b/src/libmemcached/csl/context.cc @@ -51,7 +51,7 @@ void Context::error(const char *error_arg, config_tokentype last_token, // We now test if it is something other then a syntax error, if it we // return a generic message - if (strcmp(error_arg, "syntax error") != 0) { + if (strcmp(error_arg, "syntax error")) { memcached_set_parser_error(*memc, MEMCACHED_AT, "Error occured during parsing (%s): last_token=%s(%d)", error_arg, last_token_str, last_token); diff --git a/src/libmemcached/flush_buffers.cc b/src/libmemcached/flush_buffers.cc index 6226775e..512fa2b7 100644 --- a/src/libmemcached/flush_buffers.cc +++ b/src/libmemcached/flush_buffers.cc @@ -23,7 +23,7 @@ memcached_return_t memcached_flush_buffers(memcached_st *shell) { for (uint32_t x = 0; x < memcached_server_count(memc); ++x) { memcached_instance_st *instance = memcached_instance_fetch(memc, x); - if (instance->write_buffer_offset != 0) { + if (instance->write_buffer_offset) { if (instance->fd == INVALID_SOCKET and (ret = memcached_connect(instance)) != MEMCACHED_SUCCESS) { WATCHPOINT_ERROR(ret); diff --git a/src/libmemcached/hosts.cc b/src/libmemcached/hosts.cc index 0ce66130..b478881c 100644 --- a/src/libmemcached/hosts.cc +++ b/src/libmemcached/hosts.cc @@ -345,7 +345,7 @@ memcached_return_t memcached_server_push(memcached_st *shell, const memcached_se ptr->state.is_parsing = true; for (uint32_t x = 0; x < count; ++x, ++original_host_size) { - WATCHPOINT_ASSERT(list[x].hostname[0] != 0); + WATCHPOINT_ASSERT(list[x].hostname[0]); // We have extended the array, and now we will find it, and use it. memcached_instance_st *instance = memcached_instance_fetch(ptr, original_host_size); @@ -396,7 +396,7 @@ memcached_return_t memcached_instance_push(memcached_st *ptr, // We use original_host_size since size will now point to the first new // instance allocated. for (uint32_t x = 0; x < number_of_hosts; ++x, ++original_host_size) { - WATCHPOINT_ASSERT(list[x]._hostname[0] != 0); + WATCHPOINT_ASSERT(list[x]._hostname[0]); // We have extended the array, and now we will find it, and use it. memcached_instance_st *instance = memcached_instance_fetch(ptr, original_host_size); diff --git a/src/libmemcached/io.cc b/src/libmemcached/io.cc index 8e5d93b7..27b5ecbd 100644 --- a/src/libmemcached/io.cc +++ b/src/libmemcached/io.cc @@ -101,7 +101,7 @@ static bool process_input_buffer(memcached_instance_st *instance) { ** We might be able to process some of the response messages if we ** have a callback set up */ - if (instance->root->callbacks != NULL) { + if (instance->root->callbacks) { /* * We might have responses... try to read them out and fire * callbacks diff --git a/src/libmemcached/parse.cc b/src/libmemcached/parse.cc index 37380465..7130cf46 100644 --- a/src/libmemcached/parse.cc +++ b/src/libmemcached/parse.cc @@ -54,7 +54,7 @@ memcached_server_list_st memcached_servers_parse(const char *server_strings) { errno = 0; port = (in_port_t) strtoul(ptr, (char **) NULL, 10); - if (errno != 0) { + if (errno) { memcached_server_free(servers); return NULL; } @@ -67,7 +67,7 @@ memcached_server_list_st memcached_servers_parse(const char *server_strings) { ptr2++; errno = 0; weight = uint32_t(strtoul(ptr2, (char **) NULL, 10)); - if (errno != 0) { + if (errno) { memcached_server_free(servers); return NULL; } diff --git a/src/libmemcached/purge.cc b/src/libmemcached/purge.cc index ae3961b2..4437d761 100644 --- a/src/libmemcached/purge.cc +++ b/src/libmemcached/purge.cc @@ -112,7 +112,7 @@ bool memcached_purge(memcached_instance_st *ptr) { break; } - if (ptr->root->callbacks != NULL) { + if (ptr->root->callbacks) { memcached_callback_st cb = *ptr->root->callbacks; if (memcached_success(rc)) { for (uint32_t y = 0; y < cb.number_of_callback; y++) { diff --git a/src/libmemcached/response.cc b/src/libmemcached/response.cc index 174ed957..5f0f0204 100644 --- a/src/libmemcached/response.cc +++ b/src/libmemcached/response.cc @@ -66,7 +66,7 @@ static memcached_return_t textual_value_fetch(memcached_instance_st *instance, c errno = 0; result->item_flags = (uint32_t) strtoul(next_ptr, &string_ptr, 10); - if (errno != 0 or end_ptr == string_ptr) { + if (errno or end_ptr == string_ptr) { goto read_error; } @@ -81,7 +81,7 @@ static memcached_return_t textual_value_fetch(memcached_instance_st *instance, c errno = 0; value_length = (size_t) strtoull(next_ptr, &string_ptr, 10); - if (errno != 0 or end_ptr == string_ptr) { + if (errno or end_ptr == string_ptr) { goto read_error; } @@ -97,7 +97,7 @@ static memcached_return_t textual_value_fetch(memcached_instance_st *instance, c result->item_cas = strtoull(next_ptr, &string_ptr, 10); } - if (errno != 0 or end_ptr < string_ptr) { + if (errno or end_ptr < string_ptr) { goto read_error; } @@ -202,7 +202,7 @@ static memcached_return_t textual_read_one_response(memcached_instance_st *insta char *endptr; errno = 0; long int version = strtol(response_ptr, &endptr, 10); - if (errno != 0 or version == LONG_MIN or version == LONG_MAX or version > UINT8_MAX + if (errno or version == LONG_MIN or version == LONG_MAX or version > UINT8_MAX or version == 0) { instance->major_version = instance->minor_version = instance->micro_version = UINT8_MAX; return memcached_set_error( @@ -214,7 +214,7 @@ static memcached_return_t textual_read_one_response(memcached_instance_st *insta endptr++; errno = 0; version = strtol(endptr, &endptr, 10); - if (errno != 0 or version == LONG_MIN or version == LONG_MAX or version > UINT8_MAX) { + if (errno or version == LONG_MIN or version == LONG_MAX or version > UINT8_MAX) { instance->major_version = instance->minor_version = instance->micro_version = UINT8_MAX; return memcached_set_error( *instance, MEMCACHED_UNKNOWN_READ_FAILURE, MEMCACHED_AT, @@ -225,7 +225,7 @@ static memcached_return_t textual_read_one_response(memcached_instance_st *insta endptr++; errno = 0; version = strtol(endptr, &endptr, 10); - if (errno != 0 or version == LONG_MIN or version == LONG_MAX or version > UINT8_MAX) { + if (errno or version == LONG_MIN or version == LONG_MAX or version > UINT8_MAX) { instance->major_version = instance->minor_version = instance->micro_version = UINT8_MAX; return memcached_set_error( *instance, MEMCACHED_UNKNOWN_READ_FAILURE, MEMCACHED_AT, @@ -409,7 +409,7 @@ static memcached_return_t textual_read_one_response(memcached_instance_st *insta result->numeric_value = UINT64_MAX; return memcached_set_error(*instance, MEMCACHED_UNKNOWN_READ_FAILURE, MEMCACHED_AT, memcached_literal_param("Numeric response was out of range")); - } else if (errno != 0) { + } else if (errno) { result->numeric_value = UINT64_MAX; return memcached_set_error(*instance, MEMCACHED_UNKNOWN_READ_FAILURE, MEMCACHED_AT, memcached_literal_param("Numeric response was out of range")); @@ -544,7 +544,7 @@ static memcached_return_t binary_read_one_response(memcached_instance_st *instan } break; case PROTOCOL_BINARY_CMD_SASL_LIST_MECHS: { - if (header.response.keylen != 0 || bodylen + 1 > buffer_length) { + if (header.response.keylen || bodylen + 1 > buffer_length) { return MEMCACHED_UNKNOWN_READ_FAILURE; } else { if ((rc = memcached_safe_read(instance, buffer, bodylen)) != MEMCACHED_SUCCESS) { @@ -564,7 +564,7 @@ static memcached_return_t binary_read_one_response(memcached_instance_st *instan char *endptr; errno = 0; long int version = strtol(version_buffer, &endptr, 10); - if (errno != 0 or version == LONG_MIN or version == LONG_MAX or version > UINT8_MAX + if (errno or version == LONG_MIN or version == LONG_MAX or version > UINT8_MAX or version == 0) { instance->major_version = instance->minor_version = instance->micro_version = UINT8_MAX; return memcached_set_error( @@ -576,7 +576,7 @@ static memcached_return_t binary_read_one_response(memcached_instance_st *instan endptr++; errno = 0; version = strtol(endptr, &endptr, 10); - if (errno != 0 or version == LONG_MIN or version == LONG_MAX or version > UINT8_MAX) { + if (errno or version == LONG_MIN or version == LONG_MAX or version > UINT8_MAX) { instance->major_version = instance->minor_version = instance->micro_version = UINT8_MAX; return memcached_set_error( *instance, MEMCACHED_UNKNOWN_READ_FAILURE, MEMCACHED_AT, @@ -587,7 +587,7 @@ static memcached_return_t binary_read_one_response(memcached_instance_st *instan endptr++; errno = 0; version = strtol(endptr, &endptr, 10); - if (errno != 0 or version == LONG_MIN or version == LONG_MAX or version > UINT8_MAX) { + if (errno or version == LONG_MIN or version == LONG_MAX or version > UINT8_MAX) { instance->major_version = instance->minor_version = instance->micro_version = UINT8_MAX; return memcached_set_error( *instance, MEMCACHED_UNKNOWN_READ_FAILURE, MEMCACHED_AT, @@ -701,7 +701,7 @@ static memcached_return_t binary_read_one_response(memcached_instance_st *instan } rc = MEMCACHED_SUCCESS; - if (header.response.status != 0) { + if (header.response.status) { switch (header.response.status) { case PROTOCOL_BINARY_RESPONSE_KEY_ENOENT: rc = MEMCACHED_NOTFOUND; diff --git a/src/libmemcached/sasl.cc b/src/libmemcached/sasl.cc index a190c5b7..849a2256 100644 --- a/src/libmemcached/sasl.cc +++ b/src/libmemcached/sasl.cc @@ -168,7 +168,7 @@ memcached_return_t memcached_sasl_authenticate_connection(memcached_instance_st } int pthread_error; - if ((pthread_error = pthread_once(&sasl_startup_once, sasl_startup_function)) != 0) { + if ((pthread_error = pthread_once(&sasl_startup_once, sasl_startup_function))) { return memcached_set_errno(*server, pthread_error, MEMCACHED_AT); } diff --git a/src/libmemcached/server_list.cc b/src/libmemcached/server_list.cc index d5c39c34..665b75dc 100644 --- a/src/libmemcached/server_list.cc +++ b/src/libmemcached/server_list.cc @@ -36,7 +36,7 @@ memcached_server_list_st memcached_server_list_append_with_weight(memcached_serv /* Increment count for hosts */ uint32_t count = 1; - if (ptr != NULL) { + if (ptr) { count += memcached_server_list_count(ptr); } diff --git a/src/libmemcached/stats.cc b/src/libmemcached/stats.cc index e1e71c2d..13600ff4 100644 --- a/src/libmemcached/stats.cc +++ b/src/libmemcached/stats.cc @@ -61,7 +61,7 @@ static memcached_return_t set_data(memcached_stat_st *memc_stat, const char *key } else if (strcmp("pid", key) == 0) { errno = 0; int64_t temp = strtoll(value, (char **) NULL, 10); - if (errno != 0) { + if (errno) { return MEMCACHED_FAILURE; } @@ -76,13 +76,13 @@ static memcached_return_t set_data(memcached_stat_st *memc_stat, const char *key } else if (not strcmp("uptime", key)) { errno = 0; memc_stat->uptime = strtoul(value, (char **) NULL, 10); - if (errno != 0) { + if (errno) { return MEMCACHED_FAILURE; } } else if (not strcmp("time", key)) { errno = 0; memc_stat->time = strtoul(value, (char **) NULL, 10); - if (errno != 0) { + if (errno) { return MEMCACHED_FAILURE; } } else if (not strcmp("version", key)) { @@ -91,7 +91,7 @@ static memcached_return_t set_data(memcached_stat_st *memc_stat, const char *key } else if (not strcmp("pointer_size", key)) { errno = 0; memc_stat->pointer_size = strtoul(value, (char **) NULL, 10); - if (errno != 0) { + if (errno) { return MEMCACHED_FAILURE; } } else if (not strcmp("rusage_user", key)) { @@ -103,13 +103,13 @@ static memcached_return_t set_data(memcached_stat_st *memc_stat, const char *key errno = 0; memc_stat->rusage_user_seconds = strtoul(value, (char **) NULL, 10); - if (errno != 0) { + if (errno) { return MEMCACHED_FAILURE; } errno = 0; memc_stat->rusage_user_microseconds = strtoul(walk_ptr, (char **) NULL, 10); - if (errno != 0) { + if (errno) { return MEMCACHED_FAILURE; } } else if (not strcmp("rusage_system", key)) { @@ -121,103 +121,103 @@ static memcached_return_t set_data(memcached_stat_st *memc_stat, const char *key errno = 0; memc_stat->rusage_system_seconds = strtoul(value, (char **) NULL, 10); - if (errno != 0) { + if (errno) { return MEMCACHED_FAILURE; } errno = 0; memc_stat->rusage_system_microseconds = strtoul(walk_ptr, (char **) NULL, 10); - if (errno != 0) { + if (errno) { return MEMCACHED_FAILURE; } } else if (not strcmp("curr_items", key)) { errno = 0; memc_stat->curr_items = strtoul(value, (char **) NULL, 10); - if (errno != 0) { + if (errno) { return MEMCACHED_FAILURE; } } else if (not strcmp("total_items", key)) { errno = 0; memc_stat->total_items = strtoul(value, (char **) NULL, 10); - if (errno != 0) { + if (errno) { return MEMCACHED_FAILURE; } } else if (not strcmp("bytes_read", key)) { errno = 0; memc_stat->bytes_read = strtoull(value, (char **) NULL, 10); - if (errno != 0) { + if (errno) { return MEMCACHED_FAILURE; } } else if (not strcmp("bytes_written", key)) { errno = 0; memc_stat->bytes_written = strtoull(value, (char **) NULL, 10); - if (errno != 0) { + if (errno) { return MEMCACHED_FAILURE; } } else if (not strcmp("bytes", key)) { errno = 0; memc_stat->bytes = strtoull(value, (char **) NULL, 10); - if (errno != 0) { + if (errno) { return MEMCACHED_FAILURE; } } else if (not strcmp("curr_connections", key)) { errno = 0; memc_stat->curr_connections = strtoull(value, (char **) NULL, 10); - if (errno != 0) { + if (errno) { return MEMCACHED_FAILURE; } } else if (not strcmp("total_connections", key)) { errno = 0; memc_stat->total_connections = strtoull(value, (char **) NULL, 10); - if (errno != 0) { + if (errno) { return MEMCACHED_FAILURE; } } else if (not strcmp("connection_structures", key)) { errno = 0; memc_stat->connection_structures = strtoul(value, (char **) NULL, 10); - if (errno != 0) { + if (errno) { return MEMCACHED_FAILURE; } } else if (not strcmp("cmd_get", key)) { errno = 0; memc_stat->cmd_get = strtoull(value, (char **) NULL, 10); - if (errno != 0) { + if (errno) { return MEMCACHED_FAILURE; } } else if (not strcmp("cmd_set", key)) { errno = 0; memc_stat->cmd_set = strtoull(value, (char **) NULL, 10); - if (errno != 0) { + if (errno) { return MEMCACHED_FAILURE; } } else if (not strcmp("get_hits", key)) { errno = 0; memc_stat->get_hits = strtoull(value, (char **) NULL, 10); - if (errno != 0) { + if (errno) { return MEMCACHED_FAILURE; } } else if (not strcmp("get_misses", key)) { errno = 0; memc_stat->get_misses = strtoull(value, (char **) NULL, 10); - if (errno != 0) { + if (errno) { return MEMCACHED_FAILURE; } } else if (not strcmp("evictions", key)) { errno = 0; memc_stat->evictions = strtoull(value, (char **) NULL, 10); - if (errno != 0) { + if (errno) { return MEMCACHED_FAILURE; } } else if (not strcmp("limit_maxbytes", key)) { errno = 0; memc_stat->limit_maxbytes = strtoull(value, (char **) NULL, 10); - if (errno != 0) { + if (errno) { return MEMCACHED_FAILURE; } } else if (not strcmp("threads", key)) { errno = 0; memc_stat->threads = strtoul(value, (char **) NULL, 10); - if (errno != 0) { + if (errno) { return MEMCACHED_FAILURE; } } else if ((strcmp("delete_misses", key) == 0 or /* New stats in the 1.3 beta */ diff --git a/src/libmemcached/udp.cc b/src/libmemcached/udp.cc index 0d1eb157..99052c07 100644 --- a/src/libmemcached/udp.cc +++ b/src/libmemcached/udp.cc @@ -32,7 +32,7 @@ void increment_udp_message_id(memcached_instance_st *ptr) { int msg_num = get_msg_num_from_request_id(cur_req); int thread_id = get_thread_id_from_request_id(cur_req); - if (((++msg_num) & UDP_REQUEST_ID_THREAD_MASK) != 0) + if (((++msg_num) & UDP_REQUEST_ID_THREAD_MASK)) msg_num = 0; header->request_id = htons((uint16_t)(thread_id | msg_num)); diff --git a/src/libmemcachedprotocol/ascii_handler.c b/src/libmemcachedprotocol/ascii_handler.c index f5d8e22c..17848f97 100644 --- a/src/libmemcachedprotocol/ascii_handler.c +++ b/src/libmemcachedprotocol/ascii_handler.c @@ -141,7 +141,7 @@ ascii_raw_response_handler(memcached_protocol_client_st *client, const char *tex return PROTOCOL_BINARY_RESPONSE_EINTERNAL; } - assert(client->output != NULL); + assert(client->output); #if 0 if (client->output == NULL) { @@ -285,7 +285,7 @@ static protocol_binary_response_status ascii_stat_response_handler(const void *c uint32_t bodylen) { memcached_protocol_client_st *client = (void *) cookie; - if (key != NULL) { + if (key) { ascii_raw_response_handler(client, "STAT "); client->root->spool(client, key, keylen); ascii_raw_response_handler(client, " "); @@ -479,7 +479,7 @@ static void process_arithmetic(memcached_protocol_client_st *client, char **toke uint64_t result; errno = 0; uint64_t delta = strtoull(tokens[2], NULL, 10); - if (errno != 0) { + if (errno) { return; // Error } @@ -558,7 +558,7 @@ static void process_flush(memcached_protocol_client_st *client, char **tokens, i if (ntokens == 2) { errno = 0; timeout = (uint32_t) strtoul(tokens[1], NULL, 10); - if (errno != 0) { + if (errno) { return; // Error } } @@ -598,21 +598,21 @@ static inline int process_storage_command(memcached_protocol_client_st *client, errno = 0; uint32_t flags = (uint32_t) strtoul(tokens[2], NULL, 10); - if (errno != 0) { + if (errno) { /* return error */ ascii_raw_response_handler(client, "CLIENT_ERROR: bad key\r\n"); return -1; } uint32_t timeout = (uint32_t) strtoul(tokens[3], NULL, 10); - if (errno != 0) { + if (errno) { /* return error */ ascii_raw_response_handler(client, "CLIENT_ERROR: bad key\r\n"); return -1; } unsigned long nbytes = strtoul(tokens[4], NULL, 10); - if (errno != 0) { + if (errno) { /* return error */ ascii_raw_response_handler(client, "CLIENT_ERROR: bad key\r\n"); return -1; @@ -642,7 +642,7 @@ static inline int process_storage_command(memcached_protocol_client_st *client, case CAS_CMD: errno = 0; cas = strtoull(tokens[5], NULL, 10); - if (errno != 0) { + if (errno) { /* return error */ ascii_raw_response_handler(client, "CLIENT_ERROR: bad key\r\n"); return -1; @@ -810,7 +810,7 @@ memcached_ascii_protocol_process_data(memcached_protocol_client_st *client, ssiz client->ascii_command = ascii_to_cmd(ptr, (size_t)(*length)); /* we got all data available, execute the callback! */ - if (client->root->callback->pre_execute != NULL) { + if (client->root->callback->pre_execute) { client->root->callback->pre_execute(client, NULL); } @@ -819,7 +819,7 @@ memcached_ascii_protocol_process_data(memcached_protocol_client_st *client, ssiz * just handle them immediately */ if (client->ascii_command == GET_CMD || client->ascii_command == GETS_CMD) { - if (client->root->callback->interface.v1.get != NULL) { + if (client->root->callback->interface.v1.get) { ascii_process_gets(client, ptr, end); } else { ascii_raw_response_handler(client, "SERVER_ERROR: Command not implemented\n"); @@ -900,7 +900,7 @@ memcached_ascii_protocol_process_data(memcached_protocol_client_st *client, ssiz if (ntokens != 1 || client->mute) { send_command_usage(client); } else { - if (client->root->callback->interface.v1.quit != NULL) { + if (client->root->callback->interface.v1.quit) { client->root->callback->interface.v1.quit(client); } @@ -934,7 +934,7 @@ memcached_ascii_protocol_process_data(memcached_protocol_client_st *client, ssiz } } - if (client->root->callback->post_execute != NULL) { + if (client->root->callback->post_execute) { client->root->callback->post_execute(client, NULL); } diff --git a/src/libmemcachedprotocol/binary_handler.c b/src/libmemcachedprotocol/binary_handler.c index c7a76b3f..ada4c425 100644 --- a/src/libmemcachedprotocol/binary_handler.c +++ b/src/libmemcachedprotocol/binary_handler.c @@ -405,7 +405,7 @@ add_command_handler(const void *cookie, protocol_binary_request_header *header, protocol_binary_response_status rval; memcached_protocol_client_st *client = (void *) cookie; - if (client->root->callback->interface.v1.add != NULL) { + if (client->root->callback->interface.v1.add) { uint16_t keylen = ntohs(header->request.keylen); uint32_t datalen = ntohl(header->request.bodylen) - keylen - 8; protocol_binary_request_add *request = (void *) header; @@ -450,7 +450,7 @@ decrement_command_handler(const void *cookie, protocol_binary_request_header *he protocol_binary_response_status rval; memcached_protocol_client_st *client = (void *) cookie; - if (client->root->callback->interface.v1.decrement != NULL) { + if (client->root->callback->interface.v1.decrement) { uint16_t keylen = ntohs(header->request.keylen); protocol_binary_request_decr *request = (void *) header; uint64_t init = memcached_ntohll(request->message.body.initial); @@ -497,7 +497,7 @@ delete_command_handler(const void *cookie, protocol_binary_request_header *heade protocol_binary_response_status rval; memcached_protocol_client_st *client = (void *) cookie; - if (client->root->callback->interface.v1.delete_object != NULL) { + if (client->root->callback->interface.v1.delete_object) { uint16_t keylen = ntohs(header->request.keylen); void *key = (header + 1); uint64_t cas = memcached_ntohll(header->request.cas); @@ -536,7 +536,7 @@ flush_command_handler(const void *cookie, protocol_binary_request_header *header protocol_binary_response_status rval; memcached_protocol_client_st *client = (void *) cookie; - if (client->root->callback->interface.v1.flush_object != NULL) { + if (client->root->callback->interface.v1.flush_object) { protocol_binary_request_flush *flush_object = (void *) header; uint32_t timeout = 0; if (htonl(header->request.bodylen) == 4) { @@ -577,7 +577,7 @@ get_command_handler(const void *cookie, protocol_binary_request_header *header, protocol_binary_response_status rval; memcached_protocol_client_st *client = (void *) cookie; - if (client->root->callback->interface.v1.get != NULL) { + if (client->root->callback->interface.v1.get) { uint16_t keylen = ntohs(header->request.keylen); void *key = (header + 1); rval = client->root->callback->interface.v1.get(cookie, key, keylen, get_response_handler); @@ -610,7 +610,7 @@ increment_command_handler(const void *cookie, protocol_binary_request_header *he protocol_binary_response_status rval; memcached_protocol_client_st *client = (void *) cookie; - if (client->root->callback->interface.v1.increment != NULL) { + if (client->root->callback->interface.v1.increment) { uint16_t keylen = ntohs(header->request.keylen); protocol_binary_request_incr *request = (void *) header; uint64_t init = memcached_ntohll(request->message.body.initial); @@ -657,7 +657,7 @@ static protocol_binary_response_status noop_command_handler(const void *cookie, protocol_binary_request_header *header, memcached_binary_protocol_raw_response_handler response_handler) { memcached_protocol_client_st *client = (void *) cookie; - if (client->root->callback->interface.v1.noop != NULL) { + if (client->root->callback->interface.v1.noop) { client->root->callback->interface.v1.noop(cookie); } @@ -686,7 +686,7 @@ append_command_handler(const void *cookie, protocol_binary_request_header *heade protocol_binary_response_status rval; memcached_protocol_client_st *client = (void *) cookie; - if (client->root->callback->interface.v1.append != NULL) { + if (client->root->callback->interface.v1.append) { uint16_t keylen = ntohs(header->request.keylen); uint32_t datalen = ntohl(header->request.bodylen) - keylen; char *key = (void *) (header + 1); @@ -734,7 +734,7 @@ prepend_command_handler(const void *cookie, protocol_binary_request_header *head protocol_binary_response_status rval; memcached_protocol_client_st *client = (void *) cookie; - if (client->root->callback->interface.v1.prepend != NULL) { + if (client->root->callback->interface.v1.prepend) { uint16_t keylen = ntohs(header->request.keylen); uint32_t datalen = ntohl(header->request.bodylen) - keylen; char *key = (char *) (header + 1); @@ -778,7 +778,7 @@ static protocol_binary_response_status quit_command_handler(const void *cookie, protocol_binary_request_header *header, memcached_binary_protocol_raw_response_handler response_handler) { memcached_protocol_client_st *client = (void *) cookie; - if (client->root->callback->interface.v1.quit != NULL) { + if (client->root->callback->interface.v1.quit) { client->root->callback->interface.v1.quit(cookie); } @@ -810,7 +810,7 @@ replace_command_handler(const void *cookie, protocol_binary_request_header *head protocol_binary_response_status rval; memcached_protocol_client_st *client = (void *) cookie; - if (client->root->callback->interface.v1.replace != NULL) { + if (client->root->callback->interface.v1.replace) { uint16_t keylen = ntohs(header->request.keylen); uint32_t datalen = ntohl(header->request.bodylen) - keylen - 8; protocol_binary_request_replace *request = (void *) header; @@ -861,7 +861,7 @@ set_command_handler(const void *cookie, protocol_binary_request_header *header, protocol_binary_response_status rval; memcached_protocol_client_st *client = (void *) cookie; - if (client->root->callback->interface.v1.set != NULL) { + if (client->root->callback->interface.v1.set) { uint16_t keylen = ntohs(header->request.keylen); uint32_t datalen = ntohl(header->request.bodylen) - keylen - 8; protocol_binary_request_replace *request = (void *) header; @@ -911,7 +911,7 @@ stat_command_handler(const void *cookie, protocol_binary_request_header *header, protocol_binary_response_status rval; memcached_protocol_client_st *client = (void *) cookie; - if (client->root->callback->interface.v1.stat != NULL) { + if (client->root->callback->interface.v1.stat) { uint16_t keylen = ntohs(header->request.keylen); rval = client->root->callback->interface.v1.stat(cookie, (void *) (header + 1), keylen, @@ -938,7 +938,7 @@ version_command_handler(const void *cookie, protocol_binary_request_header *head protocol_binary_response_status rval; memcached_protocol_client_st *client = (void *) cookie; - if (client->root->callback->interface.v1.version != NULL) { + if (client->root->callback->interface.v1.version) { rval = client->root->callback->interface.v1.version(cookie, version_response_handler); } else { rval = PROTOCOL_BINARY_RESPONSE_UNKNOWN_COMMAND; @@ -996,7 +996,7 @@ static protocol_binary_response_status execute_command(memcached_protocol_client } /* we got all data available, execute the callback! */ - if (client->root->callback->pre_execute != NULL) { + if (client->root->callback->pre_execute) { client->root->callback->pre_execute(client, header); } @@ -1009,14 +1009,14 @@ static protocol_binary_response_status execute_command(memcached_protocol_client switch (client->root->callback->interface_version) { case 0: - if (client->root->callback->interface.v0.comcode[cc] != NULL) { + if (client->root->callback->interface.v0.comcode[cc]) { rval = client->root->callback->interface.v0.comcode[cc](client, header, binary_raw_response_handler); } break; case 1: - if (comcode_v0_v1_remap[cc] != NULL) { + if (comcode_v0_v1_remap[cc]) { rval = comcode_v0_v1_remap[cc](client, header, binary_raw_response_handler); } break; @@ -1029,7 +1029,7 @@ static protocol_binary_response_status execute_command(memcached_protocol_client abort(); } - if (rval == PROTOCOL_BINARY_RESPONSE_UNKNOWN_COMMAND && client->root->callback->unknown != NULL) { + if (rval == PROTOCOL_BINARY_RESPONSE_UNKNOWN_COMMAND && client->root->callback->unknown) { rval = client->root->callback->unknown(client, header, binary_raw_response_handler); } @@ -1048,7 +1048,7 @@ static protocol_binary_response_status execute_command(memcached_protocol_client rval = binary_raw_response_handler(client, header, (void *) &response); } - if (client->root->callback->post_execute != NULL) { + if (client->root->callback->post_execute) { client->root->callback->post_execute(client, header); } diff --git a/src/libmemcachedprotocol/cache.c b/src/libmemcachedprotocol/cache.c index 637665d7..1699f735 100644 --- a/src/libmemcachedprotocol/cache.c +++ b/src/libmemcachedprotocol/cache.c @@ -94,10 +94,10 @@ void *cache_alloc(cache_t *cache) { object = get_object(ret); } else { object = ret = malloc(cache->bufsize); - if (ret != NULL) { + if (ret) { object = get_object(ret); - if (cache->constructor != NULL && cache->constructor(object, NULL, 0) != 0) { + if (cache->constructor && cache->constructor(object, NULL, 0)) { free(ret); object = NULL; } @@ -106,7 +106,7 @@ void *cache_alloc(cache_t *cache) { pthread_mutex_unlock(&cache->mutex); #ifndef NDEBUG - if (object != NULL) { + if (object) { /* add a simple form of buffer-check */ uint64_t *pre = ret; *pre = redzone_pattern; @@ -126,7 +126,7 @@ void cache_free(cache_t *cache, void *ptr) { /* validate redzone... */ if (memcmp(((char *) ptr) + cache->bufsize - (2 * sizeof(redzone_pattern)), &redzone_pattern, sizeof(redzone_pattern)) - != 0) +) { raise(SIGABRT); cache_error = 1; diff --git a/src/libmemcachedprotocol/handler.c b/src/libmemcachedprotocol/handler.c index 885c798f..b412b9e9 100644 --- a/src/libmemcachedprotocol/handler.c +++ b/src/libmemcachedprotocol/handler.c @@ -82,7 +82,7 @@ static bool drain_output(struct memcached_protocol_client_st *client) { } /* Do we have pending data to send? */ - while (client->output != NULL) { + while (client->output) { ssize_t len = client->root->send(client, client->sock, client->output->data + client->output->offset, client->output->nbytes - client->output->offset); @@ -238,7 +238,7 @@ static memcached_protocol_event_t determine_protocol(struct memcached_protocol_c */ struct memcached_protocol_st *memcached_protocol_create_instance(void) { struct memcached_protocol_st *ret = calloc(1, sizeof(*ret)); - if (ret != NULL) { + if (ret) { ret->recv = default_recv; ret->send = default_send; ret->drain = drain_output; @@ -273,7 +273,7 @@ void memcached_protocol_destroy_instance(struct memcached_protocol_st *instance) struct memcached_protocol_client_st * memcached_protocol_create_client(struct memcached_protocol_st *instance, memcached_socket_t sock) { struct memcached_protocol_client_st *ret = calloc(1, sizeof(memcached_protocol_client_st)); - if (ret != NULL) { + if (ret) { ret->root = instance; ret->sock = sock; ret->work = determine_protocol; diff --git a/src/libmemcachedprotocol/pedantic.c b/src/libmemcachedprotocol/pedantic.c index b6e7a002..9b7d728f 100644 --- a/src/libmemcachedprotocol/pedantic.c +++ b/src/libmemcachedprotocol/pedantic.c @@ -152,7 +152,7 @@ bool memcached_binary_protocol_pedantic_check_response( ensure(response->response.keylen == 0); ensure(response->response.extlen == 0); ensure(response->response.bodylen == 0); - ensure(response->response.cas != 0); + ensure(response->response.cas); break; case PROTOCOL_BINARY_CMD_FLUSH: case PROTOCOL_BINARY_CMD_NOOP: @@ -169,7 +169,7 @@ bool memcached_binary_protocol_pedantic_check_response( ensure(response->response.keylen == 0); ensure(response->response.extlen == 0); ensure(ntohl(response->response.bodylen) == 8); - ensure(response->response.cas != 0); + ensure(response->response.cas); break; case PROTOCOL_BINARY_CMD_STAT: @@ -181,7 +181,7 @@ bool memcached_binary_protocol_pedantic_check_response( case PROTOCOL_BINARY_CMD_VERSION: ensure(response->response.keylen == 0); ensure(response->response.extlen == 0); - ensure(response->response.bodylen != 0); + ensure(response->response.bodylen); ensure(response->response.cas == 0); break; @@ -189,14 +189,14 @@ bool memcached_binary_protocol_pedantic_check_response( case PROTOCOL_BINARY_CMD_GETQ: ensure(response->response.keylen == 0); ensure(response->response.extlen == 4); - ensure(response->response.cas != 0); + ensure(response->response.cas); break; case PROTOCOL_BINARY_CMD_GETK: case PROTOCOL_BINARY_CMD_GETKQ: - ensure(response->response.keylen != 0); + ensure(response->response.keylen); ensure(response->response.extlen == 4); - ensure(response->response.cas != 0); + ensure(response->response.cas); break; default: diff --git a/src/libmemcachedutil/pool.cc b/src/libmemcachedutil/pool.cc index 718be8b2..b57cc761 100644 --- a/src/libmemcachedutil/pool.cc +++ b/src/libmemcachedutil/pool.cc @@ -62,12 +62,12 @@ struct memcached_pool_st { } int error; - if ((error = pthread_mutex_destroy(&mutex)) != 0) { - assert_vmsg(error != 0, "pthread_mutex_destroy() %s(%d)", strerror(error), error); + if ((error = pthread_mutex_destroy(&mutex))) { + assert_vmsg(error, "pthread_mutex_destroy() %s(%d)", strerror(error), error); } - if ((error = pthread_cond_destroy(&cond)) != 0) { - assert_vmsg(error != 0, "pthread_cond_destroy() %s", strerror(error)); + if ((error = pthread_cond_destroy(&cond))) { + assert_vmsg(error, "pthread_cond_destroy() %s", strerror(error)); } delete[] server_pool; @@ -200,7 +200,7 @@ memcached_st *memcached_pool_st::fetch(const struct timespec &relative_time, rc = MEMCACHED_SUCCESS; int error; - if ((error = pthread_mutex_lock(&mutex)) != 0) { + if ((error = pthread_mutex_lock(&mutex))) { rc = MEMCACHED_IN_PROGRESS; return NULL; } @@ -222,10 +222,10 @@ memcached_st *memcached_pool_st::fetch(const struct timespec &relative_time, time_to_wait.tv_nsec = relative_time.tv_nsec; int thread_ret; - if ((thread_ret = pthread_cond_timedwait(&cond, &mutex, &time_to_wait)) != 0) { + if ((thread_ret = pthread_cond_timedwait(&cond, &mutex, &time_to_wait))) { int unlock_error; - if ((unlock_error = pthread_mutex_unlock(&mutex)) != 0) { - assert_vmsg(error != 0, "pthread_mutex_unlock() %s", strerror(error)); + if ((unlock_error = pthread_mutex_unlock(&mutex))) { + assert_vmsg(error, "pthread_mutex_unlock() %s", strerror(error)); } if (thread_ret == ETIMEDOUT) { @@ -239,16 +239,16 @@ memcached_st *memcached_pool_st::fetch(const struct timespec &relative_time, } } else if (grow_pool(this) == false) { int unlock_error; - if ((unlock_error = pthread_mutex_unlock(&mutex)) != 0) { - assert_vmsg(error != 0, "pthread_mutex_unlock() %s", strerror(error)); + if ((unlock_error = pthread_mutex_unlock(&mutex))) { + assert_vmsg(error, "pthread_mutex_unlock() %s", strerror(error)); } return NULL; } } while (ret == NULL); - if ((error = pthread_mutex_unlock(&mutex)) != 0) { - assert_vmsg(error != 0, "pthread_mutex_unlock() %s", strerror(error)); + if ((error = pthread_mutex_unlock(&mutex))) { + assert_vmsg(error, "pthread_mutex_unlock() %s", strerror(error)); } return ret; @@ -283,12 +283,12 @@ bool memcached_pool_st::release(memcached_st *released, memcached_return_t &rc) if (firstfree == 0 and current_size == size) { /* we might have people waiting for a connection.. wake them up :-) */ - if ((error = pthread_cond_broadcast(&cond)) != 0) { - assert_vmsg(error != 0, "pthread_cond_broadcast() %s", strerror(error)); + if ((error = pthread_cond_broadcast(&cond))) { + assert_vmsg(error, "pthread_cond_broadcast() %s", strerror(error)); } } - if ((error = pthread_mutex_unlock(&mutex)) != 0) { + if ((error = pthread_mutex_unlock(&mutex))) { } return true; @@ -362,8 +362,8 @@ memcached_return_t memcached_pool_behavior_set(memcached_pool_st *pool, memcache /* update the master */ memcached_return_t rc = memcached_behavior_set(pool->master, flag, data); if (memcached_failed(rc)) { - if ((error = pthread_mutex_unlock(&pool->mutex)) != 0) { - assert_vmsg(error != 0, "pthread_mutex_unlock() %s", strerror(error)); + if ((error = pthread_mutex_unlock(&pool->mutex))) { + assert_vmsg(error, "pthread_mutex_unlock() %s", strerror(error)); } return rc; } @@ -388,8 +388,8 @@ memcached_return_t memcached_pool_behavior_set(memcached_pool_st *pool, memcache } } - if ((error = pthread_mutex_unlock(&pool->mutex)) != 0) { - assert_vmsg(error != 0, "pthread_mutex_unlock() %s", strerror(error)); + if ((error = pthread_mutex_unlock(&pool->mutex))) { + assert_vmsg(error, "pthread_mutex_unlock() %s", strerror(error)); } return rc; @@ -408,8 +408,8 @@ memcached_return_t memcached_pool_behavior_get(memcached_pool_st *pool, memcache *value = memcached_behavior_get(pool->master, flag); - if ((error = pthread_mutex_unlock(&pool->mutex)) != 0) { - assert_vmsg(error != 0, "pthread_mutex_unlock() %s", strerror(error)); + if ((error = pthread_mutex_unlock(&pool->mutex))) { + assert_vmsg(error, "pthread_mutex_unlock() %s", strerror(error)); } return MEMCACHED_SUCCESS; diff --git a/src/util/signal.cc b/src/util/signal.cc index b1a7a4e2..3760e548 100644 --- a/src/util/signal.cc +++ b/src/util/signal.cc @@ -122,7 +122,7 @@ SignalThread::~SignalThread() } #if 0 - if (pthread_equal(thread, pthread_self()) != 0 and (pthread_kill(thread, 0) == ESRCH) == true) + if (pthread_equal(thread, pthread_self()) and (pthread_kill(thread, 0) == ESRCH) == true) { void *retval; pthread_join(thread, &retval); @@ -211,13 +211,13 @@ bool SignalThread::setup() set_shutdown(SHUTDOWN_RUNNING); int error; - if ((error= pthread_sigmask(SIG_BLOCK, &set, NULL)) != 0) + if ((error= pthread_sigmask(SIG_BLOCK, &set, NULL))) { std::cerr << "pthread_sigmask() died during pthread_sigmask(" << strerror(error) << ")" << std::endl; return false; } - if ((error= pthread_create(&thread, NULL, &sig_thread, this)) != 0) + if ((error= pthread_create(&thread, NULL, &sig_thread, this))) { std::cerr << "pthread_create() died during pthread_create(" << strerror(error) << ")" << std::endl; return false;