summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2011-06-14 23:59:44 +0300
committerAndrei Karas <akaras@inbox.ru>2011-06-14 23:59:44 +0300
commitbf235a610f10301471ca83ce153511d63b3fa9f9 (patch)
tree807def519ff2dd564cdb23a4c05cd9a79338eab2
parentbf9bccc30a186e338f96c230a4f63cc924c77bd8 (diff)
downloadmanaplus-bf235a610f10301471ca83ce153511d63b3fa9f9.tar.gz
manaplus-bf235a610f10301471ca83ce153511d63b3fa9f9.tar.bz2
manaplus-bf235a610f10301471ca83ce153511d63b3fa9f9.tar.xz
manaplus-bf235a610f10301471ca83ce153511d63b3fa9f9.zip
Add missing checks.
-rw-r--r--src/client.cpp43
-rw-r--r--src/gui/chatwindow.cpp26
-rw-r--r--src/gui/shopwindow.cpp5
-rw-r--r--src/map.cpp5
-rw-r--r--src/resources/resourcemanager.cpp3
5 files changed, 55 insertions, 27 deletions
diff --git a/src/client.cpp b/src/client.cpp
index f20c674d9..bba55a960 100644
--- a/src/client.cpp
+++ b/src/client.cpp
@@ -1827,21 +1827,24 @@ void Client::initTradeFilter()
if (stat(tradeListName.c_str(), &statbuf) || !S_ISREG(statbuf.st_mode))
{
tradeFile.open(tradeListName.c_str(), std::ios::out);
- tradeFile << ": sell" << std::endl;
- tradeFile << ": buy" << std::endl;
- tradeFile << ": trade" << std::endl;
- tradeFile << "i sell" << std::endl;
- tradeFile << "i buy" << std::endl;
- tradeFile << "i trade" << std::endl;
- tradeFile << "i trading" << std::endl;
- tradeFile << "i am buy" << std::endl;
- tradeFile << "i am sell" << std::endl;
- tradeFile << "i am trade" << std::endl;
- tradeFile << "i am trading" << std::endl;
- tradeFile << "i'm buy" << std::endl;
- tradeFile << "i'm sell" << std::endl;
- tradeFile << "i'm trade" << std::endl;
- tradeFile << "i'm trading" << std::endl;
+ if (tradeFile.is_open())
+ {
+ tradeFile << ": sell" << std::endl;
+ tradeFile << ": buy" << std::endl;
+ tradeFile << ": trade" << std::endl;
+ tradeFile << "i sell" << std::endl;
+ tradeFile << "i buy" << std::endl;
+ tradeFile << "i trade" << std::endl;
+ tradeFile << "i trading" << std::endl;
+ tradeFile << "i am buy" << std::endl;
+ tradeFile << "i am sell" << std::endl;
+ tradeFile << "i am trade" << std::endl;
+ tradeFile << "i am trading" << std::endl;
+ tradeFile << "i'm buy" << std::endl;
+ tradeFile << "i'm sell" << std::endl;
+ tradeFile << "i'm trade" << std::endl;
+ tradeFile << "i'm trading" << std::endl;
+ }
tradeFile.close();
}
}
@@ -1938,8 +1941,11 @@ void Client::initPacketLimiter()
inPacketFile.open(packetLimitsName.c_str(), std::ios::in);
char line[101];
- if (!inPacketFile.getline(line, 100))
+ if (!inPacketFile.is_open() || !inPacketFile.getline(line, 100))
+ {
+ inPacketFile.close();
return;
+ }
int ver = atoi(line);
@@ -1962,6 +1968,11 @@ void Client::writePacketLimits(std::string packetLimitsName)
{
std::ofstream outPacketFile;
outPacketFile.open(packetLimitsName.c_str(), std::ios::out);
+ if (!outPacketFile.is_open())
+ {
+ outPacketFile.close();
+ return;
+ }
outPacketFile << "2" << std::endl;
for (int f = 0; f < PACKET_SIZE; f ++)
{
diff --git a/src/gui/chatwindow.cpp b/src/gui/chatwindow.cpp
index a575b7054..1829a55ba 100644
--- a/src/gui/chatwindow.cpp
+++ b/src/gui/chatwindow.cpp
@@ -1304,12 +1304,15 @@ void ChatWindow::initTradeFilter()
if (!stat(tradeListName.c_str(), &statbuf) && S_ISREG(statbuf.st_mode))
{
tradeFile.open(tradeListName.c_str(), std::ios::in);
- char line[100];
- while (tradeFile.getline(line, 100))
+ if (tradeFile.is_open())
{
- std::string str = line;
- if (!str.empty())
- mTradeFilter.push_back(str);
+ char line[100];
+ while (tradeFile.getline(line, 100))
+ {
+ std::string str = line;
+ if (!str.empty())
+ mTradeFilter.push_back(str);
+ }
}
tradeFile.close();
}
@@ -1466,12 +1469,15 @@ void ChatWindow::loadCustomList()
if (!stat(listName.c_str(), &statbuf) && S_ISREG(statbuf.st_mode))
{
listFile.open(listName.c_str(), std::ios::in);
- char line[101];
- while (listFile.getline(line, 100))
+ if (listFile.is_open())
{
- std::string str = line;
- if (!str.empty())
- mCustomWords.push_back(str);
+ char line[101];
+ while (listFile.getline(line, 100))
+ {
+ std::string str = line;
+ if (!str.empty())
+ mCustomWords.push_back(str);
+ }
}
listFile.close();
}
diff --git a/src/gui/shopwindow.cpp b/src/gui/shopwindow.cpp
index 7578cbf7b..fdfea5d15 100644
--- a/src/gui/shopwindow.cpp
+++ b/src/gui/shopwindow.cpp
@@ -312,6 +312,11 @@ void ShopWindow::loadList()
if (!stat(shopListName.c_str(), &statbuf) && S_ISREG(statbuf.st_mode))
{
shopFile.open(shopListName.c_str(), std::ios::in);
+ if (!shopFile.is_open())
+ {
+ shopFile.close();
+ return;
+ }
char line[101];
while (shopFile.getline(line, 100))
{
diff --git a/src/map.cpp b/src/map.cpp
index 2c8dc90e2..773e6ecdc 100644
--- a/src/map.cpp
+++ b/src/map.cpp
@@ -1296,6 +1296,11 @@ void Map::addExtraLayer()
{
std::ifstream mapFile;
mapFile.open(mapFileName.c_str(), std::ios::in);
+ if (!mapFile.is_open())
+ {
+ mapFile.close();
+ return;
+ }
char line[201];
std::string buf;
while (mapFile.getline(line, 200))
diff --git a/src/resources/resourcemanager.cpp b/src/resources/resourcemanager.cpp
index 96902cb4c..410611fc3 100644
--- a/src/resources/resourcemanager.cpp
+++ b/src/resources/resourcemanager.cpp
@@ -690,7 +690,8 @@ void ResourceManager::saveTextFile(std::string path, std::string name,
std::string fileName = path + "/" + name;
file.open(fileName.c_str(), std::ios::out);
- file << text << std::endl;
+ if (file.is_open())
+ file << text << std::endl;
file.close();
}
}