Browse Source

Fix reading stdin buffers larger than 1000.

Patch by https://github.com/ChliHug.
master
Reece H. Dunn 8 years ago
parent
commit
1a0594c62f
2 changed files with 12 additions and 3 deletions
  1. 4
    0
      CHANGELOG.md
  2. 8
    3
      src/espeak-ng.c

+ 4
- 0
CHANGELOG.md 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
src/espeak-ng.c 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) {

Loading…
Cancel
Save