bench: Update help functions in bench and bench_internal
What changed, and why it matters
This change is a minor cleanup to the help text of benchmark programs. It makes the printed usage instructions show the actual program name (for example, how the program was launched) instead of a hardcoded name like './bench'. There is no security issue here.
No security action needed. Treat as normal code maintenance.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The commit refactors help() functions in three benchmark source files (src/bench.c, src/bench_ecmult.c, src/bench_internal.c) to accept argv[0] as executable_path and print it in usage strings. Previously some helpers took no path or the full argv array. This is a cosmetic/usability improvement only; no cryptographic, memory-safety, or logic changes are present.
Changed components
src/bench.csrc/bench_ecmult.csrc/bench_internal.cInspect captured patch +14 / −14
diff --git a/src/bench.c b/src/bench.c
index a5231b7..de7fef9 100644
--- a/src/bench.c
+++ b/src/bench.c
@@ -12,7 +12,7 @@
#include "util.h"
#include "bench.h"
-static void help(int default_iters) {
+static void help(const char *executable_path, int default_iters) {
printf("Benchmarks the following algorithms:\n");
printf(" - ECDSA signing/verification\n");
@@ -36,7 +36,7 @@ static void help(int default_iters) {
printf("The default number of iterations for each benchmark is %d. This can be\n", default_iters);
printf("customized using the SECP256K1_BENCH_ITERS environment variable.\n");
printf("\n");
- printf("Usage: ./bench [args]\n");
+ printf("Usage: %s [args]\n", executable_path);
printf("By default, all benchmarks will be run.\n");
printf("args:\n");
printf(" help : display this help and exit\n");
@@ -189,7 +189,7 @@ int main(int argc, char** argv) {
int default_iters = 20000;
int iters = get_iters(default_iters);
if (iters == 0) {
- help(default_iters);
+ help(argv[0], default_iters);
return EXIT_FAILURE;
}
@@ -197,11 +197,11 @@ int main(int argc, char** argv) {
if (have_flag(argc, argv, "-h")
|| have_flag(argc, argv, "--help")
|| have_flag(argc, argv, "help")) {
- help(default_iters);
+ help(argv[0], default_iters);
return EXIT_SUCCESS;
} else if (invalid_args) {
fprintf(stderr, "./bench: unrecognized argument.\n\n");
- help(default_iters);
+ help(argv[0], default_iters);
return EXIT_FAILURE;
}
}
diff --git a/src/bench_ecmult.c b/src/bench_ecmult.c
index bcf8b43..7393730 100644
--- a/src/bench_ecmult.c
+++ b/src/bench_ecmult.c
@@ -19,13 +19,13 @@
#define POINTS 32768
-static void help(char **argv, int default_iters) {
+static void help(const char *executable_path, int default_iters) {
printf("Benchmark EC multiplication algorithms\n");
printf("\n");
printf("The default number of iterations for each benchmark is %d. This can be\n", default_iters);
printf("customized using the SECP256K1_BENCH_ITERS environment variable.\n");
printf("\n");
- printf("Usage: %s <help|pippenger_wnaf|strauss_wnaf|simple>\n", argv[0]);
+ printf("Usage: %s [args]\n", executable_path);
printf("The output shows the number of multiplied and summed points right after the\n");
printf("function name. The letter 'g' indicates that one of the points is the generator.\n");
printf("The benchmarks are divided by the number of points.\n");
@@ -314,7 +314,7 @@ int main(int argc, char **argv) {
int default_iters = 10000;
int iters = get_iters(default_iters);
if (iters == 0) {
- help(argv, default_iters);
+ help(argv[0], default_iters);
return EXIT_FAILURE;
}
@@ -324,7 +324,7 @@ int main(int argc, char **argv) {
if(have_flag(argc, argv, "-h")
|| have_flag(argc, argv, "--help")
|| have_flag(argc, argv, "help")) {
- help(argv, default_iters);
+ help(argv[0], default_iters);
return EXIT_SUCCESS;
} else if(have_flag(argc, argv, "pippenger_wnaf")) {
printf("Using pippenger_wnaf:\n");
@@ -336,7 +336,7 @@ int main(int argc, char **argv) {
printf("Using simple algorithm:\n");
} else {
fprintf(stderr, "%s: unrecognized argument '%s'.\n\n", argv[0], argv[1]);
- help(argv, default_iters);
+ help(argv[0], default_iters);
return EXIT_FAILURE;
}
}
diff --git a/src/bench_internal.c b/src/bench_internal.c
index 001bd25..fe16e93 100644
--- a/src/bench_internal.c
+++ b/src/bench_internal.c
@@ -18,13 +18,13 @@
#include "ecmult_impl.h"
#include "bench.h"
-static void help(int default_iters) {
+static void help(const char *executable_path, int default_iters) {
printf("Benchmarks various internal routines.\n");
printf("\n");
printf("The default number of iterations for each benchmark is %d. This can be\n", default_iters);
printf("customized using the SECP256K1_BENCH_ITERS environment variable.\n");
printf("\n");
- printf("Usage: ./bench_internal [args]\n");
+ printf("Usage: %s [args]\n", executable_path);
printf("By default, all benchmarks will be run.\n");
printf("args:\n");
printf(" help : display this help and exit\n");
@@ -389,7 +389,7 @@ int main(int argc, char **argv) {
int default_iters = 20000;
int iters = get_iters(default_iters);
if (iters == 0) {
- help(default_iters);
+ help(argv[0], default_iters);
return EXIT_FAILURE;
}
@@ -397,7 +397,7 @@ int main(int argc, char **argv) {
if (have_flag(argc, argv, "-h")
|| have_flag(argc, argv, "--help")
|| have_flag(argc, argv, "help")) {
- help(default_iters);
+ help(argv[0], default_iters);
return EXIT_SUCCESS;
}
}
Why this scored 15/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.