Skip to content

Commit

Permalink
strcaseequal_neutral_len() was not returning true when it should've
Browse files Browse the repository at this point in the history
Add a few tests on every debug startup too
  • Loading branch information
lpereira committed Nov 29, 2023
1 parent 4f58b3c commit a365916
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/lib/missing.c
Original file line number Diff line number Diff line change
Expand Up @@ -716,7 +716,7 @@ bool strcaseequal_neutral_len(const char *a, const char *b, size_t len)
}
}

return false;
return (ssize_t)len < 0;
}

ALWAYS_INLINE bool strcaseequal_neutral(const char *a, const char *b)
Expand All @@ -735,6 +735,11 @@ __attribute__((constructor)) static void test_strcaseequal_neutral(void)
assert(strcaseequal_neutral("LwAN", "lwam") == false);
assert(strcaseequal_neutral("LwAn", "lWaM") == false);

assert(strcaseequal_neutral_len("Host: localhost:8080", "Host", 4) == true);
assert(strcaseequal_neutral_len("Host", "Host: localhost:8080", 4) == true);
assert(strcaseequal_neutral_len("Host", "Hosh: not-localhost:1234", 4) == false);
assert(strcaseequal_neutral_len("Host: something-else:443", "Host: localhost:8080", 4) == true);

static_assert(CHAR_BIT == 8, "sane CHAR_BIT value");
static_assert('*' == 42, "ASCII character set");
static_assert('0' == 48, "ASCII character set");
Expand Down

0 comments on commit a365916

Please sign in to comment.