From 8ec78bcbbf38963f69a7f81afee438eb08d55b52 Mon Sep 17 00:00:00 2001 From: Simo Sorce Date: Sun, 26 Nov 2006 21:49:25 +0000 Subject: [PATCH] r19909: Make this one double as fast (This used to be commit 67b88e49b896f1d783619b8f96554adaeabe80df) --- source4/lib/ldb/common/ldb_msg.c | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/source4/lib/ldb/common/ldb_msg.c b/source4/lib/ldb/common/ldb_msg.c index e9ba66aff5..0f7a214023 100644 --- a/source4/lib/ldb/common/ldb_msg.c +++ b/source4/lib/ldb/common/ldb_msg.c @@ -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; } -- 2.34.1