mirror of
https://github.com/samba-team/samba.git
synced 2024-12-23 17:34:34 +03:00
put the ifdef for HAVE_VA_COPY in one place rather than in lots of
functions
(This used to be commit 1cf3228fdc
)
This commit is contained in:
parent
9401cdbb51
commit
0bb6053946
@ -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.
|
||||
|
||||
|
@ -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 */
|
||||
|
||||
|
@ -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);
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
@ -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");
|
||||
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user