mirror of
https://github.com/rhasspy/espeak-ng.git
synced 2026-12-02 22:52:29 +00:00
Use malloc/strdup instead of Alloc.
This commit is contained in:
@@ -231,7 +231,10 @@ int LoadDictionary(Translator *tr, const char *name, int no_error)
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
tr->data_dictlist = Alloc(size);
|
if ((tr->data_dictlist = malloc(size)) == NULL) {
|
||||||
|
fclose(f);
|
||||||
|
return 3;
|
||||||
|
}
|
||||||
size = fread(tr->data_dictlist, 1, size, f);
|
size = fread(tr->data_dictlist, 1, size, f);
|
||||||
fclose(f);
|
fclose(f);
|
||||||
|
|
||||||
|
|||||||
@@ -251,18 +251,6 @@ int GetFileLength(const char *filename)
|
|||||||
return statbuf.st_size;
|
return statbuf.st_size;
|
||||||
}
|
}
|
||||||
|
|
||||||
#pragma GCC visibility pop
|
|
||||||
|
|
||||||
char *Alloc(int size)
|
|
||||||
{
|
|
||||||
char *p;
|
|
||||||
if ((p = (char *)malloc(size)) == NULL)
|
|
||||||
fprintf(stderr, "Can't allocate memory\n"); // I was told that size+1 fixes a crash on 64-bit systems
|
|
||||||
return p;
|
|
||||||
}
|
|
||||||
|
|
||||||
#pragma GCC visibility push(default)
|
|
||||||
|
|
||||||
ESPEAK_NG_API void espeak_ng_InitializePath(const char *path)
|
ESPEAK_NG_API void espeak_ng_InitializePath(const char *path)
|
||||||
{
|
{
|
||||||
if (path != NULL) {
|
if (path != NULL) {
|
||||||
|
|||||||
@@ -69,7 +69,6 @@ extern char path_home[N_PATH_HOME]; // this is the espeak-data directory
|
|||||||
|
|
||||||
extern ESPEAK_NG_API void strncpy0(char *to, const char *from, int size);
|
extern ESPEAK_NG_API void strncpy0(char *to, const char *from, int size);
|
||||||
extern ESPEAK_NG_API int GetFileLength(const char *filename);
|
extern ESPEAK_NG_API int GetFileLength(const char *filename);
|
||||||
char *Alloc(int size);
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -88,7 +88,7 @@ static espeak_ng_STATUS ReadPhFile(void **ptr, const char *fname, int *size, esp
|
|||||||
if (*ptr != NULL)
|
if (*ptr != NULL)
|
||||||
free(*ptr);
|
free(*ptr);
|
||||||
|
|
||||||
if ((*ptr = Alloc(length)) == NULL) {
|
if ((*ptr = malloc(length)) == NULL) {
|
||||||
fclose(f_in);
|
fclose(f_in);
|
||||||
return ENOMEM;
|
return ENOMEM;
|
||||||
}
|
}
|
||||||
@@ -411,7 +411,6 @@ void LoadConfig(void)
|
|||||||
FILE *f;
|
FILE *f;
|
||||||
int ix;
|
int ix;
|
||||||
char c1;
|
char c1;
|
||||||
char *p;
|
|
||||||
char string[200];
|
char string[200];
|
||||||
|
|
||||||
for (ix = 0; ix < N_SOUNDICON_SLOTS; ix++) {
|
for (ix = 0; ix < N_SOUNDICON_SLOTS; ix++) {
|
||||||
@@ -434,9 +433,7 @@ void LoadConfig(void)
|
|||||||
ix = sscanf(&buf[10], "_%c %s", &c1, string);
|
ix = sscanf(&buf[10], "_%c %s", &c1, string);
|
||||||
if (ix == 2) {
|
if (ix == 2) {
|
||||||
soundicon_tab[n_soundicon_tab].name = c1;
|
soundicon_tab[n_soundicon_tab].name = c1;
|
||||||
p = Alloc(strlen(string)+1);
|
soundicon_tab[n_soundicon_tab].filename = strdup(string);
|
||||||
strcpy(p, string);
|
|
||||||
soundicon_tab[n_soundicon_tab].filename = p;
|
|
||||||
soundicon_tab[n_soundicon_tab++].length = 0;
|
soundicon_tab[n_soundicon_tab++].length = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -220,8 +220,7 @@ static Translator *NewTranslator(void)
|
|||||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 55, 0, 56, 0, 57, 0, // 0x170
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 55, 0, 56, 0, 57, 0, // 0x170
|
||||||
};
|
};
|
||||||
|
|
||||||
tr = (Translator *)Alloc(sizeof(Translator));
|
if ((tr = (Translator *)malloc(sizeof(Translator))) == NULL)
|
||||||
if (tr == NULL)
|
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
tr->charset_a0 = charsets[1]; // ISO-8859-1, this is for when the input is not utf8
|
tr->charset_a0 = charsets[1]; // ISO-8859-1, this is for when the input is not utf8
|
||||||
|
|||||||
Reference in New Issue
Block a user