Rock Lee
2012-Oct-23 09:11 UTC
[PATCH] [btrfs-progs] Modify parse_size to remove the strdup/free
Since the function atoi(l) series stop at the first non numeric chars,
So there''s no need to strdup the original s and modify s[len-1] =
''\0''
Signed-off-by: Rock Lee <zimilo@code-trick.com>
---
mkfs.c | 5 +----
1 files changed, 1 insertions(+), 4 deletions(-)
diff --git a/mkfs.c b/mkfs.c
index 47f0c9c..663d73c 100644
--- a/mkfs.c
+++ b/mkfs.c
@@ -61,8 +61,6 @@ static u64 parse_size(char *s)
u64 mult = 1;
u64 ret;
- s = strdup(s);
-
if (len && !isdigit(s[len - 1])) {
c = tolower(s[len - 1]);
switch (c) {
@@ -78,10 +76,9 @@ static u64 parse_size(char *s)
fprintf(stderr, "Unknown size descriptor %c\n", c);
exit(1);
}
- s[len - 1] = ''\0'';
}
+
ret = atol(s) * mult;
- free(s);
return ret;
}
--
1.7.7.6
--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs"
in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
David Sterba
2012-Oct-25 16:46 UTC
Re: [PATCH] [btrfs-progs] Modify parse_size to remove the strdup/free
On Tue, Oct 23, 2012 at 05:11:27PM +0800, Rock Lee wrote:> Since the function atoi(l) series stop at the first non numeric chars, > > So there''s no need to strdup the original s and modify s[len-1] = ''\0''This change is superseded and contained in Goffredos patches which I prefer for inclusion as they do more extensive updates. thanks anyway, david -- To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html