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.
#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 */
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);
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;
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;
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);
}
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;
{
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");
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);