diff options
-rw-r--r-- | source3/CodingSuggestions | 4 | ||||
-rw-r--r-- | source3/include/includes.h | 8 | ||||
-rw-r--r-- | source3/lib/dprintf.c | 7 | ||||
-rw-r--r-- | source3/lib/snprintf.c | 18 | ||||
-rw-r--r-- | source3/lib/talloc.c | 23 | ||||
-rw-r--r-- | source3/lib/util.c | 8 | ||||
-rw-r--r-- | source3/lib/xfile.c | 8 |
7 files changed, 30 insertions, 46 deletions
diff --git a/source3/CodingSuggestions b/source3/CodingSuggestions index 1ff3e01c1c..eda2bee6d0 100644 --- a/source3/CodingSuggestions +++ b/source3/CodingSuggestions @@ -59,8 +59,8 @@ Here are some other suggestions: 6) explicitly add const qualifiers on parm passing in functions where parm is input only (somewhat controversial but const can be #defined away) -7) when passing a va_list as an arg, or assigning one to another, check - for HAVE_VA_COPY, and use it if it exists. +7) when passing a va_list as an arg, or assigning one to another + please use the VA_COPY() macro reason: on some platforms, va_list is a struct that must be initialized in each function...can SEGV if you don't. diff --git a/source3/include/includes.h b/source3/include/includes.h index 3d71f43303..705cb485fd 100644 --- a/source3/include/includes.h +++ b/source3/include/includes.h @@ -1164,5 +1164,13 @@ int asprintf(char **,const char *, ...) PRINTF_ATTRIBUTE(2,3); #define slprintf snprintf #define vslprintf vsnprintf + +/* we need to use __va_copy() on some platforms */ +#ifdef HAVE_VA_COPY +#define VA_COPY(dest, src) __va_copy(dest, src) +#else +#define VA_COPY(dest, src) (dest) = (src) +#endif + #endif /* _INCLUDES_H */ diff --git a/source3/lib/dprintf.c b/source3/lib/dprintf.c index e3aa2c7669..f0f09e199d 100644 --- a/source3/lib/dprintf.c +++ b/source3/lib/dprintf.c @@ -42,11 +42,8 @@ int d_vfprintf(FILE *f, const char *format, va_list ap) msgstr = lang_msg(format); if (!msgstr) return -1; -#if defined(HAVE_VA_COPY) - __va_copy(ap2, ap); -#else - ap2 = ap; -#endif + VA_COPY(ap2, ap); + ret = vasprintf(&p, msgstr, ap2); lang_msg_free(msgstr); diff --git a/source3/lib/snprintf.c b/source3/lib/snprintf.c index 561e775c8f..aaad55f22a 100644 --- a/source3/lib/snprintf.c +++ b/source3/lib/snprintf.c @@ -163,11 +163,7 @@ static size_t dopr(char *buffer, size_t maxlen, const char *format, va_list args size_t currlen; va_list args; -#if defined(HAVE_VA_COPY) - __va_copy(args, args_in); -#else - args = args_in; -#endif + VA_COPY(args, args_in); state = DP_S_DEFAULT; currlen = flags = cflags = min = 0; @@ -802,20 +798,16 @@ static void dopr_outch(char *buffer, size_t *currlen, size_t maxlen, char c) int ret; va_list ap2; -#if defined(HAVE_VA_COPY) - __va_copy(ap2, ap); -#else - ap2 = ap; -#endif + VA_COPY(ap2, ap); ret = vsnprintf(NULL, 0, format, ap2); if (ret <= 0) return ret; (*ptr) = (char *)malloc(ret+1); if (!*ptr) return -1; -#if defined(HAVE_VA_COPY) - __va_copy(ap2, ap); -#endif + + VA_COPY(ap2, ap); + ret = vsnprintf(*ptr, ret+1, format, ap2); return ret; diff --git a/source3/lib/talloc.c b/source3/lib/talloc.c index b66d674dd5..d81528588c 100644 --- a/source3/lib/talloc.c +++ b/source3/lib/talloc.c @@ -318,18 +318,13 @@ smb_ucs2_t *talloc_strdup_w(TALLOC_CTX *t, const smb_ucs2_t *p) char *ret; va_list ap2; -#ifdef HAVE_VA_COPY - __va_copy(ap2, ap); /* for systems were va_list is a struct */ -#else - ap2 = ap; -#endif + VA_COPY(ap2, ap); + len = vsnprintf(NULL, 0, fmt, ap2); ret = talloc(t, len+1); if (ret) { -#ifdef HAVE_VA_COPY - __va_copy(ap2, ap); -#endif + VA_COPY(ap2, ap); vsnprintf(ret, len+1, fmt, ap2); } @@ -366,20 +361,16 @@ smb_ucs2_t *talloc_strdup_w(TALLOC_CTX *t, const smb_ucs2_t *p) int len, s_len; va_list ap2; -#ifdef HAVE_VA_COPY - __va_copy(ap2, ap); -#else - ap2 = ap; -#endif + VA_COPY(ap2, ap); + s_len = strlen(s); len = vsnprintf(NULL, 0, fmt, ap2); s = talloc_realloc(t, s, s_len + len+1); if (!s) return NULL; -#ifdef HAVE_VA_COPY - __va_copy(ap2, ap); -#endif + VA_COPY(ap2, ap); + vsnprintf(s+s_len, len+1, fmt, ap2); return s; diff --git a/source3/lib/util.c b/source3/lib/util.c index 2fe9ec331b..fe1011668d 100644 --- a/source3/lib/util.c +++ b/source3/lib/util.c @@ -1820,11 +1820,9 @@ int smb_xvasprintf(char **ptr, const char *format, va_list ap) { int n; va_list ap2; -#if defined(HAVE_VA_COPY) - __va_copy(ap2, ap); -#else - ap2 = ap; -#endif + + VA_COPY(ap2, ap); + n = vasprintf(ptr, format, ap2); if (n == -1 || ! *ptr) { smb_panic("smb_xvasprintf: out of memory"); diff --git a/source3/lib/xfile.c b/source3/lib/xfile.c index 7b97d329ae..59f9fd48ad 100644 --- a/source3/lib/xfile.c +++ b/source3/lib/xfile.c @@ -188,11 +188,9 @@ int x_vfprintf(XFILE *f, const char *format, va_list ap) char *p; int len, ret; va_list ap2; -#if defined(HAVE_VA_COPY) - __va_copy(ap2, ap); -#else - ap2 = ap; -#endif + + VA_COPY(ap2, ap); + len = vasprintf(&p, format, ap2); if (len <= 0) return len; ret = x_fwrite(p, 1, len, f); |