Browse Source

Properly compare strings

Strictly speaking, we are not supposed to use memcmp to compare strings
since we are not supposed to read beyond \0, which memcmp is supposed to
potentially do. Sanitizers would warn about it, and using strncmp happens to
provide the proper semantic while being not really slower, so better
just use them.
master
Samuel Thibault 3 years ago
parent
commit
c8de29dec9

+ 1
- 1
src/libespeak-ng/compiledict.c View File

mr = mnem_rules; mr = mnem_rules;
while (mr->mnem != NULL) { while (mr->mnem != NULL) {
len = strlen(mr->mnem); len = strlen(mr->mnem);
if (memcmp(p, mr->mnem, len) == 0) {
if (strncmp(p, mr->mnem, len) == 0) {
value = mr->value; value = mr->value;
p += len; p += len;
break; break;

+ 1
- 1
src/libespeak-ng/compilembrola.c View File

if ((p = strstr(buf, "//")) != NULL) if ((p = strstr(buf, "//")) != NULL)
*p = 0; // truncate line at comment *p = 0; // truncate line at comment


if (memcmp(buf, "volume", 6) == 0) {
if (strncmp(buf, "volume", 6) == 0) {
mbrola_ctrl = atoi(&buf[6]); mbrola_ctrl = atoi(&buf[6]);
continue; continue;
} }

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

} }
} }


if (memcmp(word2, p, n_chars) != 0)
if (strncmp(word2, p, n_chars) != 0)
condition_failed = 1; condition_failed = 1;


if (condition_failed) { if (condition_failed) {

Loading…
Cancel
Save