aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLouis Burda <quent.burda@gmail.com>2021-05-22 14:25:34 +0200
committerLouis Burda <quent.burda@gmail.com>2021-05-22 14:25:34 +0200
commit17e3bc800a4016186c88bb5c12da29fdff473ef6 (patch)
tree52ceace5de5f62b256ae0a0dc1b4e898d23fd864
parent30eed818961080d6e3cf87d8459bb74f43abad0f (diff)
downloadenowars5-service-stldoctor-17e3bc800a4016186c88bb5c12da29fdff473ef6.tar.gz
enowars5-service-stldoctor-17e3bc800a4016186c88bb5c12da29fdff473ef6.zip
consider matching of terminator in strchr calls
-rw-r--r--service/src/stlfile.c28
-rw-r--r--service/src/util.c2
2 files changed, 18 insertions, 12 deletions
diff --git a/service/src/stlfile.c b/service/src/stlfile.c
index 1f4dc66..58bb5af 100644
--- a/service/src/stlfile.c
+++ b/service/src/stlfile.c
@@ -60,10 +60,16 @@ stack_ind(struct stack *stack, int search)
return -1;
}
+int
+isws(char c)
+{
+ return c && strchr(wsset, c);
+}
+
char*
-skip_set(char *p, const char *set)
+skipws(char *p)
{
- for (; *p && strchr(set, *p); p++);
+ for (; isws(*p); p++);
return p;
}
@@ -72,8 +78,8 @@ consume_arg(char **start, char **end)
{
char *p, *tmp;
- p = skip_set(*start, wsset);
- for (; !strchr(wsset, *p); p++);
+ p = skipws(*start);
+ for (; !isws(*p); p++);
if (!*p) return NULL;
tmp = *start;
*start = p + 1;
@@ -87,11 +93,11 @@ consume_keyword(char **start)
char *bp;
int i, len;
- bp = skip_set(*start, wsset);
+ bp = skipws(*start);
for (i = 0; i < ARRSIZE(kwmap); i++) {
len = strlen(kwmap[i].str);
- if (!strncmp(kwmap[i].str, bp, len) && strchr(wsset, *(bp + len))) {
+ if (!strncmp(kwmap[i].str, bp, len) && isws(*(bp + len))) {
// printf("GOT: %s\n", kwmap[i].str);
*start = bp + len + (bp[len] ? 1 : 0);
return kwmap[i].code;
@@ -168,7 +174,7 @@ parse_file_ascii(struct parseinfo *info, char *buf, size_t len)
if (!(arg = consume_arg(&bp, &end)))
PARSE_FAIL("Facet with less than 3 args!\n");
farg = strtof(arg, &tmp);
- if (!strchr(wsset, *tmp))
+ if (!isws(*tmp))
PARSE_FAIL("Facet with invalid arg '%s'!\n", arg);
}
break;
@@ -181,14 +187,14 @@ parse_file_ascii(struct parseinfo *info, char *buf, size_t len)
if (!(arg = consume_arg(&bp, &end)))
PARSE_FAIL("Vertex with less than 3 args!\n");
farg = strtof(arg, &tmp);
- if (!strchr(wsset, *tmp))
+ if (!isws(*tmp))
PARSE_FAIL("Vertex with invalid arg '%s'!\n", arg);
info->bbmin[i] = MIN(info->bbmin[i], farg);
info->bbmax[i] = MAX(info->bbmax[i], farg);
}
break;
case KW_UNKNOWN:
- prev = skip_set(prev, wsset);
+ prev = skipws(prev);
PARSE_FAIL("Expected keyword, got:\n%.*s...\n", 30, prev);
}
prev = bp;
@@ -273,8 +279,8 @@ parse_file(struct parseinfo *info, char *buf, size_t len)
info->filesize = len;
/* check bin vs ascii with first keyword */
- for (bp = buf; strchr(wsset, *bp); bp++);
- status = !strncmp("solid", bp, 5) && strchr(wsset, bp[5])
+ for (bp = buf; isws(*bp); bp++);
+ status = !strncmp("solid", bp, 5) && isws(bp[5])
? parse_file_ascii(info, buf, len)
: parse_file_bin(info, buf, len);
if (status == FAIL) return FAIL;
diff --git a/service/src/util.c b/service/src/util.c
index 31a2628..9270fd9 100644
--- a/service/src/util.c
+++ b/service/src/util.c
@@ -69,7 +69,7 @@ checkalph(const char *str, const char *alph)
int i;
for (i = 0; i < strlen(str); i++)
- if (!strchr(alph, str[i])) return 0;
+ if (str[i] && !strchr(alph, str[i])) return 0;
return 1;
}