From: Jan Engelhardt Date: Sun, 25 Oct 2020 14:41:24 +0000 (+0100) Subject: extensions: split assignments and if-exprs X-Git-Tag: v3.12~8 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=bfb0516c795ef9897c2b5df413642590440b14ee;p=thirdparty%2Fxtables-addons.git extensions: split assignments and if-exprs --- diff --git a/extensions/ACCOUNT/libxt_ACCOUNT_cl.c b/extensions/ACCOUNT/libxt_ACCOUNT_cl.c index fb52806..901b773 100644 --- a/extensions/ACCOUNT/libxt_ACCOUNT_cl.c +++ b/extensions/ACCOUNT/libxt_ACCOUNT_cl.c @@ -34,7 +34,8 @@ int ipt_ACCOUNT_init(struct ipt_ACCOUNT_context *ctx) // 4096 bytes default buffer should save us from reallocations // as it fits 200 concurrent active clients - if ((ctx->data = malloc(IPT_ACCOUNT_MIN_BUFSIZE)) == NULL) { + ctx->data = malloc(IPT_ACCOUNT_MIN_BUFSIZE); + if (ctx->data == NULL) { close(ctx->sockfd); ctx->sockfd = -1; ctx->error_str = "Out of memory for data buffer"; diff --git a/extensions/ACCOUNT/xt_ACCOUNT.c b/extensions/ACCOUNT/xt_ACCOUNT.c index 18e0b8a..7f4da85 100644 --- a/extensions/ACCOUNT/xt_ACCOUNT.c +++ b/extensions/ACCOUNT/xt_ACCOUNT.c @@ -627,7 +627,8 @@ static int ipt_acc_handle_prepare_read(struct ipt_acc_table *ipt_acc_tables, dest->itemcount = ipt_acc_tables[table_nr].itemcount; /* allocate "root" table */ - if ((dest->data = ipt_acc_zalloc_page()) == NULL) { + dest->data = ipt_acc_zalloc_page(); + if (dest->data == NULL) { printk("ACCOUNT: out of memory for root table " "in ipt_acc_handle_prepare_read()\n"); return -1; @@ -725,7 +726,8 @@ static int ipt_acc_handle_prepare_read_flush(struct ipt_acc_table *ipt_acc_table } /* Try to allocate memory */ - if (!(new_data_page = ipt_acc_zalloc_page())) { + new_data_page = ipt_acc_zalloc_page(); + if (new_data_page == NULL) { printk("ACCOUNT: ipt_acc_handle_prepare_read_flush(): " "Out of memory!\n"); return -1; @@ -979,7 +981,8 @@ static int ipt_acc_get_ctl(struct sock *sk, int cmd, void *user, int *len) /* Allocate a userspace handle */ down(&ian->ipt_acc_userspace_mutex); - if ((handle.handle_nr = ipt_acc_handle_find_slot(ian->ipt_acc_handles)) == -1) { + handle.handle_nr = ipt_acc_handle_find_slot(ian->ipt_acc_handles); + if (handle.handle_nr == -1) { ipt_acc_data_free(dest.data, dest.depth); up(&ian->ipt_acc_userspace_mutex); return -EINVAL; diff --git a/extensions/libxt_geoip.c b/extensions/libxt_geoip.c index 5b8697d..b91cd5d 100644 --- a/extensions/libxt_geoip.c +++ b/extensions/libxt_geoip.c @@ -75,7 +75,6 @@ geoip_get_subnets(const char *code, uint32_t *count, uint8_t nfproto) void *subnets; struct stat sb; char buf[256]; - int fd; #if __BYTE_ORDER == __LITTLE_ENDIAN unsigned int n; #endif @@ -86,7 +85,8 @@ geoip_get_subnets(const char *code, uint32_t *count, uint8_t nfproto) else snprintf(buf, sizeof(buf), GEOIP_DB_DIR "/%s.iv4", code); - if ((fd = open(buf, O_RDONLY)) < 0) { + int fd = open(buf, O_RDONLY); + if (fd < 0) { fprintf(stderr, "Could not open %s: %s\n", buf, strerror(errno)); xtables_error(OTHER_PROBLEM, "Could not read geoip database"); } @@ -203,7 +203,8 @@ static unsigned int parse_geoip_cc(const char *ccstr, uint16_t *cc, next = strchr(cp, ','); if (next) *next++ = '\0'; - if ((cctmp = check_geoip_cc(cp, cc, count)) != 0) { + cctmp = check_geoip_cc(cp, cc, count); + if (cctmp != 0) { if ((mem[count++].user = (unsigned long)geoip_load_cc(cp, cctmp, nfproto)) == 0) xtables_error(OTHER_PROBLEM, diff --git a/extensions/pknock/libxt_pknock.c b/extensions/pknock/libxt_pknock.c index 1cd8293..5a9aab8 100644 --- a/extensions/pknock/libxt_pknock.c +++ b/extensions/pknock/libxt_pknock.c @@ -91,12 +91,11 @@ proto_to_name(uint8_t proto) static const char * check_proto(uint16_t pnum, uint8_t invflags) { - char *proto; - if (invflags & XT_INV_PROTO) xtables_error(PARAMETER_PROBLEM, PKNOCK "only works with TCP and UDP."); - if ((proto = proto_to_name(pnum)) != NULL) + const char *proto = proto_to_name(pnum); + if (proto != NULL) return proto; else if (pnum == 0) xtables_error(PARAMETER_PROBLEM, PKNOCK "needs `-p tcp' or `-p udp'"); diff --git a/extensions/pknock/pknlusr.c b/extensions/pknock/pknlusr.c index 77deb2a..33c0f05 100644 --- a/extensions/pknock/pknlusr.c +++ b/extensions/pknock/pknlusr.c @@ -30,8 +30,8 @@ int main(int argc, char **argv) struct xt_pknock_nl_msg *pknock_msg; if (argc > 2) { - char *prog; - if (!(prog = strdup(argv[0]))) { + char *prog = strdup(argv[0]); + if (prog == NULL) { perror("strdup()"); } else { fprintf(stderr, "%s [ group-id ]\n", basename(prog)); diff --git a/extensions/pknock/xt_pknock.c b/extensions/pknock/xt_pknock.c index e3d6a90..c71b337 100644 --- a/extensions/pknock/xt_pknock.c +++ b/extensions/pknock/xt_pknock.c @@ -972,7 +972,8 @@ static bool pknock_mt(const struct sk_buff *skb, /* Sets, updates, removes or checks the peer matching status. */ if (info->option & XT_PKNOCK_KNOCKPORT) { - if ((ret = is_allowed(peer))) { + ret = is_allowed(peer); + if (ret != 0) { if (info->option & XT_PKNOCK_CLOSESECRET && (iph->protocol == IPPROTO_UDP || iph->protocol == IPPROTO_UDPLITE)) diff --git a/extensions/xt_CHAOS.c b/extensions/xt_CHAOS.c index eec36d4..69d2082 100644 --- a/extensions/xt_CHAOS.c +++ b/extensions/xt_CHAOS.c @@ -171,7 +171,8 @@ static int __init chaos_tg_init(void) printk(KERN_WARNING PFX "Warning: Could not find or load " "\"DELUDE\" target\n"); - if ((ret = xt_register_target(&chaos_tg_reg)) != 0) { + ret = xt_register_target(&chaos_tg_reg); + if (ret != 0) { printk(KERN_WARNING PFX "xt_register_target returned " "error %d\n", ret); goto out3; diff --git a/extensions/xt_lscan.c b/extensions/xt_lscan.c index 060fe44..6fd6533 100644 --- a/extensions/xt_lscan.c +++ b/extensions/xt_lscan.c @@ -184,7 +184,8 @@ lscan_mt(const struct sk_buff *skb, struct xt_action_param *par) return false; /* Check for invalid packets: -m conntrack --ctstate INVALID */ - if ((ctdata = nf_ct_get(skb, &ctstate)) == NULL) { + ctdata = nf_ct_get(skb, &ctstate); + if (ctdata == NULL) { if (info->match_stealth) return lscan_mt_stealth(tcph); /*