Skip to content

Commit

Permalink
Construct intermediate strands on the stack
Browse files Browse the repository at this point in the history
We construct a new struct strands only to pass it to VRT_StrandsWS(), so
it does not need to be created on the workspace.
  • Loading branch information
nigoroll authored and mbgrydeland committed Mar 16, 2021
1 parent 514665c commit 350be1c
Showing 1 changed file with 7 additions and 9 deletions.
16 changes: 7 additions & 9 deletions src/vmod_header.c
Original file line number Diff line number Diff line change
Expand Up @@ -212,20 +212,18 @@ VCL_VOID
vmod_append(VRT_CTX, VCL_HEADER hdr, VCL_STRANDS s)
{
struct http *hp;
struct strands *st;
struct strands st[1];
const char *p[s->n + 2];
const char *b;

CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC);

/* prefix the strand with $hdr_name + space */
st = VRT_AllocStrandsWS(ctx->ws, s->n + 2);
if (!st) {
VRT_fail(ctx, "vmod_head: workspace allocation failure");
return;
}
st->p[0] = hdr->what + 1;
st->p[1] = " ";
AN(memcpy(st->p + 2, s->p, s->n * sizeof *s->p));
p[0] = hdr->what + 1;
p[1] = " ";
AN(memcpy(p + 2, s->p, s->n * sizeof *s->p));
st->n = s->n + 2;
st->p = p;

b = VRT_StrandsWS(ctx->ws, NULL, st);

Expand Down

0 comments on commit 350be1c

Please sign in to comment.