summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJ08nY2017-04-05 13:46:58 +0200
committerJ08nY2017-04-05 13:54:12 +0200
commit605049a142aff150d36711c66935c80875e84e36 (patch)
treed74e11714ac8db8b268c9d95d37ddf395c8c5f1e
parent9ad9770e8f16d654cfef2fffa2776a186f7c4b3b (diff)
downloadecgen-605049a142aff150d36711c66935c80875e84e36.tar.gz
ecgen-605049a142aff150d36711c66935c80875e84e36.tar.zst
ecgen-605049a142aff150d36711c66935c80875e84e36.zip
Fix input when EOF reached
-rw-r--r--src/io/input.c10
1 files changed, 8 insertions, 2 deletions
diff --git a/src/io/input.c b/src/io/input.c
index db81450..49910f1 100644
--- a/src/io/input.c
+++ b/src/io/input.c
@@ -21,14 +21,13 @@ static GEN input_i(const char *prompt, long bits) {
if (len <= 0) {
return gen_m1;
}
- if (len == 1) {
+ if (len == 1 && !feof(in)) {
free(line);
return gen_m1;
}
for (size_t i = 0, j = 0; (line[j] = line[i]); j += !isspace(line[i++]))
;
- pari_sp ltop = avma;
if (len <= 3 || (line[0] != '0' && (line[1] != 'x' || line[1] != 'X'))) {
char *new_line = realloc(line, (size_t)(len + 2));
if (!new_line) {
@@ -38,8 +37,15 @@ static GEN input_i(const char *prompt, long bits) {
memmove(new_line + 2, new_line, (size_t)len);
new_line[0] = '0';
new_line[1] = 'x';
+ if (!feof(in)) {
+ new_line[len + 1] = 0;
+ } else {
+ new_line[len + 2] = 0;
+ }
line = new_line;
}
+
+ pari_sp ltop = avma;
GEN in = strtoi(line);
free(line);