From bf235a610f10301471ca83ce153511d63b3fa9f9 Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Tue, 14 Jun 2011 23:59:44 +0300 Subject: Add missing checks. --- src/client.cpp | 43 +++++++++++++++++++++++++++---------------- 1 file changed, 27 insertions(+), 16 deletions(-) (limited to 'src/client.cpp') 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 ++) { -- cgit v1.2.3-70-g09d2