rvb: Refactor to address a bogus compiler warning

gcc 13 complains that we used a pointer from before a realloc call, but
it did not understand that we actually used it to calculate an offset
only.

Refactor the code to avoid this ambiguity.

Ref #7

See https://gitlab.com/uplex/varnish/libvmod-re/-/issues/7#note_2328380883
parent fdc5d286
......@@ -182,7 +182,7 @@ rvb_size(const struct rvb *b)
static void
rvb_grow(struct rvb *b, size_t l)
{
const char *o;
ssize_t r_off, w_off;
rvb_assert(b);
assert(b->flags & RVB_F_MALLOC);
......@@ -192,18 +192,17 @@ rvb_grow(struct rvb *b, size_t l)
else
l += rvb_size(b);
o = b->u.ro.p;
// prepare for relocation
r_off = b->u.ro.r - b->u.ro.p;
w_off = b->u.wr.w - b->u.wr.p;
assert(r_off >= 0);
assert(w_off >= 0);
b->u.wr.p = realloc(b->u.wr.p, l);
AN(b->u.ro.p);
b->u.ro.l = b->u.ro.p + l;
if (b->u.ro.p == o)
return;
// realloc has relocated
b->u.ro.r = b->u.ro.p + (b->u.ro.r - o);
b->u.wr.w = b->u.wr.p + (b->u.ro.w - o);
b->u.ro.r = b->u.ro.p + r_off;
b->u.wr.w = b->u.wr.p + w_off;
}
static void
......
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