Skip to contentSkip to conversation

src: Merge assignment with return

PATCH In review Harsha Sharma 2 participants 2 messages Oct 6, 2017 – Oct 9, 2017 netfilter

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 src: Merge assignment with return

Merge assignment with return statement to directly return the value. Done using following coccinelle semantic patch

@@
local idexpression ret;
expression e;
@@

-ret =
+return

     e;

-return ret;

---
 src/mini-gmp.c  | 3 +--
 src/statement.c | 5 +----
 2 files changed, 2 insertions(+), 6 deletions(-)
src/mini-gmp.c +1 -2
index acbe1be..0579c46 100644
@@ -1297,8 +1297,7 @@ mpn_set_str_bits (mp_ptr rp, const unsigned char *sp, size_t sn,
 	    }
 	}
     }
-  rn = mpn_normalized_size (rp, rn);
-  return rn;
+  return mpn_normalized_size(rp, rn);
 }
 
 static mp_size_t
src/statement.c +1 -4
index 6166863..168f944 100644
@@ -208,10 +208,7 @@ static const struct stmt_ops objref_stmt_ops = {
 
 struct stmt *objref_stmt_alloc(const struct location *loc)
 {
-	struct stmt *stmt;
-
-	stmt = stmt_alloc(loc, &objref_stmt_ops);
-	return stmt;
+	return stmt_alloc(loc, &objref_stmt_ops);
 }
 
 static const char *syslog_level[LOG_DEBUG + 1] = {

--
2.11.0

#1 lore raw

Hi Harsha,

Quoted 24 lines · Harsha Sharma

Merge assignment with return statement to directly return the value. Done using following coccinelle semantic patch

@@
local idexpression ret;
expression e;
@@

(quoted diff) +1 -2
-ret =
+return
     e;
-return ret;
---
 src/mini-gmp.c  | 3 +--
 src/statement.c | 5 +----
 2 files changed, 2 insertions(+), 6 deletions(-)
src/mini-gmp.c +0 -0
index acbe1be..0579c46 100644

src/mini-gmp.c mpn_set_str_bits (mp_ptr rp, const unsigned char *sp, size_t sn, · line 1300

Quoted 6 lines
src/mini-gmp.c +1 -2
@@ -1297,8 +1297,7 @@ mpn_set_str_bits (mp_ptr rp, const unsigned char *sp, size_t sn,
 	    }
 	}
     }
-  rn = mpn_normalized_size (rp, rn);
-  return rn;
+  return mpn_normalized_size(rp, rn);

mini-gmp.c has been extracted from libgmp sources [1], so either you submit this chunk to them, or you leave this part as is. I would like we just cache a copy of the mini-gmp.c original file.

Probably you can just check if latest stable release of libgmp contains updates for mini-gmp.{c,h} and send us a patch to get in sync with them.

Thanks.

[1] https://gmplib.org/repo/gmp/file/tip/mini-gmp