Skip to content

Commit

Permalink
[#2] Close filestream in INI constructor on error or parsing done
Browse files Browse the repository at this point in the history
Signed-off-by: Clovis Durand <cd.clovel19@gmail.com>
  • Loading branch information
Clovel committed Mar 3, 2020
1 parent b2e5fdc commit d5422ce
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions generator/src/INI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ INI::INI(const std::string &pFile) {
/* Something went wrong if you are here */
std::cerr << "[ERROR] <INI::INI> Unknown parsing error at line "
<< lLineCount << " !" << std::endl;
mFileStream.close();
throw INIException();
}

Expand All @@ -164,6 +165,7 @@ INI::INI(const std::string &pFile) {
/* End og tag not found, this INI file is corrupt */
std::cerr << "[ERROR] <INI::INI> Found unclosed section tag at line "
<< lLineCount << " !" << std::endl;
mFileStream.close();
throw INIException();
}

Expand All @@ -178,6 +180,7 @@ INI::INI(const std::string &pFile) {
if(2U != lKeyValue.size()) {
std::cerr << "[ERROR] <INI::INI> Invalid key/name pair at line "
<< lLineCount << " !" << std::endl;
mFileStream.close();
throw INIException();
}

Expand All @@ -189,12 +192,14 @@ INI::INI(const std::string &pFile) {
if(std::string::npos != lKey.find(' ')) {
std::cerr << "[ERROR] <INI::INI> Space in key at line "
<< lLineCount << std::endl;
mFileStream.close();
throw INIException();
}

if(std::string::npos != lValue.find(' ')) {
std::cerr << "[ERROR] <INI::INI> Space in value at line "
<< lLineCount << std::endl;
mFileStream.close();
throw INIException();
}

Expand All @@ -204,6 +209,7 @@ INI::INI(const std::string &pFile) {
}

std::cout << "[INFO ] <INI::INI> Parsed INI file " << pFile << " successfully !" << std::endl;
mFileStream.close();
}

INI::~INI() {
Expand Down

0 comments on commit d5422ce

Please sign in to comment.