fix.dat parser: check the stream's badbit flag after each I/O operation
- new private method FixesLoader::throwExceptionIfStreamError(); - call it whenever appropriate.
This commit is contained in:
parent
d9c879ff30
commit
30c8328399
2 changed files with 25 additions and 3 deletions
src/Navaids
|
@ -29,6 +29,7 @@
|
||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <string> // std::getline()
|
#include <string> // std::getline()
|
||||||
|
#include <errno.h>
|
||||||
|
|
||||||
#include <simgear/debug/logstream.hxx>
|
#include <simgear/debug/logstream.hxx>
|
||||||
#include <simgear/misc/sgstream.hxx>
|
#include <simgear/misc/sgstream.hxx>
|
||||||
|
@ -69,8 +70,10 @@ void FixesLoader::loadFixes(const SGPath& path)
|
||||||
}
|
}
|
||||||
|
|
||||||
// toss the first two lines of the file
|
// toss the first two lines of the file
|
||||||
|
for (int i = 0; i < 2; i++) {
|
||||||
in >> skipeol;
|
in >> skipeol;
|
||||||
in >> skipeol;
|
throwExceptionIfStreamError(in, path);
|
||||||
|
}
|
||||||
|
|
||||||
unsigned int lineNumber = 3;
|
unsigned int lineNumber = 3;
|
||||||
|
|
||||||
|
@ -109,6 +112,21 @@ void FixesLoader::loadFixes(const SGPath& path)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
throwExceptionIfStreamError(in, path);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void FixesLoader::throwExceptionIfStreamError(
|
||||||
|
const sg_gzifstream& input_stream, const SGPath& path)
|
||||||
|
{
|
||||||
|
if (input_stream.bad()) {
|
||||||
|
const std::string errMsg = simgear::strutils::error_string(errno);
|
||||||
|
|
||||||
|
SG_LOG(SG_NAVAID, SG_ALERT,
|
||||||
|
"Error while reading '" << path.utf8Str() << "': " << errMsg);
|
||||||
|
throw sg_io_exception("Error reading file (" + errMsg + ")",
|
||||||
|
sg_location(path));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
} // of namespace flightgear;
|
} // of namespace flightgear;
|
||||||
|
|
|
@ -28,6 +28,7 @@
|
||||||
#include <simgear/compiler.h>
|
#include <simgear/compiler.h>
|
||||||
|
|
||||||
class SGPath;
|
class SGPath;
|
||||||
|
class sg_gzifstream;
|
||||||
|
|
||||||
namespace flightgear
|
namespace flightgear
|
||||||
{
|
{
|
||||||
|
@ -43,6 +44,9 @@ namespace flightgear
|
||||||
void loadFixes(const SGPath& path);
|
void loadFixes(const SGPath& path);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
void throwExceptionIfStreamError(const sg_gzifstream& input_stream,
|
||||||
|
const SGPath& path);
|
||||||
|
|
||||||
NavDataCache* _cache;
|
NavDataCache* _cache;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue