Commit b05e0c96 authored by Chen Bill's avatar Chen Bill

use wcsncpy

parent 6a2deaac
...@@ -115,14 +115,16 @@ int main(int argc, char* argv[]) { ...@@ -115,14 +115,16 @@ int main(int argc, char* argv[]) {
++i; ++i;
if(i < wargc) { if(i < wargc) {
deckCategorySpecified = true; deckCategorySpecified = true;
wcscpy(ygo::mainGame->gameConf.lastcategory, wargv[i]); wcsncpy(ygo::mainGame->gameConf.lastcategory, wargv[i], sizeof ygo::mainGame->gameConf.lastcategory / sizeof ygo::mainGame->gameConf.lastcategory[0]);
BufferIO::NullTerminate(ygo::mainGame->gameConf.lastcategory);
} }
} else if(!wcscmp(wargv[i], L"-d")) { // Deck } else if(!wcscmp(wargv[i], L"-d")) { // Deck
++i; ++i;
if(!deckCategorySpecified) if(!deckCategorySpecified)
ygo::mainGame->gameConf.lastcategory[0] = 0; ygo::mainGame->gameConf.lastcategory[0] = 0;
if(i + 1 < wargc) { // select deck if(i + 1 < wargc) { // select deck
wcscpy(ygo::mainGame->gameConf.lastdeck, wargv[i]); wcsncpy(ygo::mainGame->gameConf.lastdeck, wargv[i], sizeof ygo::mainGame->gameConf.lastdeck / sizeof ygo::mainGame->gameConf.lastdeck[0]);
BufferIO::NullTerminate(ygo::mainGame->gameConf.lastdeck);
continue; continue;
} else { // open deck } else { // open deck
exit_on_return = !keep_on_return; exit_on_return = !keep_on_return;
...@@ -135,7 +137,8 @@ int main(int argc, char* argv[]) { ...@@ -135,7 +137,8 @@ int main(int argc, char* argv[]) {
myswprintf(open_file_name, L"%ls/%ls", ygo::mainGame->gameConf.lastcategory, wargv[i]); myswprintf(open_file_name, L"%ls/%ls", ygo::mainGame->gameConf.lastcategory, wargv[i]);
#endif #endif
} else { } else {
wcscpy(open_file_name, wargv[i]); wcsncpy(open_file_name, wargv[i], sizeof open_file_name / sizeof open_file_name[0]);
BufferIO::NullTerminate(open_file_name);
} }
} }
ClickButton(ygo::mainGame->btnDeckEdit); ClickButton(ygo::mainGame->btnDeckEdit);
...@@ -156,7 +159,8 @@ int main(int argc, char* argv[]) { ...@@ -156,7 +159,8 @@ int main(int argc, char* argv[]) {
++i; ++i;
if(i < wargc) { if(i < wargc) {
open_file = true; open_file = true;
wcscpy(open_file_name, wargv[i]); wcsncpy(open_file_name, wargv[i], sizeof open_file_name / sizeof open_file_name[0]);
BufferIO::NullTerminate(open_file_name);
} }
ClickButton(ygo::mainGame->btnReplayMode); ClickButton(ygo::mainGame->btnReplayMode);
if(open_file) if(open_file)
...@@ -167,7 +171,8 @@ int main(int argc, char* argv[]) { ...@@ -167,7 +171,8 @@ int main(int argc, char* argv[]) {
++i; ++i;
if(i < wargc) { if(i < wargc) {
open_file = true; open_file = true;
wcscpy(open_file_name, wargv[i]); wcsncpy(open_file_name, wargv[i], sizeof open_file_name / sizeof open_file_name[0]);
BufferIO::NullTerminate(open_file_name);
} }
ClickButton(ygo::mainGame->btnSingleMode); ClickButton(ygo::mainGame->btnSingleMode);
if(open_file) if(open_file)
...@@ -177,14 +182,16 @@ int main(int argc, char* argv[]) { ...@@ -177,14 +182,16 @@ int main(int argc, char* argv[]) {
wchar_t* pstrext = wargv[1] + wcslen(wargv[1]) - 4; wchar_t* pstrext = wargv[1] + wcslen(wargv[1]) - 4;
if(!mywcsncasecmp(pstrext, L".ydk", 4)) { if(!mywcsncasecmp(pstrext, L".ydk", 4)) {
open_file = true; open_file = true;
wcscpy(open_file_name, wargv[i]); wcsncpy(open_file_name, wargv[i], sizeof open_file_name / sizeof open_file_name[0]);
BufferIO::NullTerminate(open_file_name);
exit_on_return = !keep_on_return; exit_on_return = !keep_on_return;
ClickButton(ygo::mainGame->btnDeckEdit); ClickButton(ygo::mainGame->btnDeckEdit);
break; break;
} }
if(!mywcsncasecmp(pstrext, L".yrp", 4)) { if(!mywcsncasecmp(pstrext, L".yrp", 4)) {
open_file = true; open_file = true;
wcscpy(open_file_name, wargv[i]); wcsncpy(open_file_name, wargv[i], sizeof open_file_name / sizeof open_file_name[0]);
BufferIO::NullTerminate(open_file_name);
exit_on_return = !keep_on_return; exit_on_return = !keep_on_return;
ClickButton(ygo::mainGame->btnReplayMode); ClickButton(ygo::mainGame->btnReplayMode);
ClickButton(ygo::mainGame->btnLoadReplay); ClickButton(ygo::mainGame->btnLoadReplay);
......
...@@ -448,7 +448,8 @@ bool MenuHandler::OnEvent(const irr::SEvent& event) { ...@@ -448,7 +448,8 @@ bool MenuHandler::OnEvent(const irr::SEvent& event) {
wcsncpy(deck_name, dash + 1, 256); wcsncpy(deck_name, dash + 1, 256);
for(size_t i = 0; i < mainGame->cbDBDecks->getItemCount(); ++i) { for(size_t i = 0; i < mainGame->cbDBDecks->getItemCount(); ++i) {
if(!wcscmp(mainGame->cbDBDecks->getItem(i), deck_name)) { if(!wcscmp(mainGame->cbDBDecks->getItem(i), deck_name)) {
wcscpy(mainGame->gameConf.lastdeck, deck_name); wcsncpy(mainGame->gameConf.lastdeck, deck_name, sizeof mainGame->gameConf.lastdeck / sizeof mainGame->gameConf.lastdeck[0]);
BufferIO::NullTerminate(mainGame->gameConf.lastdeck);
mainGame->cbDBDecks->setSelected(i); mainGame->cbDBDecks->setSelected(i);
break; break;
} }
...@@ -456,7 +457,8 @@ bool MenuHandler::OnEvent(const irr::SEvent& event) { ...@@ -456,7 +457,8 @@ bool MenuHandler::OnEvent(const irr::SEvent& event) {
} else { // only deck name } else { // only deck name
for(size_t i = 0; i < mainGame->cbDBDecks->getItemCount(); ++i) { for(size_t i = 0; i < mainGame->cbDBDecks->getItemCount(); ++i) {
if(!wcscmp(mainGame->cbDBDecks->getItem(i), open_file_name)) { if(!wcscmp(mainGame->cbDBDecks->getItem(i), open_file_name)) {
wcscpy(mainGame->gameConf.lastdeck, open_file_name); wcsncpy(mainGame->gameConf.lastdeck, open_file_name, sizeof mainGame->gameConf.lastdeck / sizeof mainGame->gameConf.lastdeck[0]);
BufferIO::NullTerminate(mainGame->gameConf.lastdeck);
mainGame->cbDBDecks->setSelected(i); mainGame->cbDBDecks->setSelected(i);
break; break;
} }
......
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