From 0118f485002c806e08ef07f79342fc1ee125eee7 Mon Sep 17 00:00:00 2001 From: kris Date: Tue, 14 Aug 2007 16:32:10 +0000 Subject: [PATCH] Adding (using) a static Snprintf() to nselib/pcre.c, due to lame problems with nbase + pcrelib on some systems --- nselib/pcre.c | 22 +++++++++++++++++++--- nselib/pcre.h | 2 +- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/nselib/pcre.c b/nselib/pcre.c index 9a2ea2bbe..d772e1277 100644 --- a/nselib/pcre.c +++ b/nselib/pcre.c @@ -6,6 +6,7 @@ #include #include #include +#include #ifdef __cplusplus extern "C" { @@ -22,6 +23,21 @@ extern "C" { #include "pcre.h" +static int Snprintf(char *s, size_t n, const char *fmt, ...) +{ + va_list ap; + int ret; + + va_start(ap, fmt); + ret = vsnprintf(s, n, fmt, ap); + va_end(ap); + + if (ret < 0 || (unsigned) ret >= n) + s[n - 1] = '\0'; + + return ret; +} + static void L_lua_error(lua_State *L, const char *message) { int status; @@ -50,11 +66,11 @@ static int udata_tostring (lua_State *L, const char* type_handle, void *udata = luaL_checkudata(L, 1, type_handle); if(udata) { - (void)snprintf(buf, 255, "%s (%p)", type_name, udata); + (void)Snprintf(buf, 255, "%s (%p)", type_name, udata); lua_pushstring(L, buf); } else { - (void)snprintf(buf, 255, "must be userdata of type '%s'", type_name); + (void)Snprintf(buf, 255, "must be userdata of type '%s'", type_name); (void)luaL_argerror(L, 1, buf); } @@ -140,7 +156,7 @@ static int Lpcre_comp(lua_State *L) ud->pr = pcre_compile(pattern, cflags, &error, &erroffset, tables); if(!ud->pr) { - (void)snprintf(buf, 255, "%s (pattern offset: %d)", error, erroffset+1); + (void)Snprintf(buf, 255, "%s (pattern offset: %d)", error, erroffset+1); /* show offset 1-based as it's common in Lua */ L_lua_error(L, buf); } diff --git a/nselib/pcre.h b/nselib/pcre.h index 637396277..e10abdec9 100644 --- a/nselib/pcre.h +++ b/nselib/pcre.h @@ -2,7 +2,7 @@ #define PCRE_H #ifdef WIN32 -#define snprintf _snprintf +#define vsnprintf _vsnprintf #endif /* WIN32 */ #define NSE_PCRELIBNAME "pcre"