Skip to content

Commit

Permalink
clar: stop using assert()
Browse files Browse the repository at this point in the history
We have a single callsite of `assert()` remaining in our codebase that
checks for unknown command line arguments. This is somewhat broken
though as asserts may not be compiled depending on how the code is
compiled. Consequently, we may not abort properly on invalid arguments
in some scenarios.

Fix this issue by using `clar_abort()` instead.
  • Loading branch information
pks-t committed Sep 20, 2024
1 parent 453aa90 commit eaefd95
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions clar.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* This file is part of clar, distributed under the ISC license.
* For full terms see the included COPYING file.
*/
#include <assert.h>

#include <errno.h>
#include <setjmp.h>
#include <stdlib.h>
Expand Down Expand Up @@ -546,7 +546,8 @@ clar_parse_args(int argc, char **argv)
break;

default:
assert(!"Unexpected commandline argument!");
clar_abort("Unexpected commandline argument '%s'.\n",
argument[1]);
}
}
}
Expand Down

0 comments on commit eaefd95

Please sign in to comment.