From f608860a7a37c4172b670aee01fa7b47381dfd9d Mon Sep 17 00:00:00 2001 From: "Reece H. Dunn" Date: Tue, 12 Jan 2016 20:44:14 +0000 Subject: [PATCH] Fix the malloc/realloc usage of phon_out_buf in GetTranslatedPhonemeString(dictionary.c) [msvc /analyze] --- src/libespeak-ng/dictionary.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/libespeak-ng/dictionary.c b/src/libespeak-ng/dictionary.c index 08c4ddbe..d622de22 100644 --- a/src/libespeak-ng/dictionary.c +++ b/src/libespeak-ng/dictionary.c @@ -556,7 +556,7 @@ const char *GetTranslatedPhonemeString(int phoneme_mode) if (phon_out_buf == NULL) { phon_out_size = N_PHON_OUT; - if ((phon_out_buf = (char *)realloc(phon_out_buf, phon_out_size)) == NULL) { + if ((phon_out_buf = (char *)malloc(phon_out_size)) == NULL) { phon_out_size = 0; return ""; } @@ -633,10 +633,12 @@ const char *GetTranslatedPhonemeString(int phoneme_mode) if ((phon_out_ix + len) >= phon_out_size) { // enlarge the phoneme buffer phon_out_size = phon_out_ix + len + N_PHON_OUT; - if ((phon_out_buf = (char *)realloc(phon_out_buf, phon_out_size)) == NULL) { + char *new_phon_out_buf = (char *)realloc(phon_out_buf, phon_out_size); + if (new_phon_out_buf == NULL) { phon_out_size = 0; return ""; - } + } else + phon_out_buf = new_phon_out_buf; } phon_buf[len] = 0;