aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Waterman <andrew@sifive.com>2023-02-03 13:34:59 -0800
committerAndrew Waterman <andrew@sifive.com>2023-02-27 14:54:16 -0800
commite4d6a9c1edbb7e35f014fd5d457f20ee5a545d2d (patch)
tree49a7f78a6528334a5d5a6fbe29addd370a858336
parentb8e562a58cc5e51a358167cfda3754f1998f8577 (diff)
downloadriscv-isa-sim-e4d6a9c1edbb7e35f014fd5d457f20ee5a545d2d.zip
riscv-isa-sim-e4d6a9c1edbb7e35f014fd5d457f20ee5a545d2d.tar.gz
riscv-isa-sim-e4d6a9c1edbb7e35f014fd5d457f20ee5a545d2d.tar.bz2
Improve input validation for --hartids flag
Disallow negative hartids, repeated hartids, and empty lists.
-rw-r--r--spike_main/spike.cc18
1 files changed, 18 insertions, 0 deletions
diff --git a/spike_main/spike.cc b/spike_main/spike.cc
index e7ee03a..533811f 100644
--- a/spike_main/spike.cc
+++ b/spike_main/spike.cc
@@ -299,10 +299,28 @@ static std::vector<size_t> parse_hartids(const char *s)
int n;
while (stream >> n) {
+ if (n < 0) {
+ fprintf(stderr, "Negative hart ID %d is unsupported\n", n);
+ exit(-1);
+ }
+
hartids.push_back(n);
if (stream.peek() == ',') stream.ignore();
}
+ if (hartids.empty()) {
+ fprintf(stderr, "No hart IDs specified\n");
+ exit(-1);
+ }
+
+ std::sort(hartids.begin(), hartids.end());
+
+ const auto dup = std::adjacent_find(hartids.begin(), hartids.end());
+ if (dup != hartids.end()) {
+ fprintf(stderr, "Duplicate hart ID %zu\n", *dup);
+ exit(-1);
+ }
+
return hartids;
}