From 41147e5b18ad09b04697c3aa729539689547281c Mon Sep 17 00:00:00 2001 From: Panu Matilainen Date: Tue, 6 May 2008 10:00:07 +0300 Subject: Eliminate static buffer in lua findkey() --- rpmio/rpmlua.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/rpmio/rpmlua.c b/rpmio/rpmlua.c index 096a411a0..3345c5604 100644 --- a/rpmio/rpmlua.c +++ b/rpmio/rpmlua.c @@ -217,10 +217,19 @@ void rpmluaGetVar(rpmlua _lua, rpmluav var) #define FINDKEY_REMOVE 2 static int findkey(lua_State *L, int oper, const char *key, va_list va) { - char buf[BUFSIZ]; + char *buf; const char *s, *e; int ret = 0; - (void) vsnprintf(buf, sizeof(buf), key, va); + int blen; + + blen = vsnprintf(NULL, 0, key, va); + if (blen <= 0) { + return -1; + } + + buf = xmalloc(blen + 1); + vsnprintf(buf, blen + 1, key, va); + s = e = buf; lua_pushvalue(L, LUA_GLOBALSINDEX); for (;;) { @@ -263,6 +272,7 @@ static int findkey(lua_State *L, int oper, const char *key, va_list va) } e++; } + free(buf); return ret; } -- cgit v1.2.3