Commit c6755471 authored by Chen Bill's avatar Chen Bill

replace snprintf, sscanf

parent aedaf56f
...@@ -140,26 +140,26 @@ void DataManager::ReadStringConfLine(const char* linebuf) { ...@@ -140,26 +140,26 @@ void DataManager::ReadStringConfLine(const char* linebuf) {
char strbuf[TEXT_LINE_SIZE]{}; char strbuf[TEXT_LINE_SIZE]{};
int value{}; int value{};
wchar_t strBuffer[4096]{}; wchar_t strBuffer[4096]{};
if (sscanf(linebuf, "!%63s", strbuf) != 1) if (std::sscanf(linebuf, "!%63s", strbuf) != 1)
return; return;
if(!std::strcmp(strbuf, "system")) { if(!std::strcmp(strbuf, "system")) {
if (sscanf(&linebuf[7], "%d %240[^\n]", &value, strbuf) != 2) if (std::sscanf(&linebuf[7], "%d %240[^\n]", &value, strbuf) != 2)
return; return;
BufferIO::DecodeUTF8(strbuf, strBuffer); BufferIO::DecodeUTF8(strbuf, strBuffer);
_sysStrings[value] = strBuffer; _sysStrings[value] = strBuffer;
} else if(!std::strcmp(strbuf, "victory")) { } else if(!std::strcmp(strbuf, "victory")) {
if (sscanf(&linebuf[8], "%x %240[^\n]", &value, strbuf) != 2) if (std::sscanf(&linebuf[8], "%x %240[^\n]", &value, strbuf) != 2)
return; return;
BufferIO::DecodeUTF8(strbuf, strBuffer); BufferIO::DecodeUTF8(strbuf, strBuffer);
_victoryStrings[value] = strBuffer; _victoryStrings[value] = strBuffer;
} else if(!std::strcmp(strbuf, "counter")) { } else if(!std::strcmp(strbuf, "counter")) {
if (sscanf(&linebuf[8], "%x %240[^\n]", &value, strbuf) != 2) if (std::sscanf(&linebuf[8], "%x %240[^\n]", &value, strbuf) != 2)
return; return;
BufferIO::DecodeUTF8(strbuf, strBuffer); BufferIO::DecodeUTF8(strbuf, strBuffer);
_counterStrings[value] = strBuffer; _counterStrings[value] = strBuffer;
} else if(!std::strcmp(strbuf, "setname")) { } else if(!std::strcmp(strbuf, "setname")) {
//using tab for comment //using tab for comment
if (sscanf(&linebuf[8], "%x %240[^\t\n]", &value, strbuf) != 2) if (std::sscanf(&linebuf[8], "%x %240[^\t\n]", &value, strbuf) != 2)
return; return;
BufferIO::DecodeUTF8(strbuf, strBuffer); BufferIO::DecodeUTF8(strbuf, strBuffer);
_setnameStrings[value] = strBuffer; _setnameStrings[value] = strBuffer;
......
...@@ -30,7 +30,7 @@ void DeckManager::LoadLFListSingle(const char* path) { ...@@ -30,7 +30,7 @@ void DeckManager::LoadLFListSingle(const char* path) {
} }
int code = 0; int code = 0;
int count = -1; int count = -1;
if (sscanf(linebuf, "%d %d", &code, &count) != 2) if (std::sscanf(linebuf, "%d %d", &code, &count) != 2)
continue; continue;
if (code <= 0 || code > MAX_CARD_ID) if (code <= 0 || code > MAX_CARD_ID)
continue; continue;
......
...@@ -1285,17 +1285,17 @@ void Game::RefreshBot() { ...@@ -1285,17 +1285,17 @@ void Game::RefreshBot() {
continue; continue;
if(linebuf[0] == '!') { if(linebuf[0] == '!') {
BotInfo newinfo; BotInfo newinfo;
if (sscanf(linebuf, "!%240[^\n]", strbuf) != 1) if (std::sscanf(linebuf, "!%240[^\n]", strbuf) != 1)
continue; continue;
BufferIO::DecodeUTF8(strbuf, newinfo.name); BufferIO::DecodeUTF8(strbuf, newinfo.name);
if (!std::fgets(linebuf, 256, fp)) if (!std::fgets(linebuf, 256, fp))
break; break;
if (sscanf(linebuf, "%240[^\n]", strbuf) != 1) if (std::sscanf(linebuf, "%240[^\n]", strbuf) != 1)
continue; continue;
BufferIO::DecodeUTF8(strbuf, newinfo.command); BufferIO::DecodeUTF8(strbuf, newinfo.command);
if (!std::fgets(linebuf, 256, fp)) if (!std::fgets(linebuf, 256, fp))
break; break;
if (sscanf(linebuf, "%240[^\n]", strbuf) != 1) if (std::sscanf(linebuf, "%240[^\n]", strbuf) != 1)
continue; continue;
BufferIO::DecodeUTF8(strbuf, newinfo.desc); BufferIO::DecodeUTF8(strbuf, newinfo.desc);
if (!std::fgets(linebuf, 256, fp)) if (!std::fgets(linebuf, 256, fp))
...@@ -1336,7 +1336,7 @@ void Game::LoadConfig() { ...@@ -1336,7 +1336,7 @@ void Game::LoadConfig() {
char strbuf[64]{}; char strbuf[64]{};
char valbuf[960]{}; char valbuf[960]{};
while(std::fgets(linebuf, sizeof linebuf, fp)) { while(std::fgets(linebuf, sizeof linebuf, fp)) {
if (sscanf(linebuf, "%63s = %959s", strbuf, valbuf) != 2) if (std::sscanf(linebuf, "%63s = %959s", strbuf, valbuf) != 2)
continue; continue;
if(!std::strcmp(strbuf, "antialias")) { if(!std::strcmp(strbuf, "antialias")) {
gameConf.antialias = strtol(valbuf, nullptr, 10); gameConf.antialias = strtol(valbuf, nullptr, 10);
...@@ -1349,7 +1349,7 @@ void Game::LoadConfig() { ...@@ -1349,7 +1349,7 @@ void Game::LoadConfig() {
enable_log = val & 0xff; enable_log = val & 0xff;
} else if(!std::strcmp(strbuf, "textfont")) { } else if(!std::strcmp(strbuf, "textfont")) {
int textfontsize = 0; int textfontsize = 0;
if (sscanf(linebuf, "%63s = %959s %d", strbuf, valbuf, &textfontsize) != 3) if (std::sscanf(linebuf, "%63s = %959s %d", strbuf, valbuf, &textfontsize) != 3)
continue; continue;
gameConf.textfontsize = textfontsize; gameConf.textfontsize = textfontsize;
BufferIO::DecodeUTF8(valbuf, gameConf.textfont); BufferIO::DecodeUTF8(valbuf, gameConf.textfont);
...@@ -1447,7 +1447,7 @@ void Game::LoadConfig() { ...@@ -1447,7 +1447,7 @@ void Game::LoadConfig() {
#endif #endif
} else { } else {
// options allowing multiple words // options allowing multiple words
if (sscanf(linebuf, "%63s = %959[^\n]", strbuf, valbuf) != 2) if (std::sscanf(linebuf, "%63s = %959[^\n]", strbuf, valbuf) != 2)
continue; continue;
if (!std::strcmp(strbuf, "nickname")) { if (!std::strcmp(strbuf, "nickname")) {
BufferIO::DecodeUTF8(valbuf, gameConf.nickname); BufferIO::DecodeUTF8(valbuf, gameConf.nickname);
...@@ -1715,7 +1715,7 @@ void Game::AddDebugMsg(const char* msg) { ...@@ -1715,7 +1715,7 @@ void Game::AddDebugMsg(const char* msg) {
} }
if (enable_log & 0x2) { if (enable_log & 0x2) {
char msgbuf[1040]; char msgbuf[1040];
snprintf(msgbuf, sizeof msgbuf, "[Script Error]: %s", msg); std::snprintf(msgbuf, sizeof msgbuf, "[Script Error]: %s", msg);
ErrorLog(msgbuf); ErrorLog(msgbuf);
} }
} }
......
...@@ -234,10 +234,10 @@ irr::video::ITexture* ImageManager::GetTexture(int code, bool fit) { ...@@ -234,10 +234,10 @@ irr::video::ITexture* ImageManager::GetTexture(int code, bool fit) {
auto tit = tMap[fit ? 1 : 0].find(code); auto tit = tMap[fit ? 1 : 0].find(code);
if(tit == tMap[fit ? 1 : 0].end()) { if(tit == tMap[fit ? 1 : 0].end()) {
char file[256]; char file[256];
snprintf(file, sizeof file, "expansions/pics/%d.jpg", code); std::snprintf(file, sizeof file, "expansions/pics/%d.jpg", code);
irr::video::ITexture* img = GetTextureFromFile(file, width, height); irr::video::ITexture* img = GetTextureFromFile(file, width, height);
if(img == nullptr) { if(img == nullptr) {
snprintf(file, sizeof file, "pics/%d.jpg", code); std::snprintf(file, sizeof file, "pics/%d.jpg", code);
img = GetTextureFromFile(file, width, height); img = GetTextureFromFile(file, width, height);
} }
if(img == nullptr && !mainGame->gameConf.use_image_scale) { if(img == nullptr && !mainGame->gameConf.use_image_scale) {
...@@ -261,10 +261,10 @@ irr::video::ITexture* ImageManager::GetBigPicture(int code, float zoom) { ...@@ -261,10 +261,10 @@ irr::video::ITexture* ImageManager::GetBigPicture(int code, float zoom) {
} }
irr::video::ITexture* texture; irr::video::ITexture* texture;
char file[256]; char file[256];
snprintf(file, sizeof file, "expansions/pics/%d.jpg", code); std::snprintf(file, sizeof file, "expansions/pics/%d.jpg", code);
irr::video::IImage* srcimg = driver->createImageFromFile(file); irr::video::IImage* srcimg = driver->createImageFromFile(file);
if(srcimg == nullptr) { if(srcimg == nullptr) {
snprintf(file, sizeof file, "pics/%d.jpg", code); std::snprintf(file, sizeof file, "pics/%d.jpg", code);
srcimg = driver->createImageFromFile(file); srcimg = driver->createImageFromFile(file);
} }
if(srcimg == nullptr) { if(srcimg == nullptr) {
...@@ -290,18 +290,18 @@ int ImageManager::LoadThumbThread() { ...@@ -290,18 +290,18 @@ int ImageManager::LoadThumbThread() {
imageManager.tThumbLoadingCodes.pop(); imageManager.tThumbLoadingCodes.pop();
imageManager.tThumbLoadingMutex.unlock(); imageManager.tThumbLoadingMutex.unlock();
char file[256]; char file[256];
snprintf(file, sizeof file, "expansions/pics/thumbnail/%d.jpg", code); std::snprintf(file, sizeof file, "expansions/pics/thumbnail/%d.jpg", code);
irr::video::IImage* img = imageManager.driver->createImageFromFile(file); irr::video::IImage* img = imageManager.driver->createImageFromFile(file);
if(img == nullptr) { if(img == nullptr) {
snprintf(file, sizeof file, "pics/thumbnail/%d.jpg", code); std::snprintf(file, sizeof file, "pics/thumbnail/%d.jpg", code);
img = imageManager.driver->createImageFromFile(file); img = imageManager.driver->createImageFromFile(file);
} }
if(img == nullptr && mainGame->gameConf.use_image_scale) { if(img == nullptr && mainGame->gameConf.use_image_scale) {
snprintf(file, sizeof file, "expansions/pics/%d.jpg", code); std::snprintf(file, sizeof file, "expansions/pics/%d.jpg", code);
img = imageManager.driver->createImageFromFile(file); img = imageManager.driver->createImageFromFile(file);
} }
if(img == nullptr && mainGame->gameConf.use_image_scale) { if(img == nullptr && mainGame->gameConf.use_image_scale) {
snprintf(file, sizeof file, "pics/%d.jpg", code); std::snprintf(file, sizeof file, "pics/%d.jpg", code);
img = imageManager.driver->createImageFromFile(file); img = imageManager.driver->createImageFromFile(file);
} }
if(img != nullptr) { if(img != nullptr) {
...@@ -346,7 +346,7 @@ irr::video::ITexture* ImageManager::GetTextureThumb(int code) { ...@@ -346,7 +346,7 @@ irr::video::ITexture* ImageManager::GetTextureThumb(int code) {
if(lit != tThumbLoading.end()) { if(lit != tThumbLoading.end()) {
if(lit->second != nullptr) { if(lit->second != nullptr) {
char file[256]; char file[256];
snprintf(file, sizeof file, "pics/thumbnail/%d.jpg", code); std::snprintf(file, sizeof file, "pics/thumbnail/%d.jpg", code);
irr::video::ITexture* texture = driver->addTexture(file, lit->second); // textures must be added in the main thread due to OpenGL irr::video::ITexture* texture = driver->addTexture(file, lit->second); // textures must be added in the main thread due to OpenGL
lit->second->drop(); lit->second->drop();
tThumb[code] = texture; tThumb[code] = texture;
...@@ -379,18 +379,18 @@ irr::video::ITexture* ImageManager::GetTextureField(int code) { ...@@ -379,18 +379,18 @@ irr::video::ITexture* ImageManager::GetTextureField(int code) {
auto tit = tFields.find(code); auto tit = tFields.find(code);
if(tit == tFields.end()) { if(tit == tFields.end()) {
char file[256]; char file[256];
snprintf(file, sizeof file, "expansions/pics/field/%d.png", code); std::snprintf(file, sizeof file, "expansions/pics/field/%d.png", code);
irr::video::ITexture* img = GetTextureFromFile(file, 512 * mainGame->xScale, 512 * mainGame->yScale); irr::video::ITexture* img = GetTextureFromFile(file, 512 * mainGame->xScale, 512 * mainGame->yScale);
if(img == nullptr) { if(img == nullptr) {
snprintf(file, sizeof file, "expansions/pics/field/%d.jpg", code); std::snprintf(file, sizeof file, "expansions/pics/field/%d.jpg", code);
img = GetTextureFromFile(file, 512 * mainGame->xScale, 512 * mainGame->yScale); img = GetTextureFromFile(file, 512 * mainGame->xScale, 512 * mainGame->yScale);
} }
if(img == nullptr) { if(img == nullptr) {
snprintf(file, sizeof file, "pics/field/%d.png", code); std::snprintf(file, sizeof file, "pics/field/%d.png", code);
img = GetTextureFromFile(file, 512 * mainGame->xScale, 512 * mainGame->yScale); img = GetTextureFromFile(file, 512 * mainGame->xScale, 512 * mainGame->yScale);
} }
if(img == nullptr) { if(img == nullptr) {
snprintf(file, sizeof file, "pics/field/%d.jpg", code); std::snprintf(file, sizeof file, "pics/field/%d.jpg", code);
img = GetTextureFromFile(file, 512 * mainGame->xScale, 512 * mainGame->yScale); img = GetTextureFromFile(file, 512 * mainGame->xScale, 512 * mainGame->yScale);
if(img == nullptr) { if(img == nullptr) {
tFields[code] = nullptr; tFields[code] = nullptr;
......
...@@ -396,9 +396,9 @@ bool MenuHandler::OnEvent(const irr::SEvent& event) { ...@@ -396,9 +396,9 @@ bool MenuHandler::OnEvent(const irr::SEvent& event) {
int flag = 0; int flag = 0;
flag += (mainGame->chkBotHand->isChecked() ? 0x1 : 0); flag += (mainGame->chkBotHand->isChecked() ? 0x1 : 0);
char arg2[8]; char arg2[8];
snprintf(arg2, sizeof arg2, "%d", flag); std::snprintf(arg2, sizeof arg2, "%d", flag);
char arg3[8]; char arg3[8];
snprintf(arg3, sizeof arg3, "%d", mainGame->gameConf.serverport); std::snprintf(arg3, sizeof arg3, "%d", mainGame->gameConf.serverport);
execl("./bot", "bot", arg1, arg2, arg3, nullptr); execl("./bot", "bot", arg1, arg2, arg3, nullptr);
exit(0); exit(0);
} else { } else {
......
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