Commit 9d4496f7 authored by Chen Bill's avatar Chen Bill Committed by GitHub

DeckManager: fix LoadLFListSingle, LoadDeck (std::istringstream) (#2699)

* fix DeckManager::LoadLFListSingle

* fix DeckManager::LoadDeck (std::istringstream)

* typos

* fix conversion

* workaround
parent b71023f2
......@@ -3,6 +3,9 @@
#define _IRR_STATIC_LIB_
#define IRR_COMPILE_WITH_DX9_DEV_PACK
#include <cerrno>
#ifdef _WIN32
#define NOMINMAX
......@@ -22,7 +25,6 @@
#else //_WIN32
#include <errno.h>
#include <netinet/in.h>
#include <sys/socket.h>
#include <sys/ioctl.h>
......
......@@ -14,7 +14,7 @@ void DeckManager::LoadLFListSingle(const char* path) {
char linebuf[256]{};
wchar_t strBuffer[256]{};
if(fp) {
while(std::fgets(linebuf, 256, fp)) {
while(std::fgets(linebuf, sizeof linebuf, fp)) {
if(linebuf[0] == '#')
continue;
if(linebuf[0] == '!') {
......@@ -28,16 +28,16 @@ void DeckManager::LoadLFListSingle(const char* path) {
cur = _lfList.rbegin();
continue;
}
if (cur == _lfList.rend())
continue;
int code = 0;
int count = -1;
if (std::sscanf(linebuf, "%d %d", &code, &count) != 2)
if (std::sscanf(linebuf, "%9d%*[ ]%9d", &code, &count) != 2)
continue;
if (code <= 0 || code > MAX_CARD_ID)
continue;
if (count < 0 || count > 2)
continue;
if (cur == _lfList.rend())
continue;
unsigned int hcode = code;
cur->content[code] = count;
cur->hash = cur->hash ^ ((hcode << 18) | (hcode >> 14)) ^ ((hcode << (27 + count)) | (hcode >> (5 - count)));
......@@ -197,7 +197,9 @@ int DeckManager::LoadDeck(Deck& deck, std::istringstream& deckStream, bool is_pa
}
if (linebuf[0] < '0' || linebuf[0] > '9')
continue;
code = std::stoi(linebuf);
code = strtol(linebuf.c_str(), nullptr, 10);
if (errno == ERANGE)
continue;
cardlist[ct++] = code;
if (is_side)
++sidec;
......
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