From 427884af5e57d6064e1b68529b8ea226bde303a6 Mon Sep 17 00:00:00 2001 From: JustAnotherArchivist Date: Sat, 29 Apr 2023 21:34:36 +0000 Subject: [PATCH] Fix warnings --- http-response-bodies.c | 7 ++++--- warc-dump-responses.c | 2 +- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/http-response-bodies.c b/http-response-bodies.c index 07bcc5f..8e3c0f9 100644 --- a/http-response-bodies.c +++ b/http-response-bodies.c @@ -91,6 +91,7 @@ checkstate: } // Handle optional URL + Length line url = NULL; + urllen = 0; if (memcmp(bufp, "HTTP/1.1 ", 9) != 0 && memcmp(bufp, "HTTP/1.0 ", 9) != 0) { DEBUG_PRINTF("No HTTP header, looking for URL line\n"); m0 = memmem(bufp, n, "\n", 1); @@ -120,7 +121,7 @@ checkstate: return 1; } DEBUG_PRINTF("Found URL: "); - for (int i = 0; i < (urllen > 64 ? 64 : urllen); ++i) DEBUG_PRINTF(isprint(*(url + i)) ? "%c" : "\\x%02x", *(url + i) & 0xFF); + for (unsigned int i = 0; i < (urllen > 64 ? 64 : urllen); ++i) DEBUG_PRINTF(isprint(*(url + i)) ? "%c" : "\\x%02x", *(url + i) & 0xFF); if (urllen > 64) DEBUG_PRINTF("<...>"); DEBUG_PRINTF("\n"); // Skip over URL line and continue processing below @@ -165,7 +166,7 @@ checkstate: fprintf(stderr, "Error: negative nscan\n"); return 1; } - if (nscan > n - (m0 - bufp)) { + if (m0 + nscan > bufp + n) { fprintf(stderr, "Error: buffer overread\n"); return 1; } @@ -290,7 +291,7 @@ checkstate: fprintf(stderr, "Error: negative nscan\n"); return 1; } - if (nscan > n - (m0 - bufp)) { + if (m0 + nscan > bufp + n) { fprintf(stderr, "Error: buffer overread\n"); return 1; } diff --git a/warc-dump-responses.c b/warc-dump-responses.c index 7649972..7cb6972 100644 --- a/warc-dump-responses.c +++ b/warc-dump-responses.c @@ -88,7 +88,7 @@ checkstate: fprintf(stderr, "Error: negative nscan\n"); return 1; } - if (nscan > n - (m0 - bufp)) { + if (m0 + nscan > bufp + n) { fprintf(stderr, "Error: buffer overread\n"); return 1; }