aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2024-06-24 12:44:39 -0400
committerDavid Robillard <d@drobilla.net>2024-06-25 15:52:07 -0400
commit032abfdff61056a7029a440fc1895bbe41ec964a (patch)
treeafbb3d137d5f7e8efeec031d7e32bf938f18484b /src
parent53fed50c8e37bf873196c2503814cd8b33acd298 (diff)
downloadserd-032abfdff61056a7029a440fc1895bbe41ec964a.tar.gz
serd-032abfdff61056a7029a440fc1895bbe41ec964a.tar.bz2
serd-032abfdff61056a7029a440fc1895bbe41ec964a.zip
Fix overly permissive parsing of syntax names on the command line
Diffstat (limited to 'src')
-rw-r--r--src/n3.c3
-rw-r--r--src/serdi.c4
-rw-r--r--src/string_utils.h16
3 files changed, 14 insertions, 9 deletions
diff --git a/src/n3.c b/src/n3.c
index 6cb8522e..a3cb93a6 100644
--- a/src/n3.c
+++ b/src/n3.c
@@ -1599,7 +1599,8 @@ tokcmp(SerdReader* const reader,
return -1;
}
- return serd_strncasecmp((const char*)node->buf, tok, n);
+ assert(node->buf[node->n_bytes] == '\0');
+ return serd_strcasecmp((const char*)node->buf, tok);
}
SerdStatus
diff --git a/src/serdi.c b/src/serdi.c
index 2bea9e3a..9d0a8f44 100644
--- a/src/serdi.c
+++ b/src/serdi.c
@@ -44,7 +44,7 @@ static SerdSyntax
get_syntax(const char* const name)
{
for (const Syntax* s = syntaxes; s->name; ++s) {
- if (!serd_strncasecmp(s->name, name, strlen(name))) {
+ if (!serd_strcasecmp(s->name, name)) {
return s->syntax;
}
}
@@ -59,7 +59,7 @@ guess_syntax(const char* const filename)
const char* ext = strrchr(filename, '.');
if (ext) {
for (const Syntax* s = syntaxes; s->name; ++s) {
- if (!serd_strncasecmp(s->extension, ext, strlen(ext))) {
+ if (!serd_strcasecmp(s->extension, ext)) {
return s->syntax;
}
}
diff --git a/src/string_utils.h b/src/string_utils.h
index 7770e1eb..4babee63 100644
--- a/src/string_utils.h
+++ b/src/string_utils.h
@@ -101,16 +101,20 @@ serd_to_upper(const char c)
return (char)((c >= 'a' && c <= 'z') ? c - 32 : c);
}
-static inline int
-serd_strncasecmp(const char* s1, const char* s2, size_t n)
+SERD_PURE_FUNC static inline int
+serd_strcasecmp(const char* s1, const char* s2)
{
- for (; n > 0 && *s2; s1++, s2++, --n) {
- if (serd_to_upper(*s1) != serd_to_upper(*s2)) {
- return ((*(const uint8_t*)s1 < *(const uint8_t*)s2) ? -1 : +1);
+ while (*s1 && *s2) {
+ const char c1 = serd_to_upper(*s1++);
+ const char c2 = serd_to_upper(*s2++);
+ if (c1 != c2) {
+ return (c1 < c2) ? -1 : +1;
}
}
- return 0;
+ const char c1 = serd_to_upper(*s1);
+ const char c2 = serd_to_upper(*s2);
+ return (c1 == c2) ? 0 : (c1 < c2) ? -1 : +1;
}
static inline uint32_t