aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFederico Angelilli <code@fedang.net>2024-11-19 01:30:56 +0100
committerFederico Angelilli <code@fedang.net>2024-11-19 01:30:56 +0100
commit79a32360e76cb0739312e15299fc22941e51b64b (patch)
tree9d51fe26b2189f7de99e46275762df9106905ac1
parent2103b6b1c2d9d07e207bea3abde001efeede402d (diff)
Fix error in format_option_match
-rw-r--r--src/format.c12
1 files changed, 7 insertions, 5 deletions
diff --git a/src/format.c b/src/format.c
index 2a2ee03..0f25084 100644
--- a/src/format.c
+++ b/src/format.c
@@ -92,17 +92,18 @@ static size_t format_option_cmp(const char *a, const char *b)
static bool format_option_match(format_pair_t *part, const format_option_t *option)
{
format_mark_t mark = 0;
- size_t off = 0;
+ size_t off = 0, tmp = 0;
for (format_pair_t *ps = option->prefixes; ps != NULL && ps->string != NULL; ps++) {
- off = format_option_cmp(part->string, ps->string);
- if (off != 0) {
+ tmp = format_option_cmp(part->string, ps->string);
+ if (tmp != 0) {
+ off += tmp;
mark |= ps->mark;
break;
}
}
- size_t tmp = format_option_cmp(part->string + off, option->option.string);
+ tmp = format_option_cmp(part->string + off, option->option.string);
if (tmp == 0) return false;
off += tmp;
mark |= option->option.mark;
@@ -110,12 +111,13 @@ static bool format_option_match(format_pair_t *part, const format_option_t *opti
for (format_pair_t *ss = option->suffixes; ss != NULL && ss->string != NULL; ss++) {
tmp = format_option_cmp(part->string + off, ss->string);
if (tmp != 0) {
+ off += tmp;
mark |= ss->mark;
break;
}
}
- if (part->string[tmp] != '\0')
+ if (part->string[off] != '\0')
return false;
part->mark = mark;