diff options
author | Panu Matilainen <pmatilai@redhat.com> | 2008-05-06 10:00:07 +0300 |
---|---|---|
committer | Panu Matilainen <pmatilai@redhat.com> | 2008-05-06 10:02:07 +0300 |
commit | 41147e5b18ad09b04697c3aa729539689547281c (patch) | |
tree | 38c0a84745309f476b7d115507c0425cb45b443f | |
parent | e5df40e683552c4f5b36f029ff5bced39058452b (diff) | |
download | rpm-41147e5b18ad09b04697c3aa729539689547281c.tar.gz rpm-41147e5b18ad09b04697c3aa729539689547281c.tar.bz2 rpm-41147e5b18ad09b04697c3aa729539689547281c.zip |
Eliminate static buffer in lua findkey()
-rw-r--r-- | rpmio/rpmlua.c | 14 |
1 files 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; } |