tAllocate input size statically - human - print numbers in human-readable format
(HTM) git clone git://z3bra.org/human
(DIR) Log
(DIR) Files
(DIR) Refs
(DIR) README
(DIR) LICENSE
---
(DIR) commit 1f789f4b2321bf0ca20096a24dbe1442b24fad7c
(DIR) parent 83ff4e8be78d328256b34a9c624654c6bbf45322
(HTM) 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
tto consume stdin.
Diffstat:
M human.c | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
---
(DIR) diff --git a/human.c b/human.c
t@@ -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 {
t@@ -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;