Commit 9a880bc8 authored by salix5's avatar salix5

sscanf fix

max len of text = 240 UTF8 char
parent 6e4bb1b6
......@@ -85,19 +85,19 @@ bool DataManager::LoadStrings(const char* file) {
continue;
sscanf(linebuf, "!%s", strbuf);
if(!strcmp(strbuf, "system")) {
sscanf(&linebuf[7], "%d %99[^\n]", &value, strbuf);
sscanf(&linebuf[7], "%d %240[^\n]", &value, strbuf);
int len = BufferIO::DecodeUTF8(strbuf, strBuffer);
wchar_t* pbuf = new wchar_t[len + 1];
wcscpy(pbuf, strBuffer);
_sysStrings[value] = pbuf;
} else if(!strcmp(strbuf, "victory")) {
sscanf(&linebuf[8], "%x %99[^\n]", &value, strbuf);
sscanf(&linebuf[8], "%x %240[^\n]", &value, strbuf);
int len = BufferIO::DecodeUTF8(strbuf, strBuffer);
wchar_t* pbuf = new wchar_t[len + 1];
wcscpy(pbuf, strBuffer);
_victoryStrings[value] = pbuf;
} else if(!strcmp(strbuf, "counter")) {
sscanf(&linebuf[8], "%x %99[^\n]", &value, strbuf);
sscanf(&linebuf[8], "%x %240[^\n]", &value, strbuf);
int len = BufferIO::DecodeUTF8(strbuf, strBuffer);
wchar_t* pbuf = new wchar_t[len + 1];
wcscpy(pbuf, strBuffer);
......
......@@ -802,14 +802,23 @@ void Game::LoadConfig() {
int fsize = ftell(fp);
fseek(fp, 0, SEEK_SET);
while(ftell(fp) < fsize) {
fgets(linebuf, 250, fp);
sscanf(linebuf, "%s = %s", strbuf, valbuf);
fgets(linebuf, 256, fp);
sscanf(linebuf, "%s = %240[^\n]", strbuf, valbuf);
if(!strcmp(strbuf, "antialias")) {
gameConf.antialias = atoi(valbuf);
} else if(!strcmp(strbuf, "use_d3d")) {
gameConf.use_d3d = atoi(valbuf) > 0;
} else if(!strcmp(strbuf, "errorlog")) {
enable_log = atoi(valbuf);
} else if(!strcmp(strbuf, "nickname")) {
BufferIO::DecodeUTF8(valbuf, wstr);
BufferIO::CopyWStr(wstr, gameConf.nickname, 20);
} else if(!strcmp(strbuf, "gamename")) {
BufferIO::DecodeUTF8(valbuf, wstr);
BufferIO::CopyWStr(wstr, gameConf.gamename, 20);
} else if(!strcmp(strbuf, "lastdeck")) {
BufferIO::DecodeUTF8(valbuf, wstr);
BufferIO::CopyWStr(wstr, gameConf.lastdeck, 64);
} else if(!strcmp(strbuf, "textfont")) {
BufferIO::DecodeUTF8(valbuf, wstr);
int textfontsize;
......@@ -830,21 +839,6 @@ void Game::LoadConfig() {
} else if(!strcmp(strbuf, "roompass")) {
BufferIO::DecodeUTF8(valbuf, wstr);
BufferIO::CopyWStr(wstr, gameConf.roompass, 20);
} else {
// options allowing multiple words
sscanf(linebuf, "%s = %99[^\n]", strbuf, valbuf);
if (!strcmp(strbuf, "nickname")) {
BufferIO::DecodeUTF8(valbuf, wstr);
BufferIO::CopyWStr(wstr, gameConf.nickname, 20);
}
else if (!strcmp(strbuf, "gamename")) {
BufferIO::DecodeUTF8(valbuf, wstr);
BufferIO::CopyWStr(wstr, gameConf.gamename, 20);
}
else if (!strcmp(strbuf, "lastdeck")) {
BufferIO::DecodeUTF8(valbuf, wstr);
BufferIO::CopyWStr(wstr, gameConf.lastdeck, 64);
}
}
}
fclose(fp);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment