mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] lib/parser: cleanup match_number()
@ 2010-10-08 15:44 Namhyung Kim
  2010-10-08 19:13 ` Andrew Morton
  0 siblings, 1 reply; 2+ messages in thread
From: Namhyung Kim @ 2010-10-08 15:44 UTC (permalink / raw)
  To: Andrew Morton; +Cc: linux-kernel

Use new variable 'len' to make code more readable.

Signed-off-by: Namhyung Kim <namhyung@gmail.com>
---
 lib/parser.c |    7 ++++---
 1 files changed, 4 insertions(+), 3 deletions(-)

diff --git a/lib/parser.c b/lib/parser.c
index fb34977..6e89eca 100644
--- a/lib/parser.c
+++ b/lib/parser.c
@@ -128,12 +128,13 @@ static int match_number(substring_t *s, int *result, int base)
 	char *endp;
 	char *buf;
 	int ret;
+	size_t len = s->to - s->from;
 
-	buf = kmalloc(s->to - s->from + 1, GFP_KERNEL);
+	buf = kmalloc(len + 1, GFP_KERNEL);
 	if (!buf)
 		return -ENOMEM;
-	memcpy(buf, s->from, s->to - s->from);
-	buf[s->to - s->from] = '\0';
+	memcpy(buf, s->from, len);
+	buf[len] = '\0';
 	*result = simple_strtol(buf, &endp, base);
 	ret = 0;
 	if (endp == buf)
-- 
1.7.0.4


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2010-10-08 19:13 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-10-08 15:44 [PATCH] lib/parser: cleanup match_number() Namhyung Kim
2010-10-08 19:13 ` Andrew Morton

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

Powered by JetHome