tdb2: use vasprintf.
authorRusty Russell <rusty@rustcorp.com.au>
Thu, 17 Mar 2011 11:42:21 +0000 (22:12 +1030)
committerRusty Russell <rusty@rustcorp.com.au>
Thu, 17 Mar 2011 11:42:21 +0000 (22:12 +1030)
ccan/tdb2/_info
ccan/tdb2/tdb.c
ccan/tdb2/test/failtest_helper.c
ccan/tdb2/test/failtest_helper.h

index 114b60b2182c7daefbaf585b15c9d9f3a2cc2033..67ad3f6c340189d18074ca93fd665fe82743a772 100644 (file)
@@ -76,6 +76,7 @@ int main(int argc, char *argv[])
                return 1;
 
        if (strcmp(argv[1], "depends") == 0) {
+               printf("ccan/asprintf\n");
                printf("ccan/hash\n");
                printf("ccan/likely\n");
                printf("ccan/asearch\n");
index f6ca01657518af29c1111700c530abda29ba7d43..2315c485eea31be3c40af274243f39cc55f633e0 100644 (file)
@@ -1,4 +1,5 @@
 #include "private.h"
+#include <ccan/asprintf/asprintf.h>
 #include <ccan/tdb2/tdb2.h>
 #include <assert.h>
 #include <stdarg.h>
@@ -756,23 +757,18 @@ enum TDB_ERROR COLD tdb_logerr(struct tdb_context *tdb,
        if (!tdb->logfn)
                return ecode;
 
-       /* FIXME: Doesn't assume asprintf. */
        va_start(ap, fmt);
-       len = vsnprintf(NULL, 0, fmt, ap);
+       len = vasprintf(&message, fmt, ap);
        va_end(ap);
 
-       message = malloc(len + 1);
-       if (!message) {
+       if (len < 0) {
                tdb->logfn(tdb, TDB_LOG_ERROR, tdb->log_private,
                           "out of memory formatting message:");
                tdb->logfn(tdb, level, tdb->log_private, fmt);
-               return ecode;
+       } else {
+               tdb->logfn(tdb, level, tdb->log_private, message);
+               free(message);
        }
-       va_start(ap, fmt);
-       len = vsprintf(message, fmt, ap);
-       va_end(ap);
-       tdb->logfn(tdb, level, tdb->log_private, message);
-       free(message);
        errno = saved_errno;
        return ecode;
 }
index a9ba4b478489fe3d97a0ab43835ae53a076a5683..1358a6c6b261d3b296a296d123c36693afe07ff1 100644 (file)
@@ -85,7 +85,6 @@ block_repeat_failures(struct failtest_call *history, unsigned num)
        const struct failtest_call *i, *last = &history[num-1];
 
        if (failmatch(last, INITIAL_TDB_MALLOC)
-           || failmatch(last, LOGGING_MALLOC)
            || failmatch(last, URANDOM_OPEN)
            || failmatch(last, URANDOM_READ)) {
                if (find_repeat(history, last, last))
index 656f7cd7fd712c9c038348d5932507188d9c2cb5..25bf21d04cb20e972614ee2f5553601ae35ca0f4 100644 (file)
@@ -4,8 +4,7 @@
 #include <stdbool.h>
 
 /* FIXME: Check these! */
-#define INITIAL_TDB_MALLOC     "tdb.c", 189, FAILTEST_MALLOC
-#define LOGGING_MALLOC         "tdb.c", 766, FAILTEST_MALLOC
+#define INITIAL_TDB_MALLOC     "tdb.c", 190, FAILTEST_MALLOC
 #define URANDOM_OPEN           "tdb.c", 49, FAILTEST_OPEN
 #define URANDOM_READ           "tdb.c", 29, FAILTEST_READ