From eb777add58308e95b07b8a67f63fb98d58ae8d7f Mon Sep 17 00:00:00 2001 From: Patrick Siegl Date: Wed, 27 Mar 2019 21:35:29 +0100 Subject: [PATCH] Support any value from /proc instead of relying on buf.-size --- software/writeentropy.c | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/software/writeentropy.c b/software/writeentropy.c index 33c832a..f7f6411 100644 --- a/software/writeentropy.c +++ b/software/writeentropy.c @@ -26,15 +26,13 @@ static uint32_t readNumberFromFile(char *fileName) { fprintf(stderr, "Unable to open %s\n", fileName); exit(1); } - char buf[42u]; - uint32_t i = 0u; - int c = getc(file); - while(c != EOF) { - buf[i++] = c; - c = getc(file); + uint32_t value = 0u; + char c; + while( (c = getc(file)) != EOF + && '0' <= c && c <= '9' ) { + value *= 10; + value += c - '0'; } - buf[i] = '\0'; - uint32_t value = atoi(buf); fclose(file); return value; }