Fix reading stdin buffers larger than 1000.

Patch by https://github.com/ChliHug.
This commit is contained in:
Reece H. Dunn
2017-02-02 07:22:59 +00:00
parent 98355a0f47
commit 1a0594c62f
2 changed files with 12 additions and 3 deletions
+4
View File
@@ -14,6 +14,10 @@ The espeak-ng project is a fork of the espeak project.
* Removed support for phoneme equivalence tables. These were disabled in the
French and German language files.
bug fixes:
* Fix reading stdin buffers larger than 1000.
updated languages:
* af (Afrikaans) -- Christo de Klerk
+8 -3
View File
@@ -23,6 +23,7 @@
#include <errno.h>
#include <getopt.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@@ -674,7 +675,7 @@ int main(int argc, char **argv)
size = strlen(p_text);
espeak_Synth(p_text, size+1, 0, POS_CHARACTER, 0, synth_flags, NULL, NULL);
} else if (flag_stdin) {
int max = 1000;
size_t max = 1000;
if ((p_text = (char *)malloc(max)) == NULL) {
espeak_ng_PrintStatusCodeMessage(ENOMEM, stderr, NULL);
exit(EXIT_FAILURE);
@@ -697,13 +698,17 @@ int main(int argc, char **argv)
break;
p_text[ix++] = (char)c;
if (ix >= (max-1)) {
max += 1000;
char *new_text = (char *)realloc(p_text, max);
char *new_text = NULL;
if (max <= SIZE_MAX - 1000) {
max += 1000;
new_text = (char *)realloc(p_text, max);
}
if (new_text == NULL) {
free(p_text);
espeak_ng_PrintStatusCodeMessage(ENOMEM, stderr, NULL);
exit(EXIT_FAILURE);
}
p_text = new_text;
}
}
if (ix > 0) {