commit 1f789f4b2321bf0ca20096a24dbe1442b24fad7c
parent 83ff4e8be78d328256b34a9c624654c6bbf45322
Author: z3bra <willyatmailoodotorg>
Date: Mon, 11 Apr 2016 13:42:29 +0200
Allocate input size statically
kudos to pranomostro for this patch.
This avoids a call to malloc() by allocating statically the buffer used
to consume stdin.
Diffstat:
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/human.c b/human.c
@@ -138,7 +138,7 @@ int human(char* s, char fac)
int main (int argc, char **argv)
{
char fac = 0;
- char *argv0, *in;
+ char *argv0, in[LINE_MAX];
/* only switches are use to force factorization */
ARGBEGIN {
@@ -158,7 +158,6 @@ int main (int argc, char **argv)
}
} else {
/* read numbers from stdin if no args, one per line */
- in = malloc(LINE_MAX);
while (fgets(in, LINE_MAX, stdin) != NULL) {
/* overwrite the '\n' */
in[strnlen(in, LINE_MAX) - 1] = 0;