Skip to content

Commit 13d6efc

Browse files
committed
fix jsondocument alloc size
1 parent 220a564 commit 13d6efc

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

src/i18n/i18n.cpp

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -164,13 +164,13 @@ bool i18n_t::setLocale( const char* localeStr )
164164
memset( locale.country, 0, sizeof(locale.country) );
165165
memset( locale.variant, 0, sizeof(locale.variant) );
166166

167-
char delimiters[3] = {'-', '_'}; // guess delimiter
167+
char delimiters[2] = {'-', '_'}; // guess delimiter
168168
char *found = NULL;
169169
size_t tokenlen = 0;
170170

171171
for( int i=0;i<sizeof(delimiters);i++ ) {
172172
found = strchr( localeCopy, delimiters[i] );
173-
if( found ) {
173+
if( found != NULL ) {
174174
locale.delimiter[0] = delimiters[i];
175175
break;
176176
}
@@ -182,8 +182,10 @@ bool i18n_t::setLocale( const char* localeStr )
182182
goto _success;
183183
}
184184

185-
// a delimiter was found, assume it's at least language+country, and at most language+country+variant
186185
found = strtok( localeCopy, locale.delimiter );
186+
187+
// a delimiter was found, assume it's at least language+country, and at most language+country+variant
188+
found = strtok( NULL, locale.delimiter );
187189
if( found == NULL ) goto _error; // this should not happen as the delimiter was found earlier
188190
tokenlen = strlen( found );
189191
if( tokenlen !=2 && tokenlen != 3 ) goto _error; // bad language value, should be 2 or three letters
@@ -206,7 +208,7 @@ bool i18n_t::setLocale( const char* localeStr )
206208
return loadLocale();
207209

208210
_error:
209-
printf("Error, malformed locale: %s", localeStr );
211+
YAML_LOG_e("Error, malformed locale: %s", localeStr );
210212
free(localeCopy);
211213
return false;
212214
}
@@ -215,7 +217,7 @@ bool i18n_t::setLocale( const char* localeStr )
215217
bool i18n_t::loadLocale()
216218
{
217219
if( fs == nullptr ) {
218-
log_n("No filesystem attached, use setFS() e.g. i18n.setFS( &LiffleFS );");
220+
YAML_LOG_n("No filesystem attached, use setFS() e.g. i18n.setFS( &LiffleFS );");
219221
return false;
220222
}
221223
std::string localeStr = getLocale();
@@ -226,7 +228,7 @@ bool i18n_t::loadLocale()
226228
size_t localeSize = localeFile.size();
227229

228230
if( l10n.doc != nullptr ) delete l10n.doc;
229-
l10n.doc = new DynamicJsonDocument( localeSize );
231+
l10n.doc = new DynamicJsonDocument( localeSize * 2 ); // TODO: better evaluation
230232
JsonVariantConst rootvar = *l10n.doc;
231233

232234
auto err = deserializeYml( *l10n.doc, localeFile ); // deserialize yaml stream to JsonDocument

0 commit comments

Comments
 (0)