fix: harden small core containers
This commit is contained in:
@@ -76,3 +76,37 @@ hmap_long_utf8_keys(struct ct *t)
|
||||
cleanup:
|
||||
hmapfree(h);
|
||||
}
|
||||
|
||||
void
|
||||
hmap_binary_keys_and_invalid_lengths(struct ct *t)
|
||||
{
|
||||
Hmap *h;
|
||||
Hnode *n;
|
||||
Str key, other;
|
||||
|
||||
h = hmapalloc(1);
|
||||
CT_CHECK(t, h != nil);
|
||||
key.n = 3;
|
||||
key.r[0] = 'a';
|
||||
key.r[1] = 0;
|
||||
key.r[2] = 'b';
|
||||
other = key;
|
||||
other.r[2] = 'c';
|
||||
hmapset(&h, &key, "one", 3);
|
||||
hmapset(&h, &other, "two", 3);
|
||||
n = hmapget(h, &key);
|
||||
if(CT_CHECK(t, n != nil)){
|
||||
CT_EQ_INT(t, 3, n->klen);
|
||||
CT_EQ_MEM(t, "one", n->val, n->vlen);
|
||||
}
|
||||
n = hmapget(h, &other);
|
||||
if(CT_CHECK(t, n != nil))
|
||||
CT_EQ_MEM(t, "two", n->val, n->vlen);
|
||||
hmapset(&h, &key, "bad", -1);
|
||||
hmapset(&h, &key, nil, 1);
|
||||
n = hmapget(h, &key);
|
||||
if(CT_CHECK(t, n != nil))
|
||||
CT_EQ_MEM(t, "one", n->val, n->vlen);
|
||||
CT_EQ_PTR(t, nil, hmapalloc(0));
|
||||
hmapfree(h);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user