summaryrefslogtreecommitdiffstats
path: root/test/bntest.c
diff options
context:
space:
mode:
authorRich Salz <rsalz@openssl.org>2017-05-23 08:59:49 -0400
committerRich Salz <rsalz@openssl.org>2017-05-23 11:07:51 -0400
commit281313e511381f3734f03233f8189d52771b2f6c (patch)
treee330ae88070728b2a21c8d3be142e1ce90137f99 /test/bntest.c
parentcaf2b6b54f04e89585184ba7bb4cb80b818d5ede (diff)
Fix line numbering for errors.
Reviewed-by: Andy Polyakov <appro@openssl.org> (Merged from https://github.com/openssl/openssl/pull/3528)
Diffstat (limited to 'test/bntest.c')
-rw-r--r--test/bntest.c22
1 files changed, 14 insertions, 8 deletions
diff --git a/test/bntest.c b/test/bntest.c
index 9de1e6eda4..ccedd7a7ec 100644
--- a/test/bntest.c
+++ b/test/bntest.c
@@ -49,7 +49,8 @@ typedef struct pair_st {
} PAIR;
typedef struct stanza_st {
- int start;
+ int curr; /* Current line in file */
+ int start; /* Line where test starts */
int numpairs;
PAIR pairs[MAXPAIRS];
} STANZA;
@@ -2005,16 +2006,16 @@ static char *strip_spaces(char *p)
/*
* Read next test stanza; return 1 if found, 0 on EOF or error.
*/
-static int readstanza(STANZA *s, int *linesread)
+static int readstanza(STANZA *s)
{
PAIR *pp = s->pairs;
char *p, *equals, *key, *value;
char buff[1024];
while (BIO_gets(fp, buff, sizeof(buff))) {
- (*linesread)++;
+ s->curr++;
if (!TEST_ptr(p = strchr(buff, '\n'))) {
- TEST_info("Line %d too long", s->start);
+ TEST_info("Line %d too long", s->curr);
return 0;
}
*p = '\0';
@@ -2027,9 +2028,13 @@ static int readstanza(STANZA *s, int *linesread)
if (buff[0] == '#')
continue;
- if (!TEST_ptr(equals = strchr(buff, '=')))
+ if (!TEST_ptr(equals = strchr(buff, '='))) {
+ TEST_info("Missing = at line %d\n", s->curr);
return 0;
+ }
*equals++ = '\0';
+ if (s->numpairs == 0)
+ s->start = s->curr;
if (!TEST_ptr(key = strip_spaces(buff))
|| !TEST_ptr(value = strip_spaces(equals))
@@ -2049,12 +2054,14 @@ static void clearstanza(STANZA *s)
PAIR *pp = s->pairs;
int i = s->numpairs;
int start = s->start;
+ int curr = s->curr;
for ( ; --i >= 0; pp++) {
OPENSSL_free(pp->key);
OPENSSL_free(pp->value);
}
memset(s, 0, sizeof(*s));
+ s->curr = curr;
s->start = start;
}
@@ -2094,7 +2101,7 @@ static char * const *testfiles;
static int run_file_tests(int i)
{
STANZA s;
- int linesread = 0, errcnt = 0;
+ int errcnt = 0;
if (!TEST_ptr(fp = BIO_new_file(testfiles[i], "rb")))
return 0;
@@ -2102,14 +2109,13 @@ static int run_file_tests(int i)
/* Read test file. */
set_test_title(testfiles[i]);
memset(&s, 0, sizeof(s));
- while (!BIO_eof(fp) && readstanza(&s, &linesread)) {
+ while (!BIO_eof(fp) && readstanza(&s)) {
if (s.numpairs == 0)
continue;
if (!file_test_run(&s)) {
errcnt++;
}
clearstanza(&s);
- s.start = linesread;
}
BIO_free(fp);