Skip to content

Commit

Permalink
Fix read_lang()
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelortmann committed Aug 27, 2024
1 parent 7dbc918 commit 6e03029
Showing 1 changed file with 16 additions and 7 deletions.
23 changes: 16 additions & 7 deletions src/language.c
Original file line number Diff line number Diff line change
Expand Up @@ -210,9 +210,10 @@ static void recheck_lang_sections(void)
static void read_lang(char *langfile)
{
FILE *FLANG;
char lbuf[512];
char lbuf[256];
char *ltext = NULL;
char *ctmp, *ctmp1;
int ltextsize = sizeof lbuf;
int lidx;
int lnew = 1;
int lline = 1;
Expand All @@ -228,7 +229,7 @@ static void read_lang(char *langfile)
}

for (*(ltext = nmalloc(sizeof lbuf)) = 0; fgets(lbuf, sizeof lbuf, FLANG);
ltext = nrealloc(ltext, strlen(ltext) + sizeof lbuf), lskip = 0) {
lskip = 0) {
if (lnew) {
if ((lbuf[0] == '#') || (sscanf(lbuf, "%s", ltext) == EOF))
lskip = 1;
Expand All @@ -238,20 +239,28 @@ static void read_lang(char *langfile)
lskip = 1;
}
if (lskip) {
while (!strchr(lbuf, '\n') && fgets(lbuf, 511, FLANG) != NULL) {
while (!strchr(lbuf, '\n') && fgets(lbuf, sizeof lbuf, FLANG) != NULL) {
lline++;
}
/* fgets == NULL means error or empty file, so check for error */
if (ferror(FLANG)) {
putlog(LOG_MISC, "*", "LANG: Error reading lang file.");
}
lline++;
lnew = 1;
continue;
}
strcpy(ltext, strchr(lbuf, ',') + 1);
} else
strcpy(strchr(ltext, 0), lbuf);
if ((ctmp = strchr(lbuf, ',')))
strcpy(ltext, strchr(lbuf, ',') + 1);
else
putlog(LOG_MISC, "*", "LANG: Malformed text line (missing ,) in %s at %d.",
langfile, lline);
} else {
if ((strlen(ltext) + strlen(lbuf) + 1) > ltextsize) {
ltextsize += sizeof lbuf;
ltext = nrealloc(ltext, ltextsize);
}
strcat(ltext, lbuf);
}
if ((ctmp = strchr(ltext, '\n'))) {
lline++;
*ctmp = 0;
Expand Down

0 comments on commit 6e03029

Please sign in to comment.