From a6ef31823bc4f7aeb88f03eedc8e0fecc484e3b4 Mon Sep 17 00:00:00 2001 From: "Avi Halachmi (:avih)" Date: Thu, 21 Nov 2024 18:03:53 +0200 Subject: [PATCH] tcc -ar options: use strchr, strpbrk (trivial, no-op) I happened to bump into thsese, but I didn't try to review the file, and there may be other places which could be similarly improved. This is originally my suboptimal code from commit 100f94be (tiny_libmaker: more robust arguments interpretation), so, a bit late, but let's improve it anyway. --- tcctools.c | 24 ++++++------------------ 1 file changed, 6 insertions(+), 18 deletions(-) diff --git a/tcctools.c b/tcctools.c index b34a4754..fffa7f97 100644 --- a/tcctools.c +++ b/tcctools.c @@ -48,18 +48,6 @@ static unsigned long le2belong(unsigned long ul) { ((ul & 0xFF)<<24)+((ul & 0xFF00)<<8); } -/* Returns 1 if s contains any of the chars of list, else 0 */ -static int contains_any(const char *s, const char *list) { - const char *l; - for (; *s; s++) { - for (l = list; *l; l++) { - if (*s == *l) - return 1; - } - } - return 0; -} - static int ar_usage(int ret) { fprintf(stderr, "usage: tcc -ar [crstvx] lib [files]\n"); fprintf(stderr, "create library ([abdiopN] not supported).\n"); @@ -103,16 +91,16 @@ ST_FUNC int tcc_tool_ar(TCCState *s1, int argc, char **argv) i_lib = 0; i_obj = 0; // will hold the index of the lib and first obj for (i = 1; i < argc; i++) { const char *a = argv[i]; - if (*a == '-' && strstr(a, ".")) + if (*a == '-' && strchr(a, '.')) ret = 1; // -x.y is always invalid (same as gnu ar) - if ((*a == '-') || (i == 1 && !strstr(a, "."))) { // options argument - if (contains_any(a, ops_conflict)) + if ((*a == '-') || (i == 1 && !strchr(a, '.'))) { // options argument + if (strpbrk(a, ops_conflict)) ret = 1; - if (strstr(a, "x")) + if (strchr(a, 'x')) extract = 1; - if (strstr(a, "t")) + if (strchr(a, 't')) table = 1; - if (strstr(a, "v")) + if (strchr(a, 'v')) verbose = 1; } else { // lib or obj files: don't abort - keep validating all args. if (!i_lib) // first file is the lib