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

Change alloc_sprintf to return a length.

This commit is contained in:
david
2012-03-08 23:56:26 +00:00
parent 23133dccf2
commit e1576d1d14
4 changed files with 12 additions and 15 deletions

View File

@@ -395,8 +395,8 @@ int Vsnprintf(char *, size_t, const char *, va_list)
int Snprintf(char *, size_t, const char *, ...) int Snprintf(char *, size_t, const char *, ...)
__attribute__ ((format (printf, 3, 4))); __attribute__ ((format (printf, 3, 4)));
char *alloc_vsprintf(const char *fmt, va_list va) int alloc_vsprintf(char **strp, const char *fmt, va_list va)
__attribute__ ((format (printf, 1, 0))); __attribute__ ((format (printf, 2, 0)));
/* Trivial function that returns nonzero if all characters in str of /* Trivial function that returns nonzero if all characters in str of
length strlength are printable (as defined by isprint()) */ length strlength are printable (as defined by isprint()) */

View File

@@ -166,20 +166,17 @@ int Snprintf(char *s, size_t n, const char *fmt, ...)
} }
/* vsprintf into a dynamically allocated buffer, similar to asprintf in /* vsprintf into a dynamically allocated buffer, similar to asprintf in
Glibc. Return the buffer or NULL on error. */ Glibc. Return the length of the buffer or -1 on error. */
char *alloc_vsprintf(const char *fmt, va_list va) { int alloc_vsprintf(char **strp, const char *fmt, va_list va) {
va_list va_tmp; va_list va_tmp;
char *s, *p; char *s;
int size = 32; int size = 32;
int n; int n;
s = NULL; s = NULL;
size = 32; size = 32;
for (;;) { for (;;) {
p = (char *) safe_realloc(s, size); s = (char *) safe_realloc(s, size);
if (p == NULL)
return NULL;
s = p;
#ifdef WIN32 #ifdef WIN32
va_tmp = va; va_tmp = va;
@@ -195,8 +192,9 @@ char *alloc_vsprintf(const char *fmt, va_list va) {
else else
break; break;
} }
*strp = s;
return s; return n;
} }
/* Trivial function that returns nonzero if all characters in str of length strlength are /* Trivial function that returns nonzero if all characters in str of length strlength are

View File

@@ -939,10 +939,9 @@ void log_vwrite(int logt, const char *fmt, va_list ap) {
case LOG_MACHINE: case LOG_MACHINE:
case LOG_SKID: case LOG_SKID:
case LOG_XML: case LOG_XML:
writebuf = alloc_vsprintf(fmt, ap); len = alloc_vsprintf(&writebuf, fmt, ap);
if (writebuf == NULL) if (writebuf == NULL)
fatal("%s: alloc_vsprintf failed.", __func__); fatal("%s: alloc_vsprintf failed.", __func__);
len = strlen(writebuf);
l = logt; l = logt;
fileidx = 0; fileidx = 0;
while ((l & 1) == 0) { while ((l & 1) == 0) {

6
xml.cc
View File

@@ -236,7 +236,7 @@ int xml_write_raw(const char *fmt, ...) {
char *s; char *s;
va_start(va, fmt); va_start(va, fmt);
s = alloc_vsprintf(fmt, va); alloc_vsprintf(&s, fmt, va);
va_end(va); va_end(va);
if (s == NULL) if (s == NULL)
return -1; return -1;
@@ -264,7 +264,7 @@ int xml_write_escaped(const char *fmt, ...) {
int xml_write_escaped_v(const char *fmt, va_list va) { int xml_write_escaped_v(const char *fmt, va_list va) {
char *s, *esc_s; char *s, *esc_s;
s = alloc_vsprintf(fmt, va); alloc_vsprintf(&s, fmt, va);
if (s == NULL) if (s == NULL)
return -1; return -1;
esc_s = escape(s); esc_s = escape(s);
@@ -386,7 +386,7 @@ int xml_attribute(const char *name, const char *fmt, ...) {
assert(xml.tag_open); assert(xml.tag_open);
va_start(va, fmt); va_start(va, fmt);
val = alloc_vsprintf(fmt, va); alloc_vsprintf(&val, fmt, va);
va_end(va); va_end(va);
if (val == NULL) if (val == NULL)
return -1; return -1;