[Pcsclite-cvs-commit] r5901 - /trunk/PCSC/src/debuglog.c

rousseau at users.alioth.debian.org rousseau at users.alioth.debian.org
Sun Aug 21 13:53:37 UTC 2011


Author: rousseau
Date: Sun Aug 21 13:53:37 2011
New Revision: 5901

URL: http://svn.debian.org/wsvn/pcsclite/?sc=1&rev=5901
Log:
log_xxd_always(): Use a variable-length array

The debug message buffer is no more with a fixed size (around 600 bytes
of buffer to log) but uses a variable-length array.

It is now possible to log extended APDU of 64kB.

The variable-length array feature is available in GCC in C90 mode and is
mandatory in C99 standard.

Modified:
    trunk/PCSC/src/debuglog.c

Modified: trunk/PCSC/src/debuglog.c
URL: http://svn.debian.org/wsvn/pcsclite/trunk/PCSC/src/debuglog.c?rev=5901&op=diff
==============================================================================
--- trunk/PCSC/src/debuglog.c (original)
+++ trunk/PCSC/src/debuglog.c Sun Aug 21 13:53:37 2011
@@ -79,10 +79,9 @@
 #else
 
 /**
- * Max string size when dumping a 256 bytes longs APDU
- * Should be bigger than 256*3+30
+ * Max string size dumping a maxmium of 2 lines of 80 characters
  */
-#define DEBUG_BUF_SIZE 2048
+#define DEBUG_BUF_SIZE 160
 
 static char LogMsgType = DEBUGLOG_NO_DEBUG;
 static char LogCategory = DEBUG_CATEGORY_NOTHING;
@@ -177,26 +176,20 @@
 static void log_xxd_always(const int priority, const char *msg,
 	const unsigned char *buffer, const int len)
 {
-	char DebugBuffer[DEBUG_BUF_SIZE];
+	char DebugBuffer[len*3 + strlen(msg) +1];
 	int i;
 	char *c;
-	char *debug_buf_end;
-
-	debug_buf_end = DebugBuffer + sizeof DebugBuffer - 5;
-
-	strlcpy(DebugBuffer, msg, sizeof(DebugBuffer));
-	c = DebugBuffer + strlen(DebugBuffer);
-
-	for (i = 0; (i < len) && (c < debug_buf_end); ++i)
+	size_t l;
+
+	l = strlcpy(DebugBuffer, msg, sizeof(DebugBuffer));
+	c = DebugBuffer + l;
+
+	for (i = 0; (i < len); ++i)
 	{
 		/* 2 hex characters, 1 space, 1 NUL : total 4 characters */
 		snprintf(c, 4, "%02X ", buffer[i]);
 		c += 3;
 	}
-
-	/* the buffer is too small so end it with "..." */
-	if ((c >= debug_buf_end) && (i < len))
-		c[-3] = c[-2] = c[-1] = '.';
 
 	log_line(priority, DebugBuffer);
 } /* log_xxd_always */




More information about the Pcsclite-cvs-commit mailing list