Skip to content

Commit 29dcd24

Browse files
committed
Fix all(?) sites where ThrowException was missing
1 parent 0bda8b5 commit 29dcd24

File tree

2 files changed

+33
-45
lines changed

2 files changed

+33
-45
lines changed

src/libnml/inifile/inifile.cc

Lines changed: 26 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -116,28 +116,27 @@ IniFile::Find(int *result, StrIntPair *pPair,
116116
// in a buffer. Just pick a suitable ErrorCode for now.
117117
if (lineno)
118118
*lineno = 0;
119-
return(ERR_TAG_NOT_FOUND);
119+
return ThrowException(ERR_TAG_NOT_FOUND);
120120
}
121121

122122
if(sscanf(pStr, "%i", &tmp) == 1){
123123
*result = tmp;
124124
if (lineno)
125125
*lineno = lineNo;
126-
return(ERR_NONE);
126+
return ThrowException(ERR_NONE);
127127
}
128128

129129
while(pPair->pStr != NULL){
130130
if(strcasecmp(pStr, pPair->pStr) == 0){
131131
*result = pPair->value;
132132
if (lineno)
133133
*lineno = lineNo;
134-
return(ERR_NONE);
134+
return ThrowException(ERR_NONE);
135135
}
136136
pPair++;
137137
}
138138

139-
ThrowException(ERR_CONVERSION);
140-
return(ERR_CONVERSION);
139+
return ThrowException(ERR_CONVERSION);
141140
}
142141

143142

@@ -153,7 +152,7 @@ IniFile::Find(double *result, StrDoublePair *pPair,
153152
// in a buffer. Just pick a suitable ErrorCode for now.
154153
if (lineno)
155154
*lineno = 0;
156-
return(ERR_TAG_NOT_FOUND);
155+
return ThrowException(ERR_TAG_NOT_FOUND);
157156
}
158157

159158
if(sscanf(pStr, "%lf", &tmp) == 1){
@@ -162,21 +161,20 @@ IniFile::Find(double *result, StrDoublePair *pPair,
162161
*result = tmp;
163162
if (lineno)
164163
*lineno = lineNo;
165-
return(ERR_NONE);
164+
return ThrowException(ERR_NONE);
166165
}
167166

168167
while(pPair->pStr != NULL){
169168
if(strcasecmp(pStr, pPair->pStr) == 0){
170169
*result = pPair->value;
171170
if (lineno)
172171
*lineno = lineNo;
173-
return(ERR_NONE);
172+
return ThrowException(ERR_NONE);
174173
}
175174
pPair++;
176175
}
177176

178-
ThrowException(ERR_CONVERSION);
179-
return(ERR_CONVERSION);
177+
return ThrowException(ERR_CONVERSION);
180178
}
181179

182180

@@ -231,13 +229,11 @@ IniFile::Find(const char *_tag, const char *_section, int _num, int *lineno)
231229

232230
if (NULL == fgets(line, LINELEN + 1, fp)) {
233231
/* got to end of file without finding it */
234-
ThrowException(ERR_SECTION_NOT_FOUND);
235-
return(NULL);
232+
return ThrowException(ERR_SECTION_NOT_FOUND, nullptr);
236233
}
237234

238235
if(check_line_endings(line)) {
239-
ThrowException(ERR_CONVERSION);
240-
return(NULL);
236+
return ThrowException(ERR_SECTION_NOT_FOUND, nullptr);
241237
}
242238

243239
/* got a line */
@@ -272,13 +268,11 @@ IniFile::Find(const char *_tag, const char *_section, int _num, int *lineno)
272268
/* check for end of file */
273269
if (NULL == fgets(line, LINELEN + 1, (FILE *) fp)) {
274270
/* got to end of file without finding it */
275-
ThrowException(ERR_TAG_NOT_FOUND);
276-
return(NULL);
271+
return ThrowException(ERR_TAG_NOT_FOUND, nullptr);
277272
}
278273

279274
if(check_line_endings(line)) {
280-
ThrowException(ERR_CONVERSION);
281-
return(NULL);
275+
ThrowException(ERR_CONVERSION, nullptr);
282276
}
283277

284278
/* got a line */
@@ -310,8 +304,7 @@ IniFile::Find(const char *_tag, const char *_section, int _num, int *lineno)
310304
fprintf(stderr,
311305
"INIFILE lineno=%d:Too many backslash line extends (limit=%d)\n",
312306
lineNo, MAX_EXTEND_LINES);
313-
ThrowException(ERR_OVER_EXTENDED);
314-
return(NULL);
307+
return ThrowException(ERR_OVER_EXTENDED, nullptr);
315308
}
316309
continue; // get next line to extend
317310
} else {
@@ -335,8 +328,7 @@ IniFile::Find(const char *_tag, const char *_section, int _num, int *lineno)
335328
/* check for '[' char-- if so, it's a section tag, and we're out
336329
of our section */
337330
if (NULL != section && nonWhite[0] == '[') {
338-
ThrowException(ERR_TAG_NOT_FOUND);
339-
return(NULL);
331+
return ThrowException(ERR_TAG_NOT_FOUND, nullptr);
340332
}
341333

342334
len = strlen(tag);
@@ -359,8 +351,7 @@ IniFile::Find(const char *_tag, const char *_section, int _num, int *lineno)
359351
valueString = AfterEqual(nonWhite);
360352
/* Eliminate white space at the end of a line also. */
361353
if (NULL == valueString) {
362-
ThrowException(ERR_TAG_NOT_FOUND);
363-
return(NULL);
354+
return ThrowException(ERR_TAG_NOT_FOUND, nullptr);
364355
}
365356
endValueString = valueString + strlen(valueString) - 1;
366357
while (*endValueString == ' ' || *endValueString == '\t'
@@ -375,8 +366,7 @@ IniFile::Find(const char *_tag, const char *_section, int _num, int *lineno)
375366
/* else continue */
376367
}
377368

378-
ThrowException(ERR_TAG_NOT_FOUND);
379-
return(NULL);
369+
return ThrowException(ERR_TAG_NOT_FOUND, nullptr);
380370
}
381371

382372
const char *
@@ -387,8 +377,7 @@ IniFile::FindString(char *dest, size_t n, const char *_tag, const char *_section
387377
return res;
388378
int r = snprintf(dest, n, "%s", res);
389379
if(r < 0 || (size_t)r >= n) {
390-
ThrowException(ERR_CONVERSION);
391-
return NULL;
380+
return ThrowException(ERR_CONVERSION, nullptr);
392381
}
393382
return dest;
394383
}
@@ -411,9 +400,7 @@ IniFile::CheckIfOpen(void)
411400
if(IsOpen())
412401
return(true);
413402

414-
ThrowException(ERR_NOT_OPEN);
415-
416-
return(false);
403+
return ThrowException(ERR_NOT_OPEN, false);
417404
}
418405

419406

@@ -430,7 +417,7 @@ IniFile::LockFile(void)
430417
fclose(fp);
431418

432419
fp = NULL;
433-
return(false);
420+
return ThrowException(ERR_LIMITS, false);
434421
}
435422

436423
return(true);
@@ -452,27 +439,25 @@ IniFile::TildeExpansion(const char *file, char *path, size_t size)
452439

453440
int res = snprintf(path, size, "%s", file);
454441
if(res < 0 || (size_t)res >= size)
455-
return ERR_CONVERSION;
442+
return ThrowException(ERR_CONVERSION);
456443

457444
if (strlen(file) < 2 || !(file[0] == '~' && file[1] == '/')) {
458445
/* no tilde expansion required, or unsupported
459446
tilde expansion type requested */
460-
return ERR_NONE;
447+
return ThrowException(ERR_NONE);
461448
}
462449

463450
home = getenv("HOME");
464451
if (!home) {
465-
ThrowException(ERR_CONVERSION);
466-
return ERR_CONVERSION;
452+
return ThrowException(ERR_CONVERSION);
467453
}
468454

469455
res = snprintf(path, size, "%s%s", home, file + 1);
470456
if(res < 0 || (size_t)res >= size) {
471-
ThrowException(ERR_CONVERSION);
472-
return ERR_CONVERSION;
457+
return ThrowException(ERR_CONVERSION);
473458
}
474459

475-
return ERR_NONE;
460+
return ThrowException(ERR_NONE);
476461
}
477462

478463
int
@@ -482,7 +467,7 @@ TildeExpansion(const char *file, char *path, size_t size)
482467
return !f.TildeExpansion(file, path, size);
483468
}
484469

485-
void
470+
IniFile::ErrorCode
486471
IniFile::ThrowException(ErrorCode errCode)
487472
{
488473
if(errCode & errMask){
@@ -493,6 +478,7 @@ IniFile::ThrowException(ErrorCode errCode)
493478
exception.lineNo = lineNo;
494479
throw(exception);
495480
}
481+
return errCode;
496482
}
497483

498484

src/libnml/inifile/inifile.hh

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,7 @@ public:
7070
return(errCode);
7171

7272
if((tmp > max) || (tmp < min)) {
73-
ThrowException(ERR_LIMITS);
74-
return(ERR_LIMITS);
73+
return ThrowException(ERR_LIMITS);
7574
}
7675

7776
*result = tmp;
@@ -91,8 +90,7 @@ public:
9190
try {
9291
*result = boost::lexical_cast<T>(tmp);
9392
} catch (boost::bad_lexical_cast &) {
94-
ThrowException(ERR_CONVERSION);
95-
return(ERR_CONVERSION);
93+
return ThrowException(ERR_CONVERSION);
9694
}
9795

9896
return(ERR_NONE);
@@ -158,7 +156,11 @@ private:
158156

159157
bool CheckIfOpen(void);
160158
bool LockFile(void);
161-
void ThrowException(ErrorCode);
159+
ErrorCode ThrowException(ErrorCode);
160+
template<typename T> T ThrowException(ErrorCode e, T val) {
161+
return ThrowException(e), val;
162+
163+
}
162164
char *AfterEqual(const char *string);
163165
char *SkipWhite(const char *string);
164166
};

0 commit comments

Comments
 (0)