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 *, ...)
__attribute__ ((format (printf, 3, 4)));
char *alloc_vsprintf(const char *fmt, va_list va)
__attribute__ ((format (printf, 1, 0)));
int alloc_vsprintf(char **strp, const char *fmt, va_list va)
__attribute__ ((format (printf, 2, 0)));
/* Trivial function that returns nonzero if all characters in str of
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
Glibc. Return the buffer or NULL on error. */
char *alloc_vsprintf(const char *fmt, va_list va) {
Glibc. Return the length of the buffer or -1 on error. */
int alloc_vsprintf(char **strp, const char *fmt, va_list va) {
va_list va_tmp;
char *s, *p;
char *s;
int size = 32;
int n;
s = NULL;
size = 32;
for (;;) {
p = (char *) safe_realloc(s, size);
if (p == NULL)
return NULL;
s = p;
s = (char *) safe_realloc(s, size);
#ifdef WIN32
va_tmp = va;
@@ -195,8 +192,9 @@ char *alloc_vsprintf(const char *fmt, va_list va) {
else
break;
}
*strp = s;
return s;
return n;
}
/* 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_SKID:
case LOG_XML:
writebuf = alloc_vsprintf(fmt, ap);
len = alloc_vsprintf(&writebuf, fmt, ap);
if (writebuf == NULL)
fatal("%s: alloc_vsprintf failed.", __func__);
len = strlen(writebuf);
l = logt;
fileidx = 0;
while ((l & 1) == 0) {

6
xml.cc
View File

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