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) {
char strbuf[TEXT_LINE_SIZE]{};
int value{};
wchar_t strBuffer[4096]{};
if (sscanf(linebuf, "!%63s", strbuf) != 1)
if (std::sscanf(linebuf, "!%63s", strbuf) != 1)
return;
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;
BufferIO::DecodeUTF8(strbuf, strBuffer);
_sysStrings[value] = strBuffer;
} 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;
BufferIO::DecodeUTF8(strbuf, strBuffer);
_victoryStrings[value] = strBuffer;
} 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;
BufferIO::DecodeUTF8(strbuf, strBuffer);
_counterStrings[value] = strBuffer;
} else if(!std::strcmp(strbuf, "setname")) {
//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;
BufferIO::DecodeUTF8(strbuf, strBuffer);
_setnameStrings[value] = strBuffer;
......
......@@ -30,7 +30,7 @@ void DeckManager::LoadLFListSingle(const char* path) {
}
int code = 0;
int count = -1;
if (sscanf(linebuf, "%d %d", &code, &count) != 2)
if (std::sscanf(linebuf, "%d %d", &code, &count) != 2)
continue;
if (code <= 0 || code > MAX_CARD_ID)
continue;
......
......@@ -1285,17 +1285,17 @@ void Game::RefreshBot() {
continue;
if(linebuf[0] == '!') {
BotInfo newinfo;
if (sscanf(linebuf, "!%240[^\n]", strbuf) != 1)
if (std::sscanf(linebuf, "!%240[^\n]", strbuf) != 1)
continue;
BufferIO::DecodeUTF8(strbuf, newinfo.name);
if (!std::fgets(linebuf, 256, fp))
break;
if (sscanf(linebuf, "%240[^\n]", strbuf) != 1)
if (std::sscanf(linebuf, "%240[^\n]", strbuf) != 1)
continue;
BufferIO::DecodeUTF8(strbuf, newinfo.command);
if (!std::fgets(linebuf, 256, fp))
break;
if (sscanf(linebuf, "%240[^\n]", strbuf) != 1)
if (std::sscanf(linebuf, "%240[^\n]", strbuf) != 1)
continue;
BufferIO::DecodeUTF8(strbuf, newinfo.desc);
if (!std::fgets(linebuf, 256, fp))
......@@ -1336,7 +1336,7 @@ void Game::LoadConfig() {
char strbuf[64]{};
char valbuf[960]{};
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;
if(!std::strcmp(strbuf, "antialias")) {
gameConf.antialias = strtol(valbuf, nullptr, 10);
......@@ -1349,7 +1349,7 @@ void Game::LoadConfig() {
enable_log = val & 0xff;
} else if(!std::strcmp(strbuf, "textfont")) {
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;
gameConf.textfontsize = textfontsize;
BufferIO::DecodeUTF8(valbuf, gameConf.textfont);
......@@ -1447,7 +1447,7 @@ void Game::LoadConfig() {
#endif
} else {
// options allowing multiple words
if (sscanf(linebuf, "%63s = %959[^\n]", strbuf, valbuf) != 2)
if (std::sscanf(linebuf, "%63s = %959[^\n]", strbuf, valbuf) != 2)
continue;
if (!std::strcmp(strbuf, "nickname")) {
BufferIO::DecodeUTF8(valbuf, gameConf.nickname);
......@@ -1715,7 +1715,7 @@ void Game::AddDebugMsg(const char* msg) {
}
if (enable_log & 0x2) {
char msgbuf[1040];
snprintf(msgbuf, sizeof msgbuf, "[Script Error]: %s", msg);
std::snprintf(msgbuf, sizeof msgbuf, "[Script Error]: %s", msg);
ErrorLog(msgbuf);
}
}
......
......@@ -234,10 +234,10 @@ irr::video::ITexture* ImageManager::GetTexture(int code, bool fit) {
auto tit = tMap[fit ? 1 : 0].find(code);
if(tit == tMap[fit ? 1 : 0].end()) {
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);
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);
}
if(img == nullptr && !mainGame->gameConf.use_image_scale) {
......@@ -261,10 +261,10 @@ irr::video::ITexture* ImageManager::GetBigPicture(int code, float zoom) {
}
irr::video::ITexture* texture;
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);
if(srcimg == nullptr) {
snprintf(file, sizeof file, "pics/%d.jpg", code);
std::snprintf(file, sizeof file, "pics/%d.jpg", code);
srcimg = driver->createImageFromFile(file);
}
if(srcimg == nullptr) {
......@@ -290,18 +290,18 @@ int ImageManager::LoadThumbThread() {
imageManager.tThumbLoadingCodes.pop();
imageManager.tThumbLoadingMutex.unlock();
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);
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);
}
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);
}
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);
}
if(img != nullptr) {
......@@ -346,7 +346,7 @@ irr::video::ITexture* ImageManager::GetTextureThumb(int code) {
if(lit != tThumbLoading.end()) {
if(lit->second != nullptr) {
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
lit->second->drop();
tThumb[code] = texture;
......@@ -379,18 +379,18 @@ irr::video::ITexture* ImageManager::GetTextureField(int code) {
auto tit = tFields.find(code);
if(tit == tFields.end()) {
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);
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);
}
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);
}
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);
if(img == nullptr) {
tFields[code] = nullptr;
......
......@@ -396,9 +396,9 @@ bool MenuHandler::OnEvent(const irr::SEvent& event) {
int flag = 0;
flag += (mainGame->chkBotHand->isChecked() ? 0x1 : 0);
char arg2[8];
snprintf(arg2, sizeof arg2, "%d", flag);
std::snprintf(arg2, sizeof arg2, "%d", flag);
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);
exit(0);
} 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