Browse Source

Merge branch 'staticanalysis'

Fixes for some code smells found with cppcheck static code analysis tool.
master
Juho Hiltunen 2 years ago
parent
commit
385105b7cd

+ 4
- 4
src/libespeak-ng/dictionary.c View File

letter_group = LetterGroupNo(rule++); letter_group = LetterGroupNo(rule++);
if ((n_bytes = IsLetterGroup(tr, post_ptr-1, letter_group, 0)) >= 0) { if ((n_bytes = IsLetterGroup(tr, post_ptr-1, letter_group, 0)) >= 0) {
add_points = (20-distance_right); add_points = (20-distance_right);
if (n_bytes >= 0) // move pointer, if group was found
post_ptr += (n_bytes-1);
// move pointer, if group was found
post_ptr += (n_bytes-1);
} else } else
failed = 1; failed = 1;
break; break;
letter_group = LetterGroupNo(rule++); letter_group = LetterGroupNo(rule++);
if ((n_bytes = IsLetterGroup(tr, pre_ptr, letter_group, 1)) >= 0) { if ((n_bytes = IsLetterGroup(tr, pre_ptr, letter_group, 1)) >= 0) {
add_points = (20-distance_right); add_points = (20-distance_right);
if (n_bytes >= 0) // move pointer, if group was found
pre_ptr -= (n_bytes-1);
// move pointer, if group was found
pre_ptr -= (n_bytes-1);
} else } else
failed = 1; failed = 1;
break; break;

+ 2
- 7
src/libespeak-ng/intonation.c View File

p = &phoneme_list[0]; p = &phoneme_list[0];
for (ix = 0; ix < n_phoneme_list; ix++, p++) { for (ix = 0; ix < n_phoneme_list; ix++, p++) {
if ((p->type == phVOWEL) && (p->stresslevel >= 4)) { if ((p->type == phVOWEL) && (p->stresslevel >= 4)) {
if (count_stressed == 0)
final_stressed = ix;

if (p->stresslevel >= 4) {
final_stressed = ix;
count_stressed++;
}
final_stressed = ix;
count_stressed++;
} }
} }



+ 6
- 7
src/libespeak-ng/numbers.c View File

sprintf(ph_out, "%s%s%s%s", ph_tens, ph_and, ph_digits, ph_ordinal); sprintf(ph_out, "%s%s%s%s", ph_tens, ph_and, ph_digits, ph_ordinal);
used_and = 1; used_and = 1;
} else { } else {
if (tr->langopts.numbers & NUM_SINGLE_VOWEL) {
if ((tr->langopts.numbers & NUM_SINGLE_VOWEL) && ph_digits[0] != 0) {
// remove vowel from the end of tens if units starts with a vowel (LANG=Italian) // remove vowel from the end of tens if units starts with a vowel (LANG=Italian)
if (((ix = strlen(ph_tens)-1) >= 0) && (ph_digits[0] != 0)) {
if ((next_phtype = phoneme_tab[(unsigned int)(ph_digits[0])]->type) == phSTRESS)
next_phtype = phoneme_tab[(unsigned int)(ph_digits[1])]->type;
ix = strlen(ph_tens) - 1;
if ((next_phtype = phoneme_tab[(unsigned int)(ph_digits[0])]->type) == phSTRESS)
next_phtype = phoneme_tab[(unsigned int)(ph_digits[1])]->type;


if ((phoneme_tab[(unsigned int)(ph_tens[ix])]->type == phVOWEL) && (next_phtype == phVOWEL))
ph_tens[ix] = 0;
}
if ((phoneme_tab[(unsigned int)(ph_tens[ix])]->type == phVOWEL) && (next_phtype == phVOWEL))
ph_tens[ix] = 0;
} }


if ((tr->langopts.numbers2 & NUM2_ORDINAL_DROP_VOWEL) && (ph_ordinal[0] != 0)) { if ((tr->langopts.numbers2 & NUM2_ORDINAL_DROP_VOWEL) && (ph_ordinal[0] != 0)) {

+ 10
- 7
src/libespeak-ng/setlengths.c View File

wpm = embedded_value[EMBED_S2]; wpm = embedded_value[EMBED_S2];


#if HAVE_SONIC_H #if HAVE_SONIC_H
int wpm2;
int wpm_value; int wpm_value;
double sonic;

speed.min_pause = 5; speed.min_pause = 5;


wpm_value = wpm; wpm_value = wpm;
if (control & 2) if (control & 2)
DoSonicSpeed(1 * 1024); DoSonicSpeed(1 * 1024);
if ((wpm_value >= espeakRATE_MAXIMUM) || ((wpm_value > speed.fast_settings) && (wpm > 350))) { if ((wpm_value >= espeakRATE_MAXIMUM) || ((wpm_value > speed.fast_settings) && (wpm > 350))) {
int wpm2;
wpm2 = wpm; wpm2 = wpm;
wpm = espeakRATE_NORMAL; wpm = espeakRATE_NORMAL;


speed3 = (x * voice->speedf3)/256; speed3 = (x * voice->speedf3)/256;
} }
if (control & 2) { if (control & 2) {
double sonic;
sonic = ((double)wpm2)/wpm; sonic = ((double)wpm2)/wpm;
DoSonicSpeed((int)(sonic * 1024)); DoSonicSpeed((int)(sonic * 1024));
speed.pause_factor = 85; speed.pause_factor = 85;
// relative 0=absolute 1=relative // relative 0=absolute 1=relative


int new_value = value; int new_value = value;
int default_value;
extern const int param_defaults[N_SPEECH_PARAM]; extern const int param_defaults[N_SPEECH_PARAM];


if (relative) { if (relative) {
if (parameter < 5) { if (parameter < 5) {
int default_value;
default_value = param_defaults[parameter]; default_value = param_defaults[parameter];
new_value = default_value + (default_value * value)/100; new_value = default_value + (default_value * value)/100;
} }
PHONEME_LIST *p; PHONEME_LIST *p;
PHONEME_LIST *p2; PHONEME_LIST *p2;


int stress;
int type;
static int more_syllables = 0; static int more_syllables = 0;
bool pre_sonorant = false; bool pre_sonorant = false;
bool pre_voiced = false; bool pre_voiced = false;
int last_pitch = 0; int last_pitch = 0;
int pitch_start; int pitch_start;
int length_mod; int length_mod;

int next2type; int next2type;
int len; int len;
int env2; int env2;
int embedded_ix = 0; int embedded_ix = 0;
int min_drop; int min_drop;
int pitch1; int pitch1;
int emphasized;
int tone_mod; int tone_mod;
unsigned char *pitch_env = NULL; unsigned char *pitch_env = NULL;
PHONEME_DATA phdata_tone; PHONEME_DATA phdata_tone;



for (ix = 1; ix < n_phoneme_list; ix++) { for (ix = 1; ix < n_phoneme_list; ix++) {
int stress;
int emphasized;

prev = &phoneme_list[ix-1]; prev = &phoneme_list[ix-1];
p = &phoneme_list[ix]; p = &phoneme_list[ix];
stress = p->stresslevel & 0x7; stress = p->stresslevel & 0x7;
if (p->synthflags & SFLAG_EMBEDDED) if (p->synthflags & SFLAG_EMBEDDED)
DoEmbedded2(&embedded_ix); DoEmbedded2(&embedded_ix);


int type;
type = p->type; type = p->type;
if (p->synthflags & SFLAG_SYLLABLE) if (p->synthflags & SFLAG_SYLLABLE)
type = phVOWEL; type = phVOWEL;

+ 23
- 33
src/libespeak-ng/voices.c View File

int pt; int pt;
int y; int y;
int freq1 = 0; int freq1 = 0;
int freq2;
int height1 = tone_pts[1]; int height1 = tone_pts[1];
int height2;


for (pt = 0; pt < 12; pt += 2) { for (pt = 0; pt < 12; pt += 2) {
if (tone_pts[pt] == -1) { if (tone_pts[pt] == -1) {
if (pt > 0) if (pt > 0)
tone_pts[pt+1] = tone_pts[pt-1]; tone_pts[pt+1] = tone_pts[pt-1];
} }
int freq2;
int height2;
freq2 = tone_pts[pt] / 8; // 8Hz steps freq2 = tone_pts[pt] / 8; // 8Hz steps
height2 = tone_pts[pt+1]; height2 = tone_pts[pt+1];
if ((freq2 - freq1) > 0) { if ((freq2 - freq1) > 0) {
// store them as flags in *flags // store them as flags in *flags
// the meaning of the numbers is bit ordinals, not integer values // the meaning of the numbers is bit ordinals, not integer values
// give an error if number > maxValue is read // give an error if number > maxValue is read
int n;
while (*p != 0) { while (*p != 0) {
while (isspace(*p)) p++; while (isspace(*p)) p++;
int n;
if ((n = atoi(p)) > 0) { if ((n = atoi(p)) > 0) {
p++; p++;
if (n < maxValue) { if (n < maxValue) {
char phonemes_name[40] = ""; char phonemes_name[40] = "";
const char *language_type; const char *language_type;
char buf[sizeof(path_home)+30]; char buf[sizeof(path_home)+30];
char path_voices[sizeof(path_home)+12];


char name1[40]; char name1[40];
char name2[80]; char name2[80];


if (voicename[0] == 0 && !(control & 8)/*compiling phonemes*/) if (voicename[0] == 0 && !(control & 8)/*compiling phonemes*/)
strcpy(voicename, ESPEAKNG_DEFAULT_VOICE); strcpy(voicename, ESPEAKNG_DEFAULT_VOICE);


char path_voices[sizeof(path_home)+12];
sprintf(path_voices, "%s%cvoices%c", path_home, PATHSEP, PATHSEP); sprintf(path_voices, "%s%cvoices%c", path_home, PATHSEP, PATHSEP);
sprintf(buf, "%s%s", path_voices, voicename); // look in the main voices directory sprintf(buf, "%s%s", path_voices, voicename); // look in the main voices directory


// Remove any voice variant suffix (name or number) from a voice name // Remove any voice variant suffix (name or number) from a voice name
// Returns the voice variant name // Returns the voice variant name


char *p;
static char variant_name[40]; static char variant_name[40];
char variant_prefix[5]; char variant_prefix[5];


variant_prefix[0] = 0; variant_prefix[0] = 0;


if (vname != NULL) { if (vname != NULL) {
char *p;
if ((p = strchr(vname, '+')) != NULL) { if ((p = strchr(vname, '+')) != NULL) {
// The voice name has a +variant suffix // The voice name has a +variant suffix
variant_num = 0; variant_num = 0;


static int ScoreVoice(espeak_VOICE *voice_spec, const char *spec_language, int spec_n_parts, int spec_lang_len, espeak_VOICE *voice) static int ScoreVoice(espeak_VOICE *voice_spec, const char *spec_language, int spec_n_parts, int spec_lang_len, espeak_VOICE *voice)
{ {
int ix;
const char *p; const char *p;
int c1, c2;
int language_priority;
int n_parts;
int matching;
int matching_parts;
int score = 0; int score = 0;
int x; int x;
int ratio;
int required_age;
int diff;


p = voice->languages; // list of languages+dialects for which this voice is suitable p = voice->languages; // list of languages+dialects for which this voice is suitable




// compare the required language with each of the languages of this voice // compare the required language with each of the languages of this voice
while (*p != 0) { while (*p != 0) {
language_priority = *p++;
int language_priority = *p++;


matching = 1;
matching_parts = 0;
n_parts = 1;


int n_parts = 1;
int matching = 1;
int matching_parts = 0;
int ix;
for (ix = 0;; ix++) { for (ix = 0;; ix++) {
int c1, c2;
if ((ix >= spec_lang_len) || ((c1 = spec_language[ix]) == '-')) if ((ix >= spec_lang_len) || ((c1 = spec_language[ix]) == '-'))
c1 = 0; c1 = 0;
if ((c2 = p[ix]) == '-') if ((c2 = p[ix]) == '-')


x = 5; x = 5;
// reduce the score if not all parts of the required language match // reduce the score if not all parts of the required language match
int diff;
if ((diff = (spec_n_parts - matching_parts)) > 0) if ((diff = (spec_n_parts - matching_parts)) > 0)
x -= diff; x -= diff;


score += 5; // give some preference for non-child female voice if a child is requested score += 5; // give some preference for non-child female voice if a child is requested


if (voice->age != 0) { if (voice->age != 0) {
int required_age;
if (voice_spec->age == 0) if (voice_spec->age == 0)
required_age = 30; required_age = 30;
else else
required_age = voice_spec->age; required_age = voice_spec->age;


int ratio;
ratio = (required_age*100)/voice->age; ratio = (required_age*100)/voice->age;
if (ratio < 100) if (ratio < 100)
ratio = 10000/ratio; ratio = 10000/ratio;
int lang_len = 0; int lang_len = 0;
espeak_VOICE *vp; espeak_VOICE *vp;
char language[80]; char language[80];
char buf[sizeof(path_home)+80];


// count number of parts in the specified language // count number of parts in the specified language
if ((voice_select->languages != NULL) && (voice_select->languages[0] != 0)) { if ((voice_select->languages != NULL) && (voice_select->languages[0] != 0)) {
lang_len = 2; lang_len = 2;
} }


char buf[sizeof(path_home)+80];
sprintf(buf, "%s/voices/%s", path_home, language); sprintf(buf, "%s/voices/%s", path_home, language);
if (GetFileLength(buf) == -EISDIR) { if (GetFileLength(buf) == -EISDIR) {
// A subdirectory name has been specified. List all the voices in that subdirectory // A subdirectory name has been specified. List all the voices in that subdirectory
int match_fname2 = -1; int match_fname2 = -1;
int match_name = -1; int match_name = -1;
const char *id; // this is the filename within espeak-ng-data/voices const char *id; // this is the filename within espeak-ng-data/voices
char *variant_name;
int last_part_len; int last_part_len;
char last_part[41]; char last_part[41];
char name[40]; char name[40];
} }


strncpy0(name, name2, sizeof(name)); strncpy0(name, name2, sizeof(name));
if ((variant_name = strchr(name, '+')) != NULL) {
*variant_name = 0;
variant_name++;
}


sprintf(last_part, "%c%s", PATHSEP, name); sprintf(last_part, "%c%s", PATHSEP, name);
last_part_len = strlen(last_part); last_part_len = strlen(last_part);
int n_variants; int n_variants;
int variant_number; int variant_number;
int gender; int gender;
int skip;
int aged = 1; int aged = 1;
char *variant_name; char *variant_name;
const char *p, *p_start; const char *p, *p_start;
for (ix = 0, ix2 = 0; ix < nv; ix++) { for (ix = 0, ix2 = 0; ix < nv; ix++) {
vp = voices[ix]; vp = voices[ix];
// is the main voice the required gender? // is the main voice the required gender?
skip = 0;
bool skip = false;


if ((gender != ENGENDER_UNKNOWN) && (vp->gender != gender)) if ((gender != ENGENDER_UNKNOWN) && (vp->gender != gender))
skip = 1;
skip = true;
if ((ix2 == 0) && aged && (vp->age < AGE_OLD)) if ((ix2 == 0) && aged && (vp->age < AGE_OLD))
skip = 1;
skip = true;


if (skip == 0)
if (skip == false)
voices2[ix2++] = vp; voices2[ix2++] = vp;


for (j = 0; (j < vp->xx1) && (n_variants < N_VOICE_VARIANTS);) { for (j = 0; (j < vp->xx1) && (n_variants < N_VOICE_VARIANTS);) {
{ {
char path_voices[sizeof(path_home)+12]; char path_voices[sizeof(path_home)+12];


int ix;
int j;
espeak_VOICE *v; espeak_VOICE *v;
static espeak_VOICE **voices = NULL; static espeak_VOICE **voices = NULL;


SetVoiceScores(voice_spec, voices, 1); SetVoiceScores(voice_spec, voices, 1);
} else { } else {
// list all: omit variant and mbrola voices // list all: omit variant and mbrola voices
int ix;
int j;

j = 0; j = 0;
for (ix = 0; (v = voices_list[ix]) != NULL; ix++) { for (ix = 0; (v = voices_list[ix]) != NULL; ix++) {
if ((v->languages[0] != 0) && (strcmp(&v->languages[1], "variant") != 0) if ((v->languages[0] != 0) && (strcmp(&v->languages[1], "variant") != 0)

Loading…
Cancel
Save