summaryrefslogtreecommitdiff
path: root/tests/test_schema.c
diff options
context:
space:
mode:
Diffstat (limited to 'tests/test_schema.c')
-rw-r--r--tests/test_schema.c12
1 files changed, 8 insertions, 4 deletions
diff --git a/tests/test_schema.c b/tests/test_schema.c
index 4f075dae8d68..39eb7f399125 100644
--- a/tests/test_schema.c
+++ b/tests/test_schema.c
@@ -40,20 +40,24 @@ read_stdin (char **buf)
p = *buf;
remain = size;
- while ((ret = read (STDIN_FILENO, p, remain)) > 0) {
+ while ((ret = read (STDIN_FILENO, p, remain - 1)) > 0) {
remain -= ret;
p += ret;
- if (remain == 0) {
+
+ if (remain <= 1) {
*buf = realloc (*buf, size * 2);
if (*buf == NULL) {
return -1;
}
- p = *buf + size;
- remain = size;
+
+ p = *buf + size - 1;
+ remain = size + 1;
size *= 2;
}
}
+ *p = '\0';
+
return ret;
}