[Pkg-gnupg-commit] [libassuan] 407/437: Avoid a vasprintf call if tracing has not been enabled.

Eric Dorland eric at moszumanska.debian.org
Fri May 22 05:34:10 UTC 2015


This is an automated email from the git hooks/post-receive script.

eric pushed a commit to branch master
in repository libassuan.

commit 134c045c7d1f93ce61f62193d33af8a6e8825543
Author: Werner Koch <wk at gnupg.org>
Date:   Wed Jun 25 20:25:28 2014 +0200

    Avoid a vasprintf call if tracing has not been enabled.
    
    * src/debug.c (_assuan_debug): Check wether CAT want to be logged.
---
 src/debug.c | 28 ++++++++++++++++------------
 1 file changed, 16 insertions(+), 12 deletions(-)

diff --git a/src/debug.c b/src/debug.c
index 5ed4d4d..d6c3e80 100644
--- a/src/debug.c
+++ b/src/debug.c
@@ -1,22 +1,22 @@
 /* debug.c - helpful output in desperate situations
    Copyright (C) 2000 Werner Koch (dd9jn)
    Copyright (C) 2001, 2002, 2003, 2004, 2005, 2007, 2009 g10 Code GmbH
- 
+
    This file is part of Assuan.
 
    Assuan is free software; you can redistribute it and/or modify it
    under the terms of the GNU Lesser General Public License as
    published by the Free Software Foundation; either version 2.1 of
    the License, or (at your option) any later version.
-   
+
    Assuan is distributed in the hope that it will be useful, but
    WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    Lesser General Public License for more details.
-   
+
    You should have received a copy of the GNU Lesser General Public
    License along with this program; if not, write to the Free Software
-   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 
+   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
    MA 02110-1301, USA.  */
 
 #if HAVE_CONFIG_H
@@ -51,7 +51,11 @@ _assuan_debug (assuan_context_t ctx, unsigned int cat, const char *format, ...)
   char *msg;
   int res;
 
-  if (!ctx || !ctx->log_cb)
+  /* vasprintf is an expensive operation thus we first check whether
+     the callback has enabled CAT for logging.  */
+  if (!ctx
+      || !ctx->log_cb
+      || !(*ctx->log_cb) (ctx, ctx->log_cb_data, cat, NULL))
     return;
 
   saved_errno = errno;
@@ -77,11 +81,11 @@ _assuan_debug_begin (assuan_context_t ctx,
 
   *line = NULL;
   /* Probe if this wants to be logged based on category.  */
-  if (! ctx 
-      || ! ctx->log_cb 
+  if (! ctx
+      || ! ctx->log_cb
       || ! (*ctx->log_cb) (ctx, ctx->log_cb_data, cat, NULL))
     return;
-  
+
   va_start (arg_ptr, format);
   res = vasprintf ((char **) line, format, arg_ptr);
   va_end (arg_ptr);
@@ -147,8 +151,8 @@ _assuan_debug_buffer (assuan_context_t ctx, unsigned int cat,
   int j;
 
   /* Probe if this wants to be logged based on category.  */
-  if (!ctx 
-      || ! ctx->log_cb 
+  if (!ctx
+      || ! ctx->log_cb
       || ! (*ctx->log_cb) (ctx, ctx->log_cb_data, cat, NULL))
     return;
 
@@ -157,7 +161,7 @@ _assuan_debug_buffer (assuan_context_t ctx, unsigned int cat,
       char str[51];
       char *strp = str;
       char *strp2 = &str[34];
-      
+
       for (j = 0; j < 16; j++)
 	{
 	  unsigned char val;
@@ -179,7 +183,7 @@ _assuan_debug_buffer (assuan_context_t ctx, unsigned int cat,
       *(strp++) = ' ';
       *(strp2++) = '\n';
       *(strp2) = '\0';
-      
+
       _assuan_debug (ctx, cat, fmt, func, tagname, tag, str);
     }
 }

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-gnupg/libassuan.git



More information about the Pkg-gnupg-commit mailing list