radareorg / sdb

Simple and fast string based key-value database with support for arrays and json
https://www.radare.org/
MIT License
218 stars 62 forks source link

Silent the warning: comparison between signed and unsigned integer expressions #165

Closed tesuji closed 5 years ago

tesuji commented 5 years ago

In Travis log with commit 0f72498:

ht.c: In function ‘compute_size’:
ht.c:55:13: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  return idx != UT32_MAX ? ht_primes_sizes[idx] : (sz | 1);
             ^
ht.c:55:48: warning: signed and unsigned type in conditional expression [-Wsign-compare]
  return idx != UT32_MAX ? ht_primes_sizes[idx] : (sz | 1);
                                                ^
ht.c: In function ‘ht_new_size’:
ht.c:128:11: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  while (i < S_ARRAY_SIZE (ht_primes_sizes) &&
           ^
ht.c:129:36: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   ht_primes_sizes[i] * LOAD_FACTOR < initial_size) {
                                    ^

array.c: In function ‘sdb_array_contains’:
array.c:503:35: warning: signed and unsigned type in conditional expression [-Wsign-compare]
    size_t len = next ? next - ptr : strlen (ptr);
                                   ^

Comparison between signed and unsigned int could be really dangerous. So these comparisons should be fixed properly.

radare commented 5 years ago

Cc @ret2libc

On 9 Oct 2018, at 08:49, lzutao notifications@github.com wrote:

In Travis log:

ht.c: In function ‘compute_size’: ht.c:55:13: warning: comparison between signed and unsigned integer expressions [-Wsign-compare] return idx != UT32_MAX ? ht_primes_sizes[idx] : (sz | 1); ^ ht.c:55:48: warning: signed and unsigned type in conditional expression [-Wsign-compare] return idx != UT32_MAX ? ht_primes_sizes[idx] : (sz | 1); ^ ht.c: In function ‘ht_new_size’: ht.c:128:11: warning: comparison between signed and unsigned integer expressions [-Wsign-compare] while (i < S_ARRAY_SIZE (ht_primes_sizes) && ^ ht.c:129:36: warning: comparison between signed and unsigned integer expressions [-Wsign-compare] ht_primes_sizes[i] * LOAD_FACTOR < initial_size) { ^

array.c: In function ‘sdb_array_contains’: array.c:503:35: warning: signed and unsigned type in conditional expression [-Wsign-compare] size_t len = next ? next - ptr : strlen (ptr); ^ Comparison between signed and unsigned int could be really dangerous. So these comparisons should be fixed properly.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub, or mute the thread.

ret2libc commented 5 years ago

thanks i'll work on this.