r19909: Make this one double as fast
authorSimo Sorce <idra@samba.org>
Sun, 26 Nov 2006 21:49:25 +0000 (21:49 +0000)
committerGerald (Jerry) Carter <jerry@samba.org>
Wed, 10 Oct 2007 19:28:35 +0000 (14:28 -0500)
(This used to be commit 67b88e49b896f1d783619b8f96554adaeabe80df)

source4/lib/ldb/common/ldb_msg.c

index e9ba66aff5ddf11d70c41e5ffa138087195f209c..0f7a214023905df589b0a413a806e8b7002abb50 100644 (file)
@@ -763,17 +763,29 @@ void ldb_msg_remove_element(struct ldb_message *msg, struct ldb_message_element
 char *ldb_timestring(TALLOC_CTX *mem_ctx, time_t t)
 {
        struct tm *tm = gmtime(&t);
+       char *ts;
+       int r;
 
        if (!tm) {
                return NULL;
        }
 
+       /* we now excatly how long this string will be */
+       ts = talloc_array(mem_ctx, char, 18);
+
        /* formatted like: 20040408072012.0Z */
-       return talloc_asprintf(mem_ctx, 
-                              "%04u%02u%02u%02u%02u%02u.0Z",
-                              tm->tm_year+1900, tm->tm_mon+1,
-                              tm->tm_mday, tm->tm_hour, tm->tm_min,
-                              tm->tm_sec);
+       r = snprintf(ts, 18,
+                       "%04u%02u%02u%02u%02u%02u.0Z",
+                       tm->tm_year+1900, tm->tm_mon+1,
+                       tm->tm_mday, tm->tm_hour, tm->tm_min,
+                       tm->tm_sec);
+
+       if (r != 17) {
+               talloc_free(ts);
+               return NULL;
+       }
+
+       return ts;
 }