Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
 help / color / mirror / Atom feed
* [FFmpeg-devel] [PATCH] checkasm: print usage on invalid arguments
@ 2023-07-14 18:44 Rémi Denis-Courmont
  0 siblings, 0 replies; only message in thread
From: Rémi Denis-Courmont @ 2023-07-14 18:44 UTC (permalink / raw)
  To: ffmpeg-devel

This checks that arguments are handled. If not, then this prints a
short usage notice and returns an error.
---
 tests/checkasm/checkasm.c | 34 +++++++++++++++++++++++-----------
 1 file changed, 23 insertions(+), 11 deletions(-)

diff --git a/tests/checkasm/checkasm.c b/tests/checkasm/checkasm.c
index d72850f076..fafa4a0c82 100644
--- a/tests/checkasm/checkasm.c
+++ b/tests/checkasm/checkasm.c
@@ -756,6 +756,14 @@ static void bench_uninit(void)
 #endif
 }
 
+static int usage(const char *path)
+{
+    fprintf(stderr,
+            "Usage: %s [--bench] [--test=<pattern>] [--verbose] [seed]\n",
+            path);
+    return 1;
+}
+
 int main(int argc, char *argv[])
 {
     unsigned int seed = av_get_random_seed();
@@ -771,25 +779,29 @@ int main(int argc, char *argv[])
         return 0;
     }
 
-    while (argc > 1) {
-        if (!strncmp(argv[1], "--bench", 7)) {
+    for (i = 1; i < argc; i++) {
+        const char *arg = argv[i];
+        unsigned long l;
+        char *end;
+
+        if (!strncmp(arg, "--bench", 7)) {
             if (bench_init() < 0)
                 return 1;
-            if (argv[1][7] == '=') {
-                state.bench_pattern = argv[1] + 8;
+            if (arg[7] == '=') {
+                state.bench_pattern = arg + 8;
                 state.bench_pattern_len = strlen(state.bench_pattern);
             } else
                 state.bench_pattern = "";
-        } else if (!strncmp(argv[1], "--test=", 7)) {
-            state.test_name = argv[1] + 7;
-        } else if (!strcmp(argv[1], "--verbose") || !strcmp(argv[1], "-v")) {
+        } else if (!strncmp(arg, "--test=", 7)) {
+            state.test_name = arg + 7;
+        } else if (!strcmp(arg, "--verbose") || !strcmp(arg, "-v")) {
             state.verbose = 1;
+        } else if ((l = strtoul(arg, &end, 10)) <= UINT_MAX &&
+                   *end == '\0') {
+            seed = l;
         } else {
-            seed = strtoul(argv[1], NULL, 10);
+            return usage(argv[0]);
         }
-
-        argc--;
-        argv++;
     }
 
     fprintf(stderr, "checkasm: using random seed %u\n", seed);
-- 
2.40.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2023-07-14 18:45 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-07-14 18:44 [FFmpeg-devel] [PATCH] checkasm: print usage on invalid arguments Rémi Denis-Courmont

Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

This inbox may be cloned and mirrored by anyone:

	git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \
		ffmpegdev@gitmailbox.com
	public-inbox-index ffmpegdev

Example config snippet for mirrors.


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git