These are global arrays reused several times. When using them msan and
valgrind thus believe they are always initialized, which reduces their
capacity to detect uninitialized values. We can however explicitly tell them
when they are reused, and thus to be considered as uninitialized.
code cleanup: Check all local includes with include-what-you-use
Going through files in src/libespeak-ng/, include-what-you-use removed a
few unnecessary includes and included explanations on why a certain
header should be included. This makes tracking globals and dependencies easier.
Running the codebase through IWYU should be repeated after each major
code restIncludes to standard c library weren't checked to avoid
breaking builds with other platforms.
See https://github.com/include-what-you-use/include-what-you-use
code cleanup: pass voice_t wvoice as a parameter instead of using a global
SetSynth_Klatt() was using wvoice in two ways:
1) global wvoice was used directly
2) global wvoice was also passed in Wavegen_Klatt() as an argument "v"
Now the code only uses the function argument wvoice
Contributes to #68.
Valgrind reports
==20307== Invalid write of size 1
==20307== at 0x4E856FE: Wavegen.part.1 (wavegen.c:880)
==20307== by 0x4E86682: Wavegen (wavegen.c:670)
==20307== by 0x4E86682: Wavegen2 (wavegen.c:1235)
==20307== by 0x4E86682: WavegenFill2 (wavegen.c:1317)
==20307== by 0x4E86CA7: WavegenFill (wavegen.c:1398)
==20307== by 0x4E7093F: Synthesize (speech.c:442)
==20307== by 0x4E712E0: sync_espeak_Synth (speech.c:549)
==20307== by 0x4E8A5C0: process_espeak_command (espeak_command.c:317)
==20307== by 0x4E8B387: say_thread (fifo.c:333)
==20307== by 0x50E85A9: start_thread (pthread_create.c:463)
==20307== by 0x53F5CBE: clone (clone.S:95)
==20307== Address 0xad5e1bd is 0 bytes after a block of size 2,205 alloc'd
==20307== at 0x4C2CABF: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==20307== by 0x4C2EE04: realloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==20307== by 0x4E70CFC: espeak_ng_InitializeOutput (speech.c:286)
==20307== by 0x4E6176E: espeak_Initialize (espeak_api.c:67)
==20307== by 0x10A5D8: initialize_espeak (espeak.c:303)
==20307== by 0x109D1D: main (espeakup.c:201)
==20307==
Indeed, the out_ptr >= out_end test is not enough: it only checks that
one byte can fit the buffer, while klatt and wavegen produce two bytes.
See issue #8, https://github.com/espeak-ng/espeak-ng/issues/8
There might still be some ints that could be changed to boolean.
Possible regressions in fifo.c:
int fifo_is_busy() and int fifo_is_command_enabled() used to return an int. Now they return a boolean. This might cause problems on systems where stdbool true/false is something else than 1/0.