From: Steinar H. Gunderson Date: Sat, 3 Jan 2009 01:27:29 +0000 (+0100) Subject: Fix signedness warnings. X-Git-Url: https://git.sesse.net/?p=fjl;a=commitdiff_plain;h=f6111465adacc2840f4cd25d55b3017cbf0593b2 Fix signedness warnings. --- diff --git a/dehuff.c b/dehuff.c index dd5c57d..a725469 100644 --- a/dehuff.c +++ b/dehuff.c @@ -9,7 +9,7 @@ void reliable_read(raw_input_func_t* input_func, void* userdata, uint8_t* buf, s { while (len > 0) { ssize_t bytes_read = input_func(userdata, buf, len); - assert(bytes_read <= len); + assert(bytes_read <= (ssize_t)len); // TODO: We need better error handling here. setjmp()/longjmp() // should hopefully do the trick, but we need to take care for @@ -159,7 +159,7 @@ unsigned read_huffman_symbol_slow_path(const struct huffman_table* table, unsigned code = read_bits(source, 1); int i = 0; - while (code > table->maxcode[i] || table->maxcode[i] == -1) { + while (table->maxcode[i] == -1 || code > (unsigned)table->maxcode[i]) { possibly_refill(source, 1); code = (code << 1) | read_bits(source, 1); ++i; diff --git a/input.c b/input.c index 7db6e1e..6c4630f 100644 --- a/input.c +++ b/input.c @@ -28,7 +28,7 @@ void possibly_refill_slow_path(struct bit_source* source, unsigned num_bits) (*source->input_func)(source->userdata, source->bytes + source->bytes_available, bytes_to_read); - assert(bytes_read <= bytes_to_read); + assert(bytes_read <= (ssize_t)bytes_to_read); assert(bytes_read >= (ssize_t)-1); // TODO: We need better error handling here. setjmp()/longjmp() diff --git a/input_test.c b/input_test.c index 3ff7ba0..57fae74 100644 --- a/input_test.c +++ b/input_test.c @@ -42,7 +42,7 @@ void test_basic_reading() struct bit_source source; init_bit_source(&source, custom_read, &ud); - for (int i = 0; i < sizeof(bytes) * 8 / 6; ++i) { + for (unsigned i = 0; i < sizeof(bytes) * 8 / 6; ++i) { possibly_refill(&source, 6); unsigned ret = read_bits(&source, 6); assert(ret == 0x2a); @@ -62,7 +62,7 @@ void test_slow_source() struct bit_source source; init_bit_source(&source, custom_read_slow, &ud); - for (int i = 0; i < sizeof(bytes) * 8 / 6; ++i) { + for (unsigned i = 0; i < sizeof(bytes) * 8 / 6; ++i) { possibly_refill(&source, 6); unsigned ret = read_bits(&source, 6); assert(ret == 0x2a); diff --git a/unstuff.c b/unstuff.c index 4a69178..997a562 100644 --- a/unstuff.c +++ b/unstuff.c @@ -34,7 +34,7 @@ int unstuff_fast(uint8_t* dst, const uint8_t* src, size_t len) size_t bytes_read = 0; size_t bytes_written = 0; - while (len - bytes_read >= 0) { + while (bytes_read < len) { // Find the first marker byte in the rest of the stream. const uint8_t* ptr = memchr(src, MARKER_CHAR, len - bytes_read); if (ptr == NULL) { diff --git a/unstuff_test.c b/unstuff_test.c index 754f8bf..863aef5 100644 --- a/unstuff_test.c +++ b/unstuff_test.c @@ -51,7 +51,7 @@ void gen_random_stuffed_data(uint8_t* dst, size_t len) { // Standard NR LCG (we avoid rand() to get consistent behavior across platforms). uint32_t seed = 1234; - for (int i = 0; i < len; ++i) { + for (unsigned i = 0; i < len; ++i) { seed = seed * 1664525 + 1013904223; uint8_t byte = (uint8_t)(seed & 0xff); if (byte != 0xff) { @@ -84,7 +84,7 @@ void test_performance(unstuff_func_t* unstuff) struct timeval start, now; gettimeofday(&start, NULL); - for (int i = 0; i < num_runs; ++i) { + for (unsigned i = 0; i < num_runs; ++i) { int ret = unstuff(dst, src, len); assert(ret != -1); }