summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristopher Wellons <wellons@nullprogram.com>2017-10-05 23:31:03 -0400
committerChristopher Wellons <wellons@nullprogram.com>2017-10-05 23:31:03 -0400
commitfa01ab965478fd4286ae9a70d0aad952cbc4c13e (patch)
treed74460a3a308fc1b488c313ca9d2d34937d5e070
parentb1c933e95bff649d0ca207e5c6d2e255b2b9dd58 (diff)
More consistent error checking
-rw-r--r--test/benchmark.c16
1 files changed, 9 insertions, 7 deletions
diff --git a/test/benchmark.c b/test/benchmark.c
index 22b5322..2914a50 100644
--- a/test/benchmark.c
+++ b/test/benchmark.c
@@ -71,7 +71,7 @@ int
main(void)
{
long errors, n;
- size_t z = BUFLEN * 1024 * 1024;
+ size_t z = BUFLEN * 1024L * 1024;
unsigned char *buffer = malloc(z);
unsigned char *end = buffer_fill(buffer, z);
@@ -87,10 +87,10 @@ main(void)
long count = 0;
while (p < end) {
p = utf8_decode(p, &c, &e);
+ errors += !!e; // force errors to be checked
count++;
}
- errors += !!e;
- if (p == end)
+ if (p == end) // reached the end successfully?
n++;
} while (running);
@@ -107,11 +107,13 @@ main(void)
uint32_t c;
uint32_t state = 0;
long count = 0;
- for (; p < end; p++)
- if (!bj_utf8_decode(&state, &c, *p))
+ for (; p < end; p++) {
+ if (!bh_utf8_decode(&state, &c, *p))
count++;
- errors += state != UTF8_ACCEPT;
- if (p == end)
+ else if (state == UTF8_REJECT)
+ errors++; // force errors to be checked
+ }
+ if (p == end) // reached the end successfully?
n++;
} while (running);