Allow debug_str to be provided a negative length count for convenience.

This commit is contained in:
Sam Hocevar
2015-01-24 16:01:29 +01:00
parent c88842f9a4
commit 56b013a605
2 changed files with 7 additions and 6 deletions
+6 -5
View File
@@ -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';
}
+1 -1
View File
@@ -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