Skip to content

Commit

Permalink
log_xxd_always(): Use a variable-length array
Browse files Browse the repository at this point in the history
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.

git-svn-id: svn:https://anonscm.debian.org/svn/pcsclite/trunk/PCSC@5901 0ce88b0d-b2fd-0310-8134-9614164e65ea
  • Loading branch information
LudovicRousseau committed Aug 21, 2011
1 parent 3868286 commit 56c2785
Showing 1 changed file with 7 additions and 14 deletions.
21 changes: 7 additions & 14 deletions src/debuglog.c
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,9 @@ INTERNAL void DebugLogCategory(const int category, const unsigned char *buffer,
#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;
Expand Down Expand Up @@ -177,27 +176,21 @@ static void log_line(const int priority, const char *DebugBuffer)
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;
size_t l;

strlcpy(DebugBuffer, msg, sizeof(DebugBuffer));
c = DebugBuffer + strlen(DebugBuffer);
l = strlcpy(DebugBuffer, msg, sizeof(DebugBuffer));
c = DebugBuffer + l;

for (i = 0; (i < len) && (c < debug_buf_end); ++i)
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 */

Expand Down

0 comments on commit 56c2785

Please sign in to comment.