Skip to contentSkip to conversation

Fix wrong bracket placing

PATCH In review Thomas Jarosch 2 participants 2 messages Dec 27, 2012 – Jan 9, 2013

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Fix wrong bracket placing

cppcheck (vaguely) reported:
[lib/parse.c:448]: (style) Suspicious condition (assignment + comparison); Clarify expression with parentheses.

---
 lib/parse.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
lib/parse.c +2 -2
index 550048c..d06e9cd 100644
@@ -445,8 +445,8 @@ ipset_parse_proto(struct ipset_session *session,
 		uint8_t protonum;
 		int err;
 
-		if (!((err = string_to_u8(session, str, &protonum) == 0) &&
-		      (protoent = getprotobynumber(protonum)) != NULL))
+		if (!((err = string_to_u8(session, str, &protonum)) == 0) &&
+		      (protoent = getprotobynumber(protonum)) != NULL)
 			return syntax_err("cannot parse '%s' "
 					  "as a protocol", str);
 	}
Signature · 1 line
1.7.11.7
#1 lore raw

Hi Thomas,

Quoted 26 lines · Thomas Jarosch

cppcheck (vaguely) reported:
[lib/parse.c:448]: (style) Suspicious condition (assignment + comparison); Clarify expression with parentheses.

---
 lib/parse.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
lib/parse.c +2 -2
index 550048c..d06e9cd 100644
@@ -445,8 +445,8 @@ ipset_parse_proto(struct ipset_session *session,
 		uint8_t protonum;
 		int err;
 
-		if (!((err = string_to_u8(session, str, &protonum) == 0) &&
-		      (protoent = getprotobynumber(protonum)) != NULL))
+		if (!((err = string_to_u8(session, str, &protonum)) == 0) &&
+		      (protoent = getprotobynumber(protonum)) != NULL)
 			return syntax_err("cannot parse '%s' "
 					  "as a protocol", str);
 	}
Signature · 1 line
1.7.11.7

Your patch fixes the warning but modifies the condition. So I simplified the condition and am going to apply the next patch:

lib/parse.c +3 -4
index 550048c..951d2f3 100644
@@ -442,11 +442,10 @@ ipset_parse_proto(struct ipset_session *session,
        protoent = getprotobyname(strcasecmp(str, "icmpv6") == 0
                                  ? "ipv6-icmp" : str);
        if (protoent == NULL) {
-               uint8_t protonum;
-               int err;
+               uint8_t protonum = 0;
 
-               if (!((err = string_to_u8(session, str, &protonum) == 0) &&
-                     (protoent = getprotobynumber(protonum)) != NULL))
+               if (string_to_u8(session, str, &protonum) ||
+                   (protoent = getprotobynumber(protonum)) == NULL)
                        return syntax_err("cannot parse '%s' "
                                          "as a protocol", str);
        }

Best regards,
Jozsef
-
E-mail : [email protected], [email protected] PGP key : http://www.kfki.hu/~kadlec/pgp_public_key.txt
Address : Wigner Research Centre for Physics, Hungarian Academy of Sciences

          H-1525 Budapest 114, POB. 49, Hungary