tech-pkg archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Fix for libnbcompat's asprintf



Hi all,
there is an old outstanding bug that libnbcompat's asprintf doesn't work
correctly, if the output is longer than 128 Bytes. The attached patch
fixes that, as long as either va_copy, __builtin_va_copy or direct
(struct) assignmemnt of va_list is supported. Can I get some testing for
this, especially on HP-UX which has no asprintf?

Joerg
Index: asprintf.c
===================================================================
RCS file: /home/joerg/repo/netbsd/pkgsrc/pkgtools/libnbcompat/files/asprintf.c,v
retrieving revision 1.2
diff -u -p -r1.2 asprintf.c
--- asprintf.c  20 Jul 2007 00:10:06 -0000      1.2
+++ asprintf.c  17 Jun 2012 02:14:12 -0000
@@ -56,6 +56,7 @@ vasprintf(char **ret, const char *fmt, v
        char *buf, *new_buf;
        size_t len;
        int retval;
+       va_list ap2;
 
        len = 128;
        buf = malloc(len);
@@ -64,6 +65,13 @@ vasprintf(char **ret, const char *fmt, v
                return -1;
        }
 
+#if defined(HAVE_VA_COPY)
+       va_copy(ap2, ap);
+#elif defined(HAVE___BUILTIN_VA_COPY)
+       __builtin_va_copy(ap2, ap);
+#else
+       ap2 = ap;
+#endif
        retval = vsnprintf(buf, len, fmt, ap);
        if (retval < 0) {
                free(buf);
@@ -87,7 +95,7 @@ vasprintf(char **ret, const char *fmt, v
                *ret = NULL;
                return -1;
        }
-       retval = vsnprintf(buf, len, fmt, ap);
+       retval = vsnprintf(buf, len, fmt, ap2);
        if (retval != len - 1) {
                free(buf);
                *ret = NULL;
Index: configure
===================================================================
RCS file: /home/joerg/repo/netbsd/pkgsrc/pkgtools/libnbcompat/files/configure,v
retrieving revision 1.77
diff -u -p -r1.77 configure
--- configure   28 Dec 2011 19:19:31 -0000      1.77
+++ configure   17 Jun 2012 02:15:26 -0000
@@ -4486,6 +4486,98 @@ esac
 fi
 
 
+
+       { $as_echo "$as_me:${as_lineno-$LINENO}: checking for va_copy" >&5
+$as_echo_n "checking for va_copy... " >&6; }
+if ${pkg_cv_have_va_copy+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+
+               cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+
+#include <stdarg.h>
+
+int
+main ()
+{
+
+       va_list ap, ap2;
+       va_copy(ap2, ap);
+       return 0;
+;
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_link "$LINENO"; then :
+   pkg_cv_have_va_copy=yes
+else
+   pkg_cv_have_va_copy=no
+fi
+rm -f core conftest.err conftest.$ac_objext \
+    conftest$ac_exeext conftest.$ac_ext
+
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $pkg_cv_have_va_copy" >&5
+$as_echo "$pkg_cv_have_va_copy" >&6; }
+       if test "x$pkg_cv_have_va_copy" = "xyes"; then
+               $as_echo "#define HAVE_VA_COPY 1" >>confdefs.h
+
+
+       else
+               :
+]
+               :
+       fi
+
+
+
+       { $as_echo "$as_me:${as_lineno-$LINENO}: checking for 
__builtin_va_copy" >&5
+$as_echo_n "checking for __builtin_va_copy... " >&6; }
+if ${pkg_cv_have___builtin_va_copy+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+
+               cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+
+#include <stdarg.h>
+
+int
+main ()
+{
+
+       va_list ap, ap2;
+       __builtin_va_copy(ap2, ap);
+       return 0;
+;
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_link "$LINENO"; then :
+   pkg_cv_have___builtin_va_copy=yes
+else
+   pkg_cv_have___builtin_va_copy=no
+fi
+rm -f core conftest.err conftest.$ac_objext \
+    conftest$ac_exeext conftest.$ac_ext
+
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: 
$pkg_cv_have___builtin_va_copy" >&5
+$as_echo "$pkg_cv_have___builtin_va_copy" >&6; }
+       if test "x$pkg_cv_have___builtin_va_copy" = "xyes"; then
+               $as_echo "#define HAVE___BUILTIN_VA_COPY 1" >>confdefs.h
+
+
+       else
+               :
+]
+               :
+       fi
+
+
 for ac_header in md5.h
 do :
   ac_fn_c_check_header_mongrel "$LINENO" "md5.h" "ac_cv_header_md5_h" 
"$ac_includes_default"
Index: configure.ac
===================================================================
RCS file: 
/home/joerg/repo/netbsd/pkgsrc/pkgtools/libnbcompat/files/configure.ac,v
retrieving revision 1.78
diff -u -p -r1.78 configure.ac
--- configure.ac        28 Dec 2011 19:19:31 -0000      1.78
+++ configure.ac        17 Jun 2012 02:15:22 -0000
@@ -78,6 +78,30 @@ AC_CHECK_FUNC(regexec, [:], [
        AC_LIBOBJ(regfree)
 ])
 
+AC_MSG_TRY_LINK([for va_copy], pkg_cv_have_va_copy, [
+#include <stdarg.h>
+], [
+       va_list ap, ap2;
+       va_copy(ap2, ap);
+       return 0;
+],     AC_DEFINE(HAVE_VA_COPY)
+       AH_TEMPLATE([HAVE_VA_COPY], [
+               Define to 1 if the `va_copy' function is supported.
+       ]), [:]
+])
+
+AC_MSG_TRY_LINK([for __builtin_va_copy], pkg_cv_have___builtin_va_copy, [
+#include <stdarg.h>
+], [
+       va_list ap, ap2;
+       __builtin_va_copy(ap2, ap);
+       return 0;
+],     AC_DEFINE(HAVE___BUILTIN_VA_COPY)
+       AH_TEMPLATE([HAVE___BUILTIN_VA_COPY], [
+               Define to 1 if the `__builtin_va_copy' function is supported.
+       ]), [:]
+])
+
 AC_CHECK_HEADERS([md5.h], [
        AC_MSG_TRY_COMPILE([for MD5Init in md5.h], pkg_cv_have_md5init, [
                #include <sys/types.h>
Index: nbcompat/config.h.in
===================================================================
RCS file: 
/home/joerg/repo/netbsd/pkgsrc/pkgtools/libnbcompat/files/nbcompat/config.h.in,v
retrieving revision 1.29
diff -u -p -r1.29 config.h.in
--- nbcompat/config.h.in        20 Apr 2010 00:32:23 -0000      1.29
+++ nbcompat/config.h.in        17 Jun 2012 02:09:59 -0000
@@ -508,6 +508,9 @@
 /* Define to 1 if you have the <utime.h> header file. */
 #undef HAVE_UTIME_H
 
+/* Define to 1 if the `va_copy' function is supported. */
+#undef HAVE_VA_COPY
+
 /* Define to 1 if you have the `vfork' function. */
 #undef HAVE_VFORK
 
@@ -541,6 +544,9 @@
 /* define if your compiler has __attribute__ */
 #undef HAVE___ATTRIBUTE__
 
+/* Define to 1 if the `__builtin_va_copy' function is supported. */
+#undef HAVE___BUILTIN_VA_COPY
+
 /* Define to the address where bug reports for this package should be sent. */
 #undef PACKAGE_BUGREPORT
 


Home | Main Index | Thread Index | Old Index