Example code: bugfix of KW scan.

This commit is contained in:
Hong, Yang A 2021-01-15 13:55:04 +00:00
parent 433d2f386a
commit e0c489f98f
3 changed files with 20 additions and 0 deletions

View File

@ -123,6 +123,7 @@
#include <vector>
#include <unordered_map>
#include <climits>
#include <unistd.h>
// We use the BSD primitives throughout as they exist on both BSD and Linux.
@ -657,6 +658,10 @@ int main(int argc, char **argv) {
break;
case 'n':
repeatCount = atoi(optarg);
if (repeatCount <= 0 || repeatCount > UINT_MAX) {
cerr << "Invalid repeatCount." << endl;
exit(-1);
}
break;
default:
usage(argv[0]);

View File

@ -58,6 +58,7 @@
#include <unordered_map>
#include <vector>
#include <climits>
#include <unistd.h>
// We use the BSD primitives throughout as they exist on both BSD and Linux.
@ -489,6 +490,10 @@ int main(int argc, char **argv) {
// Streaming mode scans.
double secsStreamingScan = 0.0, secsStreamingOpenClose = 0.0;
if (repeatCount <= 0 || repeatCount > UINT_MAX) {
cerr << "Invalid repeatCount." << endl;
exit(-1);
}
for (unsigned int i = 0; i < repeatCount; i++) {
// Open streams.
clock.start();

View File

@ -57,6 +57,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <hs.h>
@ -152,6 +153,15 @@ int main(int argc, char *argv[]) {
char *pattern = argv[1];
char *inputFN = argv[2];
if (access(inputFN, F_OK) != 0) {
fprintf(stderr, "ERROR: file doesn't exist.\n");
return -1;
}
if (access(inputFN, R_OK) != 0) {
fprintf(stderr, "ERROR: can't be read.\n");
return -1;
}
/* First, we attempt to compile the pattern provided on the command line.
* We assume 'DOTALL' semantics, meaning that the '.' meta-character will
* match newline characters. The compiler will analyse the given pattern and