Skip to content

Commit

Permalink
safety modification to reader and dictionary. The program halts if re…
Browse files Browse the repository at this point in the history
…ader is not opened and readDictionary is called. Same thing happens (halt) when non existing schema was requested from dictionary.
  • Loading branch information
gavalian committed Feb 10, 2022
1 parent e86f779 commit ff32db9
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 5 deletions.
8 changes: 7 additions & 1 deletion hipo4/dictionary.h
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,13 @@ class schema {
std::vector<std::string> getSchemaList();
void addSchema(schema sc){ factory[sc.getName()] = sc;}
bool hasSchema(const char *name) { return (factory.count(name)!=0);}
schema &getSchema(const char *name){ return factory[name];}
schema &getSchema(const char *name){
if(factory.count(name)==0){
printf("\n\nhipo::dictionary (ERROR) schema {%s} does not exist... exiting\n\n",name);
exit(0);
}
return factory[name];
}
bool parse(const char *schemaString);
void show();
};
Expand Down
4 changes: 4 additions & 0 deletions hipo4/reader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,10 @@ void reader::getStructureNoCopy(hipo::structure &structure,int group, int item)
* @param dict - reference to dictionary object.
*/
void reader::readDictionary(hipo::dictionary &dict){
if(inputStream.is_open()==false){
printf("\n\nhipo::reader (ERROR) file is not open.... exiting...\n\n");
exit(0);
}
long position = header.headerLength*4;
hipo::record dictRecord;
dictRecord.readRecord(inputStream,position,0);
Expand Down
10 changes: 6 additions & 4 deletions hipo4/reader.h
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,8 @@

namespace hipo {

typedef struct fileHeader_t {
// typedef struct fileHeader_t {
struct fileHeader_t {
int uniqueid{};
int filenumber{};
int headerLength{}; // in words (usually 14)
Expand All @@ -131,16 +132,17 @@ namespace hipo {
long userRegister{};
long trailerPosition{};
long firstRecordPosition{};
} fileHeader_t;
};// fileHeader_t;


typedef struct recordInfo_t {
// typedef struct recordInfo_t {
struct recordInfo_t {
long recordPosition{};
int recordLength{};
int recordEntries{};
long userWordOne{};
long userWordTwo{};
} recordInfo_t;
};// recordInfo_t;


/**
Expand Down

1 comment on commit ff32db9

@gavalian
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tag 1.5 includes :

  1. fixes in file header structure (removed typedef from struct definition)
  2. reader::readDictionary now exits (halts the program) is it's called without opening the file
  3. dictionary::getSchema exits (halts the program) is non exiting schema is requested. Users should first call dictionary::hasSchema then make decision if the bank does not exist.

Please sign in to comment.