diff --git a/src/libzzuf/debug.c b/src/libzzuf/debug.c index c57e2e1..a674f3c 100644 --- a/src/libzzuf/debug.c +++ b/src/libzzuf/debug.c @@ -331,14 +331,14 @@ static void mydebug(char const *format, va_list args) errno = saved_errno; } -void zzuf_debug_str(char *str, uint8_t const *buffer, - unsigned len, unsigned maxlen) +void zzuf_debug_str(char *str, uint8_t const *buffer, int len, int maxlen) { /* Open the double quotes */ - *str++ = '"'; + if (len >= 0) + *str++ = '"'; /* Print as many escaped characters as possible */ - for (unsigned i = 0; i < len; ++i) + for (int i = 0; i < len; ++i) { if (len > maxlen && i == maxlen / 2) { @@ -372,7 +372,8 @@ void zzuf_debug_str(char *str, uint8_t const *buffer, } /* Close the double quotes */ - *str++ = '"'; + if (len >= 0) + *str++ = '"'; *str++ = '\0'; } diff --git a/src/libzzuf/debug.h b/src/libzzuf/debug.h index 43b6d54..d628f0e 100644 --- a/src/libzzuf/debug.h +++ b/src/libzzuf/debug.h @@ -17,7 +17,7 @@ extern void zzuf_debug(char const *format, ...) ATTRIBUTE_PRINTF(1,2); extern void zzuf_debug2(char const *format, ...) ATTRIBUTE_PRINTF(1,2); extern void zzuf_debug_str(char *str, uint8_t const *buffer, - unsigned len, unsigned maxlen); + int len, int maxlen); #ifdef LIBZZUF # define debug zzuf_debug