From 24e1eaa0ccf8dc498d0b12b61b102483d8793bb0 Mon Sep 17 00:00:00 2001 From: Samuel Thibault Date: Thu, 9 Jun 2022 09:48:12 +0200 Subject: [PATCH] Mark static arrays undefined when they are reused So valgrind can potentially catch e.g. missing \0. --- src/libespeak-ng/compiledict.c | 2 ++ src/libespeak-ng/dictionary.c | 2 ++ src/libespeak-ng/readclause.c | 8 +++++++- src/libespeak-ng/ssml.c | 3 +++ src/libespeak-ng/synth_mbrola.c | 2 ++ src/libespeak-ng/synthdata.c | 2 ++ src/libespeak-ng/synthesize.c | 5 +++++ src/libespeak-ng/translate.c | 2 ++ src/libespeak-ng/voices.c | 6 ++++++ 9 files changed, 31 insertions(+), 1 deletion(-) diff --git a/src/libespeak-ng/compiledict.c b/src/libespeak-ng/compiledict.c index 6e12d571..dcb87475 100644 --- a/src/libespeak-ng/compiledict.c +++ b/src/libespeak-ng/compiledict.c @@ -223,6 +223,8 @@ char *DecodeRule(const char *group_chars, int group_length, char *rule, int cont char suffix[20]; static char output[80]; + MAKE_MEM_UNDEFINED(&output, sizeof(output)); + static const char symbols[] = { ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '&', '%', '+', '#', 'S', 'D', 'Z', 'A', 'L', '!', diff --git a/src/libespeak-ng/dictionary.c b/src/libespeak-ng/dictionary.c index 51ce500a..a92d4771 100644 --- a/src/libespeak-ng/dictionary.c +++ b/src/libespeak-ng/dictionary.c @@ -2875,6 +2875,8 @@ int LookupDictList(Translator *tr, char **wordptr, char *ph_out, unsigned int *f char word[N_WORD_BYTES]; static char word_replacement[N_WORD_BYTES]; + MAKE_MEM_UNDEFINED(&word_replacement, sizeof(word_replacement)); + length = 0; word2 = word1 = *wordptr; diff --git a/src/libespeak-ng/readclause.c b/src/libespeak-ng/readclause.c index e8dbc57d..1c645a45 100644 --- a/src/libespeak-ng/readclause.c +++ b/src/libespeak-ng/readclause.c @@ -187,6 +187,8 @@ const char *WordToString2(unsigned int word) static char buf[5]; char *p; + MAKE_MEM_UNDEFINED(&buf, sizeof(buf)); + p = buf; for (ix = 3; ix >= 0; ix--) { if ((*p = word >> (ix*8)) != 0) @@ -227,6 +229,8 @@ static const char *LookupCharName(Translator *tr, int c, int only) char *string; static char buf[60]; + MAKE_MEM_UNDEFINED(&buf, sizeof(buf)); + buf[0] = 0; flags[0] = 0; flags[1] = 0; @@ -541,8 +545,10 @@ int ReadClause(Translator *tr, char *buf, short *charix, int *charix_top, int n_ c1 = c2; if (ungot_string_ix >= 0) { - if (ungot_string[ungot_string_ix] == 0) + if (ungot_string[ungot_string_ix] == 0) { + MAKE_MEM_UNDEFINED(&ungot_string, sizeof(ungot_string)); ungot_string_ix = -1; + } } if ((ungot_string_ix == 0) && (ungot_char2 == 0)) diff --git a/src/libespeak-ng/ssml.c b/src/libespeak-ng/ssml.c index ec49b204..dd710aaa 100644 --- a/src/libespeak-ng/ssml.c +++ b/src/libespeak-ng/ssml.c @@ -47,6 +47,7 @@ #include "synthesize.h" // for SPEED_FACTORS, speed #include "translate.h" // for CTRL_EMBEDDED, IsDigit09, utf8_out #include "voice.h" // for SelectVoice, SelectVoiceByName +#include "speech.h" // for MAKE_MEM_UNDEFINED static const MNEM_TAB ssmltags[] = { { "speak", SSML_SPEAK }, @@ -214,6 +215,8 @@ static const char *VoiceFromStack(SSML_STACK *ssml_stack, int n_ssml_stack, espe char language[40]; char buf[80]; + MAKE_MEM_UNDEFINED(&voice_name, sizeof(voice_name)); + strcpy(voice_name, ssml_stack[0].voice_name); strcpy(language, ssml_stack[0].language); voice_select.age = ssml_stack[0].voice_age; diff --git a/src/libespeak-ng/synth_mbrola.c b/src/libespeak-ng/synth_mbrola.c index 151f38ea..68e1f5e2 100644 --- a/src/libespeak-ng/synth_mbrola.c +++ b/src/libespeak-ng/synth_mbrola.c @@ -253,6 +253,8 @@ static char *WritePitch(int env, int pitch1, int pitch2, int split, int final) char buf[50]; static char output[50]; + MAKE_MEM_UNDEFINED(&output, sizeof(output)); + output[0] = 0; pitch_env = envelope_data[env]; diff --git a/src/libespeak-ng/synthdata.c b/src/libespeak-ng/synthdata.c index 9db1b61b..272fec74 100644 --- a/src/libespeak-ng/synthdata.c +++ b/src/libespeak-ng/synthdata.c @@ -208,6 +208,8 @@ frameref_t *LookupSpect(PHONEME_TAB *this_ph, int which, FMT_PARAMS *fmt_params, frame_t *frame; static frameref_t frames_buf[N_SEQ_FRAMES]; + MAKE_MEM_UNDEFINED(&frames_buf, sizeof(frames_buf)); + seq = (SPECT_SEQ *)(&phondata_ptr[fmt_params->fmt_addr]); seqk = (SPECT_SEQK *)seq; nf = seq->n_frames; diff --git a/src/libespeak-ng/synthesize.c b/src/libespeak-ng/synthesize.c index 29789746..5414871c 100644 --- a/src/libespeak-ng/synthesize.c +++ b/src/libespeak-ng/synthesize.c @@ -43,6 +43,7 @@ #include "translate.h" // for translator, LANGUAGE_OPTIONS, Trans... #include "voice.h" // for voice_t, voice, LoadVoiceVariant #include "wavegen.h" // for WcmdqInc, WcmdqFree, WcmdqStop +#include "speech.h" // for MAKE_MEM_UNDEFINED static void SmoothSpect(void); @@ -77,6 +78,8 @@ const char *WordToString(unsigned int word) int ix; static char buf[5]; + MAKE_MEM_UNDEFINED(&buf, sizeof(buf)); + for (ix = 0; ix < 4; ix++) buf[ix] = word >> (ix*8); buf[4] = 0; @@ -388,6 +391,8 @@ static frame_t *AllocFrame() ix++; if (ix >= N_FRAME_POOL) ix = 0; + + MAKE_MEM_UNDEFINED(&frame_pool[ix], sizeof(frame_pool[ix])); return &frame_pool[ix]; } diff --git a/src/libespeak-ng/translate.c b/src/libespeak-ng/translate.c index 0db80fd4..6e1d5cab 100644 --- a/src/libespeak-ng/translate.c +++ b/src/libespeak-ng/translate.c @@ -1988,6 +1988,8 @@ void TranslateClause(Translator *tr, int *tone_out, char **voice_change) if (tr == NULL) return; + MAKE_MEM_UNDEFINED(&voice_change_name, sizeof(voice_change_name)); + embedded_ix = 0; embedded_read = 0; pre_pause = 0; diff --git a/src/libespeak-ng/voices.c b/src/libespeak-ng/voices.c index 60d0794d..c96e326c 100644 --- a/src/libespeak-ng/voices.c +++ b/src/libespeak-ng/voices.c @@ -982,6 +982,7 @@ static char *ExtractVoiceVariantName(char *vname, int variant_num, int add_dir) static char variant_name[40]; char variant_prefix[5]; + MAKE_MEM_UNDEFINED(&variant_name, sizeof(variant_name)); variant_name[0] = 0; sprintf(variant_prefix, "!v%c", PATHSEP); if (add_dir == 0) @@ -1319,6 +1320,9 @@ char const *SelectVoice(espeak_VOICE *voice_select, int *found) static espeak_VOICE voice_variants[N_VOICE_VARIANTS]; static char voice_id[50]; + MAKE_MEM_UNDEFINED(&voice_variants, sizeof(voice_variants)); + MAKE_MEM_UNDEFINED(&voice_id, sizeof(voice_id)); + *found = 1; memcpy(&voice_select2, voice_select, sizeof(voice_select2)); @@ -1329,6 +1333,8 @@ char const *SelectVoice(espeak_VOICE *voice_select, int *found) // no language is specified. Get language from the named voice static char buf[60]; + MAKE_MEM_UNDEFINED(&buf, sizeof(buf)); + if (voice_select2.name == NULL) { if ((voice_select2.name = voice_select2.identifier) == NULL) voice_select2.name = ESPEAKNG_DEFAULT_VOICE;