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