From 16336ba2655db7f1df78437deb6de84d16c7c3c1 Mon Sep 17 00:00:00 2001 From: Dmitry Golovin Date: Tue, 22 Aug 2017 17:28:21 +0300 Subject: fix comparison of unsigned expression < 0 is always false found by clang --- src/archive.c | 3 ++- src/io.c | 8 +++++--- 2 files changed, 7 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/archive.c b/src/archive.c index b1f9c30..9196cb2 100644 --- a/src/archive.c +++ b/src/archive.c @@ -159,8 +159,9 @@ static void handle_extended_header(struct apk_file_info *fi, apk_blob_t hdr) unsigned int len = apk_blob_pull_uint(&hdr, 10); apk_blob_pull_char(&hdr, ' '); if (!apk_blob_split(hdr, APK_BLOB_STR("="), &name, &hdr)) break; + if (len < hdr.ptr - start + 1) break; len -= hdr.ptr - start + 1; - if (len < 0 || hdr.len < len) break; + if (hdr.len < len) break; value = APK_BLOB_PTR_LEN(hdr.ptr, len); hdr = APK_BLOB_PTR_LEN(hdr.ptr+len, hdr.len-len); apk_blob_pull_char(&hdr, '\n'); diff --git a/src/io.c b/src/io.c index bfc9c1c..832e06c 100644 --- a/src/io.c +++ b/src/io.c @@ -151,7 +151,8 @@ struct apk_istream *apk_istream_from_file(int atfd, const char *file) size_t apk_istream_skip(struct apk_istream *is, size_t size) { unsigned char buf[2048]; - size_t done = 0, r, togo; + size_t done = 0, togo; + ssize_t r; while (done < size) { togo = size - done; @@ -173,7 +174,8 @@ size_t apk_istream_splice(void *stream, int fd, size_t size, static void *splice_buffer = NULL; struct apk_istream *is = (struct apk_istream *) stream; unsigned char *buf, *mmapbase = MAP_FAILED; - size_t bufsz, done = 0, r, togo; + size_t bufsz, done = 0, togo; + ssize_t r; bufsz = size; if (size > 128 * 1024) { @@ -536,7 +538,7 @@ struct apk_bstream *apk_bstream_tee(struct apk_bstream *from, int atfd, const ch apk_blob_t apk_blob_from_istream(struct apk_istream *is, size_t size) { void *ptr; - size_t rsize; + ssize_t rsize; ptr = malloc(size); if (ptr == NULL) -- cgit v1.2.3-70-g09d2