Commit Graph
1861 Commits
Author SHA1 Message Date
Valdis Vitolins 3572290fbf Merge pull request #1121 2022-03-20 22:19:45 +02:00
Valdis Vitolins cfec1551a0 Merge pull request #1119 2022-03-20 22:19:03 +02:00
Samuel Thibault b457d6f58e Fix uninitialized fields
The memory sanitizer would complain:

==4157154==WARNING: MemorySanitizer: use-of-uninitialized-value
    #0 0x7fc191d0a85b in TranslateWord3 /home/samy/brl/speech/espeak-ng-git/src/libespeak-ng/translate.c:1065:7
    #1 0x7fc191d02916 in TranslateWord /home/samy/brl/speech/espeak-ng-git/src/libespeak-ng/translate.c:1100:14
    #2 0x7fc191d1b324 in TranslateWord2 /home/samy/brl/speech/espeak-ng-git/src/libespeak-ng/translate.c:1448:15
    #3 0x7fc191d14ebc in TranslateClause /home/samy/brl/speech/espeak-ng-git/src/libespeak-ng/translate.c:2623:17
    #4 0x7fc191cfbc9b in SpeakNextClause /home/samy/brl/speech/espeak-ng-git/src/libespeak-ng/synthesize.c:1569:2
    #5 0x7fc191cd52fc in Synthesize /home/samy/brl/speech/espeak-ng-git/src/libespeak-ng/speech.c:457:2
    #6 0x7fc191cd6d7c in sync_espeak_Synth /home/samy/brl/speech/espeak-ng-git/src/libespeak-ng/speech.c:570:29
    #7 0x7fc191cd6d7c in espeak_ng_Synthesize /home/samy/brl/speech/espeak-ng-git/src/libespeak-ng/speech.c:678:10
    #8 0x7fc191ca0340 in espeak_Synth /home/samy/brl/speech/espeak-ng-git/src/libespeak-ng/espeak_api.c:90:32
    #9 0x4a4381 in main /home/samy/brl/speech/espeak-ng-git/src/espeak-ng.c:691:3
    #10 0x7fc19168b7fc in __libc_start_main csu/../csu/libc-start.c:332:16
    #11 0x421449 in _start (/home/samy/ens/projet/1/speech/espeak-ng-git/src/.libs/espeak-ng+0x421449)

  Uninitialized value was created by a heap allocation
    #0 0x45000d in malloc (/home/samy/ens/projet/1/speech/espeak-ng-git/src/.libs/espeak-ng+0x45000d)
    #1 0x7fc191d1ca29 in NewTranslator /home/samy/brl/speech/espeak-ng-git/src/libespeak-ng/tr_languages.c:242:26
    #2 0x7fc191d1ca29 in SelectTranslator /home/samy/brl/speech/espeak-ng-git/src/libespeak-ng/tr_languages.c:482:7

(and similar for expect_verb_sn expect_noun, expect_past,
clause_upper_count, clause_lower_count)

Indeed TranslateWord3 doesn't always initialize these fields. Better
just initialize them directly from the Translator creation.
2022-03-20 00:27:44 +01:00
Samuel Thibault 9cee174426 sPlayer: fix accessing bw
The bw array is 0-based, not 1-based.
2022-03-19 10:55:06 +01:00
Samuel Thibault 261954b4bd Fix deleting SpeechWaveGenerator
Similarly to dab5457620 "Fix deleting FrameManagerImpl*", we need a
virtual destructor. clang was complaining about it:

src/speechPlayer/src/speechPlayer.cpp:52:2: warning: delete called on 'SpeechWaveGenerator' that is abstract but has non-virtual destructor [-Wdelete-abstract-non-virtual-dtor]
        delete playerHandleInfo->waveGenerator;
        ^
2022-03-19 10:50:28 +01:00
Valdis Vitolins 59718c2895 Merge pull request #1114 2022-03-16 21:35:32 +02:00
Valdis Vitolins e001908192 Merge pull request #1112 2022-03-16 21:34:26 +02:00
Valdis Vitolins 149c6b3d0d Merge pull request #1111 2022-03-16 21:34:08 +02:00
Valdis Vitolins d0bbf97edb Merge pull request #1109 2022-03-16 21:31:33 +02:00
Valdis Vitolins 45eb1aa3af Merge pull request #1107 2022-03-16 21:31:15 +02:00
Valdis Vitolins d953c2aa96 Merge pull request #1106 2022-03-16 21:31:02 +02:00
Valdis Vitolins d2ff410540 Merge pull request #1104 2022-03-16 21:30:33 +02:00
Valdis Vitolins 4125cef425 Merge pull request #1103 2022-03-16 21:30:16 +02:00
Valdis Vitolins 9368392743 Merge pull request #1102 2022-03-16 21:29:59 +02:00
Valdis Vitolins d1adedf650 Merge pull request #1095 2022-03-16 21:24:45 +02:00
Samuel Thibault 15091d82be fifo: Protect setting my_terminate_is_required
We need to keep the mutex around setting it, to make sure that the
visibility of setting it to true doesn't get delayed, notably not after
the signal (which could entail that the signal becomes useless, leading
to a hang).
2022-03-16 00:22:58 +01:00
Samuel Thibault dab5457620 Fix deleting FrameManagerImpl*
delete playerHandleInfo->frameManager wasn't actually calling
FrameManagerImpl~, because playerHandleInfo->frameManager is only a
FrameManager, which didn't have a destructor, and nothing was saying that
it's actually a FrameManagerImpl behind. Adding a virtual destructor
fixes that.
2022-03-15 23:26:20 +01:00
Samuel Thibault 51af5a4155 Add KlattFiniSP
speechPlayer_terminate was never called without calling
speechPlayer_initialize right after, so there would always be a FrameManager
laying behind.
2022-03-15 21:27:44 +01:00
Samuel Thibault 34a12c83b4 IsLetterGroup: Do not blindly walk back in the word
strlen(p) may be arbitrarily long, that would underflow the word, for
instance:

testing fr Latn
=================================================================
==3741805==ERROR: AddressSanitizer: stack-buffer-overflow on address 0x7ffd733c1329 at pc 0x7ff5ffbad2de bp 0x7ffd733bf310 sp 0x7ffd733bf308
READ of size 1 at 0x7ffd733c1329 thread T0
    #0 0x7ff5ffbad2dd in IsLetterGroup src/libespeak-ng/dictionary.c:714
    #1 0x7ff5ffbbe425 in MatchRule src/libespeak-ng/dictionary.c:1979
    #2 0x7ff5ffbc09e9 in TranslateRules src/libespeak-ng/dictionary.c:2301
    #3 0x7ff5ffc26656 in TranslateWord3 src/libespeak-ng/translate.c:733
    #4 0x7ff5ffc2a10b in TranslateWord src/libespeak-ng/translate.c:1100
    #5 0x7ff5ffc2bef2 in TranslateWord2 src/libespeak-ng/translate.c:1361
    #6 0x7ff5ffc374e2 in TranslateClause src/libespeak-ng/translate.c:2623
    #7 0x7ff5ffc1d010 in SpeakNextClause src/libespeak-ng/synthesize.c:1569
    #8 0x7ff5ffbfbd46 in Synthesize src/libespeak-ng/speech.c:492
    #9 0x7ff5ffbfd52a in sync_espeak_Synth src/libespeak-ng/speech.c:570
    #10 0x7ff5ffbfdd1f in espeak_ng_Synthesize src/libespeak-ng/speech.c:678
    #11 0x7ff5ffbc72fd in espeak_Synth src/libespeak-ng/espeak_api.c:90
    #12 0x5627511a3137 in main src/espeak-ng.c:691
    #13 0x7ff5fee557fc in __libc_start_main ../csu/libc-start.c:332
    #14 0x5627511a0569 in _start (/home/samy/ens/projet/1/speech/espeak-ng-git/src/.libs/espeak-ng+0x6569)

Address 0x7ffd733c1329 is located in stack of thread T0 at offset 1177 in frame
    #0 0x7ff5ffc2f760 in TranslateClause src/libespeak-ng/translate.c:1941

  This frame has 16 object(s):
    [48, 52) 'cc' (line 1944)
    [64, 68) 'source_index' (line 1945)
    [80, 84) 'prev_in' (line 1948)
    [96, 100) 'prev_out' (line 1949)
    [112, 116) 'next_in' (line 1952)
    [128, 132) 'char_inserted' (line 1954)
    [144, 148) 'word_flags' (line 1963)
    [160, 164) 'charix_top' (line 1975)
    [176, 180) 'tone' (line 1985)
    [192, 196) 'next2_in' (line 2294)
    [208, 212) 'c_temp' (line 2518)
    [224, 374) 'number_buf' (line 2522)
    [448, 1048) 'num_wtab' (line 2523)
    [1184, 1984) 'sbuf' (line 1982) <== Memory access at offset 1177 underflows this variable
    [2112, 3720) 'charix' (line 1977)
    [3856, 7456) 'words' (line 1978)

sbuf is however properly '\0'-header, so we can make IsLetterGroup
carefully walk back in the word and issue a mismatch if it walks back
too much.

Fixes #1108
2022-03-15 18:17:42 +01:00
Samuel Thibault 7f1222c6ad Properly maintain margin in ph_list2
TranslateWord2 uses phonemes in ph_list2. Apart from the breakable loops, it
may statically require up to 7 phonemes. Then TranslateClause always
uses 2 phonemes. We thus have to keep these margins along the loops to
avoid any overflow.

Fixes #1073 #1095
2022-03-15 15:47:09 +01:00
Samuel Thibault 005a590786 addPluralSuffixes: Use space as heading separator
Otherwise asan reports this during make check:

testing en ibm mit ibms mits IBM MIT APH CES ITX IBMs MIT's APHs CES's ITXs
==3733154==ERROR: AddressSanitizer: stack-buffer-overflow on address 0x7ffe420233ef at pc 0x7f2e8a30aef1 bp 0x7ffe42022c80 sp 0x7ffe42022c78
READ of size 1 at 0x7ffe420233ef thread T0
    #0 0x7f2e8a30aef0 in utf8_in2 src/libespeak-ng/translate.c:281
    #1 0x7f2e8a2a6db1 in MatchRule src/libespeak-ng/dictionary.c:2058
    #2 0x7f2e8a2a89e9 in TranslateRules src/libespeak-ng/dictionary.c:2301
    #3 0x7f2e8a30cc77 in addPluralSuffixes src/libespeak-ng/translate.c:393
    #4 0x7f2e8a30e2c9 in TranslateWord3 src/libespeak-ng/translate.c:684
    #5 0x7f2e8a31210b in TranslateWord src/libespeak-ng/translate.c:1100
    #6 0x7f2e8a313ef2 in TranslateWord2 src/libespeak-ng/translate.c:1361
    #7 0x7f2e8a31f4e2 in TranslateClause src/libespeak-ng/translate.c:2623
    #8 0x7f2e8a305010 in SpeakNextClause src/libespeak-ng/synthesize.c:1569
    #9 0x7f2e8a2e390e in Synthesize src/libespeak-ng/speech.c:457
    #10 0x7f2e8a2e552a in sync_espeak_Synth src/libespeak-ng/speech.c:570
    #11 0x7f2e8a2e5d1f in espeak_ng_Synthesize src/libespeak-ng/speech.c:678
    #12 0x7f2e8a2af2fd in espeak_Synth src/libespeak-ng/espeak_api.c:90
    #13 0x5618104c9137 in main src/espeak-ng.c:691
    #14 0x7f2e8953d7fc in __libc_start_main ../csu/libc-start.c:332
    #15 0x5618104c6569 in _start (/home/samy/ens/projet/1/speech/espeak-ng-git/src/.libs/espeak-ng+0x6569)

Address 0x7ffe420233ef is located in stack of thread T0 at offset 47 in frame
    #0 0x7f2e8a30cb3b in addPluralSuffixes src/libespeak-ng/translate.c:380

  This frame has 3 object(s):
    [32, 36) 'word_zz' (line 381)
    [48, 52) 'word_iz' (line 382) <== Memory access at offset 47 underflows this variable
    [64, 68) 'word_ss' (line 383)

and indeed, RULE_NOVOWELS keeps looking back until it finds a spacing
character, so we have to provide it with one.
2022-03-15 03:40:52 +01:00
Samuel Thibault 0119efec28 MatchRule: Do not go back before the pre-ptr
pre_ptr is already one byte before the current letter, so we do not want
to subtract 1 again. Otherwise this would for instance underflow word_iz
of addPluralSuffixes.
2022-03-15 03:39:12 +01:00
Samuel Thibault 4dd1e04d8a Make polint use 0-based indexing
This avoids having to make LoadEnvelope2 pass &env_x[-1], which is very
strongly frowned upon by sanitizers such as usan.
2022-03-15 03:03:41 +01:00
Samuel Thibault eb512f66e1 Add more heading margin in TranslateClause
Valgrind reports:

==3642987== Conditional jump or move depends on uninitialised value(s)
==3642987==    at 0x491F268: TranslateNumber_1 (numbers.c:1785)
==3642987==    by 0x4923C35: TranslateNumber (numbers.c:2080)
==3642987==    by 0x49556DC: TranslateWord3 (translate.c:644)
==3642987==    by 0x4957FCE: TranslateWord (translate.c:1100)
==3642987==    by 0x4959344: TranslateWord2 (translate.c:1361)
==3642987==    by 0x496116E: TranslateClause (translate.c:2613)
==3642987==    by 0x494FF7A: SpeakNextClause (synthesize.c:1569)
==3642987==    by 0x4939B9D: Synthesize (speech.c:457)
==3642987==    by 0x493AE6A: sync_espeak_Synth (speech.c:570)
==3642987==    by 0x493B286: espeak_ng_Synthesize (speech.c:678)
==3642987==    by 0x4916925: espeak_Synth (espeak_api.c:90)
==3642987==    by 0x10CF5D: main (espeak-ng.c:691)
==3642987==  Uninitialised value was created by a stack allocation
==3642987==    at 0x495BD9F: TranslateClause (translate.c:1941)

Indeed, TranslateNumber_1 looks back up to three bytes before, with
IsDigit09(word[-3])), so we have to increase the heading margin to three
spaces.
2022-03-15 02:35:11 +01:00
Samuel Thibault f6d3c947de Fix uninitialized phonemes_repeat array
valgrind reports

==3632264== Conditional jump or move depends on uninitialised value(s)
==3632264==    at 0x4846688: strcmp (vg_replace_strmem.c:924)
==3632264==    by 0x490EC12: LookupDictList (dictionary.c:2889)
==3632264==    by 0x49554C6: TranslateWord3 (translate.c:588)
==3632264==    by 0x4957FCE: TranslateWord (translate.c:1100)
==3632264==    by 0x4959344: TranslateWord2 (translate.c:1361)
==3632264==    by 0x4961390: TranslateClause (translate.c:2621)
==3632264==    by 0x494FF7A: SpeakNextClause (synthesize.c:1569)
==3632264==    by 0x4939B9D: Synthesize (speech.c:457)
==3632264==    by 0x493AE6A: sync_espeak_Synth (speech.c:570)
==3632264==    by 0x493B286: espeak_ng_Synthesize (speech.c:678)
==3632264==    by 0x4916925: espeak_Synth (espeak_api.c:90)
==3632264==    by 0x10CF5D: main (espeak-ng.c:691)

And indeed tr->phonemes_repeat may not necessarily be initialized.
2022-03-15 02:25:45 +01:00
Samuel Thibault b106fd5c91 Avoid shifting integers
shifting negative integers has an undefined behavior, so we have to
avoid it entirely. Using * 256 and / 256 provides the expected behavior
while being correctly optimized by the compiler.
2022-03-11 18:23:19 +01:00
Jakub Kulík 4b090ad8a1 Add support for Solaris 2022-03-01 11:56:48 +01:00
Samuel Thibault 977bff9a06 event_notify: Remove spurious 50ms delay
event_notify currently introduces an arbitrary 50ms delay between speech
requests. This is usually unnoticed since it's small. But when
cancelling a long series of events, they add up to potentially seconds
of delays, while the user was precisely requesting to just cancel
everything as fast as possible.

This 50ms delay was probably meant to work around some issues elsewhere.
If they are still there, they should be fixed, not worked around.
2022-02-13 02:54:00 +01:00
Ulrich Müller c7eb52fe14 src/libespeak-ng: Replace ieee80.c by a free software implementation
https://github.com/espeak-ng/espeak-ng/issues/1072

Signed-off-by: Ulrich Müller <ulm@gentoo.org>
2022-02-10 17:53:19 +01:00
Juho Hiltunen 0577cd90a6 code cleanup: remove unused variable markers_used 2022-01-03 21:14:18 +02:00
Juho Hiltunen dbcfa71f92 code cleanup: remove unused n_envelopes, N_ENVELOPES, envelope_paths and
envelope_dat.

envelope_dat and envelope_paths were only set but never used.
LoadEnvelope() and LoadEnvelope2() no longer need fname as an argument.
2022-01-02 21:21:35 +02:00
Juho Hiltunen 8fc69e2999 code cleanup: remove unnecessary temporary variable yy 2022-01-02 19:34:09 +02:00
Sergei Trofimovich ccb1c31ba3 compiledict.c: change 'temp' to "${dict}temp" temporary file
This way we can compile multiple dictionaries at a time without
stepping on 'temp' file from different compilation steps:

    $ make -j8 -B
    ...
    make[1]: *** [Makefile:3082: espeak-ng-data/an_dict] Segmentation fault (core dumped)
    make[1]: *** Deleting file 'espeak-ng-data/an_dict'
    make[1]: *** [Makefile:3082: espeak-ng-data/az_dict] Segmentation fault (core dumped)
    make[1]: *** Deleting file 'espeak-ng-data/az_dict'
2021-11-07 12:55:57 +00:00
Samuel Thibault 572fe31c1b mbrola: Report error when loading an mbrola voice fails
Otherwise espeak_SetVoiceByName returns EE_OK even if the mbrola voice
file could not be loaded and thus setting the voice actually failed.
2021-10-16 22:40:55 +02:00
Juho Hiltunen d80f1a80a2 Use ESPEAKNG_DEFAULT_VOICE instead of hard coded "en".
This will make it easier to set a default voice other than
English. This is important for cases when a language will fall back to
the default voice.

Some references to L('e', 'n') still need to be changed.
2021-08-10 19:57:53 +03:00
Juho Hiltunen 3038d40081 code cleanup: remove unnecessary #defines.
Found by parsing the results from this bash script:
for define in $(grep define *.h |  awk'{print $2}');
do if ! grep -q $define *.c
then
        echo "$define not found";
fi
done
2021-07-31 17:29:33 +03:00
Juho Hiltunen e91d0a5861 code cleanup: don't add a \0 to voices_language in LoadVoice().
This is unnecessary since the string is already null terminated in the
V_LANGUAGE switch case. sscanf creates a null terminated string in
language_name, which is then copied to voice_language by strcpy (keeping
the \0).
2021-07-30 17:18:47 +03:00
Juho Hiltunen eae0665be5 code cleanup: move voices->width in LoadVoice()
It's probably unnecessary code and could be removed. However, it would
break tests. This is a temporary solution.

The solution is to do it once in VoiceReset() and then if the "formant"
keyword changes voice->width.
2021-07-28 22:11:47 +03:00
Juho Hiltunen c28412db78 Don't set stress_flags with language option "stressRule".
Language option "stressOpt" already handles separate flags instead of a
single integer. There's no reason to have two ways of setting the same
option.
2021-07-27 22:15:28 +03:00
Juho Hiltunen 537617afc5 et: fi: move stressopt from tr_languages.c to language files
This is to make sure "stressopt" language option works. Current tests
would fail if it didn't.
2021-07-27 22:15:28 +03:00
Juho Hiltunen 602847371d rename language option stressopt to stressOpt 2021-07-27 22:15:28 +03:00
Juho Hiltunen a6abb1e89b code cleanup: use ReadNumbers() for language options "dictrules", "stressopt"
language option "numbers" could be changed to use the same function, but
it needs tests.
2021-07-27 22:15:28 +03:00
Juho Hiltunen fdc1afd407 code cleanup: new function ReadNumbers()
ReadNumbers8) parses an unknown number of numbers from language files.
Used mostly for setting flags.
Used mostly for setting flags.
2021-07-27 22:15:28 +03:00
Juho Hiltunen ac643ea5ad code cleanup: remove unnecessary call to SelectPhonemeTable()
It is called multiple times in LoadVoice().
2021-07-26 17:43:15 +03:00
Juho Hiltunen 80895db0a8 code cleanup: move SetSpeed() inside the switch case in LoadVoice()
SetSpeed is needed when "speed" keyword changes voice->speed_percent.
2021-07-26 17:07:42 +03:00
Juho Hiltunen 01f094346d nb: fix regression for language options.
182aba4cc started calling Norwegian nb instead of no. The result is that
code in tr_languages.c was never run.
2021-07-23 18:32:33 +03:00
Juho Hiltunen 1a5db2f498 code cleanup: move dict_min_size handline in LoadVoice(). 2021-07-11 19:43:04 +03:00
Juho Hiltunen 0e7202f9a9 code cleanup: remove unused language option l_length_mods.
It is not used by any language. There is no need to check for it in
LoadVoice().
2021-07-11 19:09:44 +03:00
Juho Hiltunen 863655903a code cleanup: move SetLengthMods to setlengths.c 2021-07-11 17:05:00 +03:00
Juho Hiltunen 72434616b0 code cleanup: move voice->freq2 and voice->height2 handline in LoadVoice().
VoiceReset() now sets them initially. VoiceFormant() changes them if
"formant" option is used.
2021-07-11 16:30:17 +03:00