Commit 871b6b48 authored by Poul-Henning Kamp's avatar Poul-Henning Kamp

Use the new bprintf() macros to avoid some (v)asprintf() calls.



git-svn-id: http://www.varnish-cache.org/svn/trunk/varnish-cache@4459 d4fa192b-c00b-0410-8231-f00ffab90ce4
parent 32016d15
......@@ -89,8 +89,7 @@ macro_def(struct vtclog *vl, const char *instance, const char *name,
va_list ap;
if (instance != NULL) {
assert (snprintf(buf, sizeof buf, "%s_%s", instance, name)
< sizeof buf);
bprintf(buf, "%s_%s", instance, name);
name = buf;
}
......@@ -109,8 +108,9 @@ macro_def(struct vtclog *vl, const char *instance, const char *name,
va_start(ap, fmt);
free(m->val);
m->val = NULL;
assert(vasprintf(&m->val, fmt, ap) >= 0);
vbprintf(buf, fmt, ap);
va_end(ap);
m->val = strdup(buf);
AN(m->val);
vtc_log(vl, 4, "macro def %s=%s", name, m->val);
} else if (m != NULL) {
......
......@@ -47,7 +47,6 @@ SVNID("$Id$")
#include "vcc_priv.h"
#include "vcc_compile.h"
#include "libvarnish.h"
#include "compat/vasprintf.h"
struct acl_e {
VTAILQ_ENTRY(acl_e) list;
......@@ -456,7 +455,7 @@ void
vcc_Cond_Ip(const struct var *vp, struct tokenlist *tl)
{
unsigned tcond;
char *acln;
char acln[32];
switch (tl->t->tok) {
case '~':
......@@ -473,13 +472,11 @@ vcc_Cond_Ip(const struct var *vp, struct tokenlist *tl)
VTAILQ_INIT(&tl->acl);
tcond = tl->t->tok;
vcc_NextToken(tl);
assert(asprintf(&acln, "%u", tl->cnt) > 0);
AN(acln);
bprintf(acln, "%u", tl->cnt);
vcc_acl_entry(tl);
vcc_acl_emit(tl, acln, 1);
Fb(tl, 1, "%smatch_acl_anon_%s(sp, %s)\n",
(tcond == T_NEQ ? "!" : ""), acln, vp->rname);
free(acln);
break;
default:
vsb_printf(tl->sb, "Invalid condition ");
......@@ -495,7 +492,7 @@ void
vcc_Acl(struct tokenlist *tl)
{
struct token *an;
char *acln;
char acln[1024];
vcc_NextToken(tl);
VTAILQ_INIT(&tl->acl);
......@@ -505,8 +502,7 @@ vcc_Acl(struct tokenlist *tl)
vcc_NextToken(tl);
vcc_AddDef(tl, an, R_ACL);
assert(asprintf(&acln, "%.*s", PF(an)) > 0);
AN(acln);
bprintf(acln, "%.*s", PF(an));
ExpectErr(tl, '{');
vcc_NextToken(tl);
......@@ -521,6 +517,4 @@ vcc_Acl(struct tokenlist *tl)
vcc_NextToken(tl);
vcc_acl_emit(tl, acln, 0);
free(acln);
}
......@@ -40,7 +40,6 @@ SVNID("$Id$")
#include "vcc_priv.h"
#include "vcc_compile.h"
#include "libvarnish.h"
#include "compat/vasprintf.h"
/*--------------------------------------------------------------------*/
......@@ -49,7 +48,8 @@ HeaderVar(struct tokenlist *tl, const struct token *t, const struct var *vh)
{
char *p;
struct var *v;
int i;
int i, l;
char buf[258];
(void)tl;
......@@ -65,16 +65,22 @@ HeaderVar(struct tokenlist *tl, const struct token *t, const struct var *vh)
v->fmt = STRING;
v->hdr = vh->hdr;
v->methods = vh->methods;
assert(asprintf(&p, "VRT_GetHdr(sp, %s, \"\\%03o%s:\")", v->hdr,
(unsigned)(strlen(v->name + vh->len) + 1), v->name + vh->len) > 0);
AN(p);
TlFree(tl, p);
l = strlen(v->name + vh->len) + 1;
bprintf(buf, "VRT_GetHdr(sp, %s, \"\\%03o%s:\")",
v->hdr, (unsigned)l, v->name + vh->len);
i = strlen(buf);
p = TlAlloc(tl, i + 1);
memcpy(p, buf, i + 1);
v->rname = p;
assert(asprintf(&p, "VRT_SetHdr(sp, %s, \"\\%03o%s:\", ", v->hdr,
(unsigned)(strlen(v->name + vh->len) + 1), v->name + vh->len) > 0);
AN(p);
TlFree(tl, p);
bprintf(buf, "VRT_SetHdr(sp, %s, \"\\%03o%s:\", ",
v->hdr, (unsigned)l, v->name + vh->len);
i = strlen(buf);
p = TlAlloc(tl, i + 1);
memcpy(p, buf, i + 1);
v->lname = p;
return (v);
}
......
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