Skip to content

Commit 379c335

Browse files
committed
improve error handling
1 parent 1cd71d2 commit 379c335

File tree

6 files changed

+21
-10
lines changed

6 files changed

+21
-10
lines changed

src/cllazyfile/lazyDataSectionReader.cc

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,5 @@ lazyDataSectionReader::lazyDataSectionReader( lazyFileReader * parent, std::ifst
77
_sectionID = _lazyFile->getInstMgr()->registerDataSection( this );
88
_sectionIdentifier = "";
99
std::cerr << "FIXME set _sectionIdentifier" << std::endl;
10-
error = true; std::cerr << "FIXME read file, set `error` correctly, ..." << std::endl;
11-
10+
_error = false;
1211
}

src/cllazyfile/lazyDataSectionReader.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
*/
2020
class lazyDataSectionReader: public sectionReader {
2121
protected:
22-
bool error, completelyLoaded;
22+
bool _error, _completelyLoaded;
2323
// lazyFileReader* parent;
2424
std::string _sectionIdentifier;
2525

@@ -28,7 +28,7 @@ class lazyDataSectionReader: public sectionReader {
2828
public:
2929
virtual ~lazyDataSectionReader() {}
3030
bool success() {
31-
return !error;
31+
return !_error;
3232
}
3333
// SDAI_Application_instance* getRealInstance( std::streampos start, std::streampos end );
3434
};

src/cllazyfile/lazyInstMgr.cc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ lazyInstMgr::lazyInstMgr() {
66
_headerRegistry = new Registry( HeaderSchemaInit );
77
_lazyInstanceCount = 0;
88
_longestTypeNameLen = 0;
9+
_errors = new ErrorDescriptor();
910
}
1011

1112
sectionID lazyInstMgr::registerDataSection( lazyDataSectionReader * sreader ) {
@@ -38,3 +39,8 @@ unsigned long lazyInstMgr::getNumTypes() /*const*/ {
3839
}
3940
return n ;
4041
}
42+
43+
void lazyInstMgr::openFile( std::string fname ) {
44+
// lazyFileReader adds itself to the file list - good idea or bad?
45+
/*_files.push_back( */new lazyFileReader( fname, this ) /*)*/;
46+
}

src/cllazyfile/lazyInstMgr.h

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ class lazyInstMgr {
4040
lazyFileReaderVec_t _files;
4141

4242
Registry * _headerRegistry, * _mainRegistry;
43+
ErrorDescriptor * _errors;
4344

4445
unsigned long _lazyInstanceCount;
4546
int _longestTypeNameLen;
@@ -49,13 +50,9 @@ class lazyInstMgr {
4950
public:
5051
lazyInstMgr();
5152
void addSchema( void (*initFn) () ); //?
52-
void openFile( std::string fname ) {
53-
// lazyFileReader adds itself to the file list - good idea or bad?
54-
/*_files.push_back( */new lazyFileReader( fname, this ) /*)*/;
55-
}
53+
void openFile( std::string fname );
5654

5755
void addLazyInstance( namedLazyInstance inst );
58-
void addDataSection( lazyDataSectionReader* d, lazyFileReader* f ); ///< only used by lazy file reader functions
5956

6057
/// FIXME don't return something that can be modified; also, template references will cause problems on windows
6158
instanceRefMMap_range getReferentInstances( instanceID id ) {
@@ -87,6 +84,10 @@ class lazyInstMgr {
8784
sectionID registerDataSection( lazyDataSectionReader * sreader );
8885
fileID registerLazyFile( lazyFileReader * freader );
8986

87+
ErrorDescriptor * getErrorDesc() {
88+
return _errors;
89+
}
90+
9091
/* TODO impliment these
9192
* void normalizeInstanceIds();
9293
* void eliminateDuplicates();

src/cllazyfile/lazyP21DataSectionReader.cc

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ lazyP21DataSectionReader::lazyP21DataSectionReader( lazyFileReader * parent, std
66
lazyDataSectionReader( parent, file, start ) {
77
findSectionStart();
88
findSectionEnd();
9+
if( _sectionEnd < 0 ) {
10+
_error = true;
11+
return;
12+
}
913
_file.seekg( _sectionStart );
1014
namedLazyInstance nl;
1115
while( nl = nextInstance(), ( nl.loc.end != nl.loc.begin ) ) {
@@ -46,7 +50,7 @@ const namedLazyInstance lazyP21DataSectionReader::nextInstance() {
4650
i.name = getDelimitedKeyword(";( /\\");
4751
i.loc.end = seekInstanceEnd();
4852

49-
if( i.loc.end >= _sectionEnd ) {
53+
if( ( i.loc.end < 0 ) || ( i.loc.end >= _sectionEnd ) ) {
5054
//invalid instance, so clear everything
5155
i.loc.end = i.loc.begin;
5256
delete i.name;

src/cllazyfile/lazyTypes.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ typedef struct {
3030
unmodified, simply copy it from the input file to the output file */
3131
} lazyInstanceLoc;
3232

33+
/// used when populating the instance type map \sa lazyInstMgr::_instanceTypeMMap
3334
typedef struct {
3435
lazyInstanceLoc loc;
3536
std::string * name;

0 commit comments

Comments
 (0)