diff options
author | Rainer Gerhards <rgerhards@adiscon.com> | 2013-07-19 16:04:45 +0200 |
---|---|---|
committer | Rainer Gerhards <rgerhards@adiscon.com> | 2013-07-19 16:04:45 +0200 |
commit | 6356763f8e8420d6e0077052636e1bc1ea225d89 (patch) | |
tree | ebeeb5596b9f4cbeb96483e47a0dd7d36f05037e /tests/chkseq.c | |
parent | 55c2a488c061ec8e9a6973784173c7b1538b2dc5 (diff) | |
download | rsyslog-6356763f8e8420d6e0077052636e1bc1ea225d89.tar.gz rsyslog-6356763f8e8420d6e0077052636e1bc1ea225d89.tar.bz2 rsyslog-6356763f8e8420d6e0077052636e1bc1ea225d89.zip |
bugfix: testbench tool chkseq did improperly report invalid file
This happened when permitted duplicate values existed in the very
last lines, right before end-of-file.
Thanks to Radu Gheorghe for reporting this bug.
Diffstat (limited to 'tests/chkseq.c')
-rw-r--r-- | tests/chkseq.c | 41 |
1 files changed, 37 insertions, 4 deletions
diff --git a/tests/chkseq.c b/tests/chkseq.c index b22c8992..bea9f83a 100644 --- a/tests/chkseq.c +++ b/tests/chkseq.c @@ -48,6 +48,7 @@ int main(int argc, char *argv[]) int start = 0, end = 0; int opt; int nDups = 0; + int reachedEOF; int edLen; /* length of extra data */ static char edBuf[500*1024]; /* buffer for extra data (pretty large to be on the save side...) */ char *file = NULL; @@ -126,15 +127,47 @@ int main(int argc, char *argv[]) } } - if(nDups != 0) - printf("info: had %d duplicates (this is no error)\n", nDups); - if(i - 1 != end) { printf("only %d records in file, expected %d\n", i - 1, end); exit(1); } - if(!feof(fp)) { + if(feof(fp)) { + reachedEOF = 1; + } else { + /* if duplicates are permitted, we need to do a final check if we have duplicates at the + * end of file. + */ + if(dupsPermitted) { + i = end; + while(!feof(fp)) { + if(bHaveExtraData) { + scanfOK = fscanf(fp, "%d,%d,%s\n", &val, &edLen, edBuf) == 3 ? 1 : 0; + if(edLen != (int) strlen(edBuf)) { + printf("extra data length specified %d, but actually is %ld in record %d\n", + edLen, (long) strlen(edBuf), i); + exit(1); + } + } else { + scanfOK = fscanf(fp, "%d\n", &val) == 1 ? 1 : 0; + } + + if(val != i) { + reachedEOF = 0; + goto breakIF; + } + } + reachedEOF = feof(fp) ? 1 : 0; + } else { + reachedEOF = 0; + } + } + +breakIF: + if(nDups != 0) + printf("info: had %d duplicates (this is no error)\n", nDups); + + if(!reachedEOF) { printf("end of processing, but NOT end of file!\n"); exit(1); } |