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

* Removed support for phoneme equivalence tables. These were disabled in the * Removed support for phoneme equivalence tables. These were disabled in the
French and German language files. French and German language files.


bug fixes:

* Fix reading stdin buffers larger than 1000.

updated languages: updated languages:


* af (Afrikaans) -- Christo de Klerk * af (Afrikaans) -- Christo de Klerk

+ 8
- 3
src/espeak-ng.c View File

#include <errno.h> #include <errno.h>
#include <getopt.h> #include <getopt.h>
#include <stdbool.h> #include <stdbool.h>
#include <stdint.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
size = strlen(p_text); size = strlen(p_text);
espeak_Synth(p_text, size+1, 0, POS_CHARACTER, 0, synth_flags, NULL, NULL); espeak_Synth(p_text, size+1, 0, POS_CHARACTER, 0, synth_flags, NULL, NULL);
} else if (flag_stdin) { } else if (flag_stdin) {
int max = 1000;
size_t max = 1000;
if ((p_text = (char *)malloc(max)) == NULL) { if ((p_text = (char *)malloc(max)) == NULL) {
espeak_ng_PrintStatusCodeMessage(ENOMEM, stderr, NULL); espeak_ng_PrintStatusCodeMessage(ENOMEM, stderr, NULL);
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
break; break;
p_text[ix++] = (char)c; p_text[ix++] = (char)c;
if (ix >= (max-1)) { 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) { if (new_text == NULL) {
free(p_text); free(p_text);
espeak_ng_PrintStatusCodeMessage(ENOMEM, stderr, NULL); espeak_ng_PrintStatusCodeMessage(ENOMEM, stderr, NULL);
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
p_text = new_text;
} }
} }
if (ix > 0) { if (ix > 0) {

Loading…
Cancel
Save