1
0
mirror of https://github.com/nmap/nmap.git synced 2025-12-20 06:29:02 +00:00

Adding (using) a static Snprintf() to nselib/pcre.c, due to lame problems with nbase + pcrelib on some systems

This commit is contained in:
kris
2007-08-14 16:32:10 +00:00
parent 5396114d73
commit 0118f48500
2 changed files with 20 additions and 4 deletions

View File

@@ -6,6 +6,7 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <stdarg.h>
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
@@ -22,6 +23,21 @@ extern "C" {
#include "pcre.h" #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) static void L_lua_error(lua_State *L, const char *message)
{ {
int status; 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); void *udata = luaL_checkudata(L, 1, type_handle);
if(udata) { if(udata) {
(void)snprintf(buf, 255, "%s (%p)", type_name, udata); (void)Snprintf(buf, 255, "%s (%p)", type_name, udata);
lua_pushstring(L, buf); lua_pushstring(L, buf);
} }
else { 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); (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); ud->pr = pcre_compile(pattern, cflags, &error, &erroffset, tables);
if(!ud->pr) { 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 */ /* show offset 1-based as it's common in Lua */
L_lua_error(L, buf); L_lua_error(L, buf);
} }

View File

@@ -2,7 +2,7 @@
#define PCRE_H #define PCRE_H
#ifdef WIN32 #ifdef WIN32
#define snprintf _snprintf #define vsnprintf _vsnprintf
#endif /* WIN32 */ #endif /* WIN32 */
#define NSE_PCRELIBNAME "pcre" #define NSE_PCRELIBNAME "pcre"