From a79291e081170562730b07df5f804bdf8ed11202 Mon Sep 17 00:00:00 2001 From: JustAnotherArchivist Date: Mon, 9 Jan 2023 20:52:56 +0000 Subject: [PATCH] Fix debug output for small/empty buffer --- http-response-bodies.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/http-response-bodies.c b/http-response-bodies.c index a61ddab..00f25ec 100644 --- a/http-response-bodies.c +++ b/http-response-bodies.c @@ -43,7 +43,7 @@ int main(int argc, char* argv[]) { checkstate: DEBUG_PRINTF("Have %zu bytes of buffer (at %p)\n", n, (void*)bufp); DEBUG_PRINTF("Beginning of buffer: "); - for (int i = 0; i < 64; ++i) DEBUG_PRINTF(isprint(*(bufp + i)) ? "%c" : "\\x%02x", *(bufp + i) & 0xFF); + for (int i = 0; i < (n > 64 ? 64 : n); ++i) DEBUG_PRINTF(isprint(*(bufp + i)) ? "%c" : "\\x%02x", *(bufp + i) & 0xFF); DEBUG_PRINTF("\n"); if (n == 0) { break;