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.
Unified · Split
| @@ -48,18 +48,6 @@ static unsigned long le2belong(unsigned long ul) { · 47 unmodified lines | ||
| 48 | 48 | ((ul & 0xFF)<<24)+((ul & 0xFF00)<<8); |
| 49 | 49 | } |
| 50 | 50 | |
| 51 | −/* Returns 1 if s contains any of the chars of list, else 0 */ | |
| 52 | −static int contains_any(const char *s, const char *list) { | |
| 53 | − const char *l; | |
| 54 | − for (; *s; s++) { | |
| 55 | − for (l = list; *l; l++) { | |
| 56 | − if (*s == *l) | |
| 57 | − return 1; | |
| 58 | − } | |
| 59 | − } | |
| 60 | − return 0; | |
| 61 | −} | |
| 62 | − | |
| 63 | 51 | static int ar_usage(int ret) { |
| 64 | 52 | fprintf(stderr, "usage: tcc -ar [crstvx] lib [files]\n"); |
| 65 | 53 | fprintf(stderr, "create library ([abdiopN] not supported).\n"); |
| @@ -103,16 +91,16 @@ ST_FUNC int tcc_tool_ar(TCCState *s1, int argc, char **argv) · 37 unmodified lines | ||
| 103 | 91 | i_lib = 0; i_obj = 0; // will hold the index of the lib and first obj |
| 104 | 92 | for (i = 1; i < argc; i++) { |
| 105 | 93 | const char *a = argv[i]; |
| 106 | − if (*a == '-' && strstr(a, ".")) | |
| 94 | + if (*a == '-' && strchr(a, '.')) | |
| 107 | 95 | ret = 1; // -x.y is always invalid (same as gnu ar) |
| 108 | − if ((*a == '-') || (i == 1 && !strstr(a, "."))) { // options argument | |
| 109 | − if (contains_any(a, ops_conflict)) | |
| 96 | + if ((*a == '-') || (i == 1 && !strchr(a, '.'))) { // options argument | |
| 97 | + if (strpbrk(a, ops_conflict)) | |
| 110 | 98 | ret = 1; |
| 111 | − if (strstr(a, "x")) | |
| 99 | + if (strchr(a, 'x')) | |
| 112 | 100 | extract = 1; |
| 113 | − if (strstr(a, "t")) | |
| 101 | + if (strchr(a, 't')) | |
| 114 | 102 | table = 1; |
| 115 | − if (strstr(a, "v")) | |
| 103 | + if (strchr(a, 'v')) | |
| 116 | 104 | verbose = 1; |
| 117 | 105 | } else { // lib or obj files: don't abort - keep validating all args. |
| 118 | 106 | if (!i_lib) // first file is the lib |