Skip to content

Commit 4fbf88f

Browse files
authored
Merge pull request #704 from RamonUnch/Use-a-fixed-8-char-buf-for-xx_YY-lang-code
Use a fixed 8 char buf for xx_YY lang code
2 parents 853434f + ea7649e commit 4fbf88f

3 files changed

Lines changed: 5 additions & 8 deletions

File tree

config.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -549,7 +549,7 @@ static INT_PTR CALLBACK GeneralPageDialogProc(HWND hwnd, UINT msg, WPARAM wParam
549549
if (langinfo) {
550550
for (i = 0; i < nlanguages; i++) {
551551
CB_AddString(control, langinfo[i].lang);
552-
if (langinfo[i].code && !lstrcmpi(l10n->Code, langinfo[i].code) ) {
552+
if ( !lstrcmpi(l10n->Code, langinfo[i].code) ) {
553553
CB_SetCurSel(control, i);
554554
}
555555
}

languages.c

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ static void LoadTranslationOrTT(const TCHAR *__restrict__ ini, const TCHAR * __r
8181
if (!ret)
8282
tsection[0] = tsection[1] = TEXT('\0');
8383

84-
if(!l10n_ini) l10n_ini = (struct strings *)calloc(1, sizeof(struct strings));
84+
if(!l10n_ini) { l10n_ini = (struct strings *)calloc(1, sizeof(struct strings)); }
8585
if(!l10n_ini) return; // Unable to allocate mem
8686

8787
for (i=0; i < ARR_SZ(l10n_inimapping); i++) {
@@ -136,7 +136,7 @@ void ListAllTranslations()
136136
// First element
137137
langinfo = (struct langinfoitem *)malloc( sizeof(struct langinfoitem) );
138138
if (!langinfo) return;
139-
langinfo[0].code = en_US.Code;
139+
lstrcpy_s(langinfo[0].code, ARR_SZ(langinfo[0].code), en_US.Code);
140140
langinfo[0].lang_english = en_US.LangEnglish;
141141
langinfo[0].lang = en_US.Lang;
142142
langinfo[0].author = en_US.Author;
@@ -167,9 +167,7 @@ void ListAllTranslations()
167167

168168
// Short language code such as en-US, fr-FR, it-IT etc.
169169
txt = GetSectionOptionCStr(tsection, "Code", TEXT(""));
170-
langinfo[n].code = (TCHAR *)calloc(lstrlen(txt)+1, sizeof(TCHAR));
171-
if (!langinfo[n].code) break;
172-
lstrcpy(langinfo[n].code, txt);
170+
lstrcpy_s(langinfo[n].code, ARR_SZ(langinfo[n].code), txt);
173171

174172
// Language name in English
175173
txt = GetSectionOptionCStr(tsection, "LangEnglish", TEXT(""));
@@ -241,7 +239,6 @@ void FreeAllLangRelated()
241239
{
242240
if (langinfo) {
243241
for (int i=1; i < nlanguages; i++) {
244-
free(langinfo[i].code);
245242
free(langinfo[i].lang_english);
246243
free(langinfo[i].lang);
247244
free(langinfo[i].author);

languages.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
#define L10NSTR(i) ( ((const TCHAR*const*const)l10n)[i] )
2222

2323
struct langinfoitem {
24-
TCHAR *code;
24+
TCHAR code[8];
2525
TCHAR *lang_english;
2626
TCHAR *lang;
2727
TCHAR *author;

0 commit comments

Comments
 (0)