Commit 2e9f190a authored by Vladimír Čunát's avatar Vladimír Čunát

kr_bitcmp: add meaning to NULL inputs

Reasoning: we currently only use the function from lua modules and nil
values are very common there; I want to pick these changes to a bugfix
update without extensive checking whether the modules might pass
invalid input if user passes invalid config and thus introduce new
crashes.  The checks also seem cheap performance-wise.
parent dd971978
......@@ -364,6 +364,18 @@ int kr_straddr_subnet(void *dst, const char *addr)
int kr_bitcmp(const char *a, const char *b, int bits)
/* We're using the function from lua directly, so at least for now
* we avoid crashing on bogus inputs. Meaning: NULL is ordered before
* anything else, and negative length is the same as zero.
* TODO: review the call sites and probably remove the checks. */
if (bits <= 0 || (!a && !b)) {
return 0;
} else if (!a) {
return -1;
} else if (!b) {
return 1;
assert(a && b && bits >= 0 || bits == 0);
/* Compare part byte-divisible part. */
const size_t chunk = bits / 8;
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment