RedisLabsModules / redex

Extension modules to Redis' native data types and commands
GNU Affero General Public License v3.0
69 stars 13 forks source link

fix warnings from clang #7

Closed neomantra closed 7 years ago

neomantra commented 8 years ago

Building on clang (see #6) yields the following warnings:

gcc -I../ -g -fPIC -O2 -std=gnu99   -c -o /Users/evan/projects/redex/src/rxkeys.o /Users/evan/projects/redex/src/rxkeys.c
/Users/evan/projects/redex/src/rxkeys.c:97:43: warning: passing 'unsigned long long *' to parameter of type 'long long *' converts between pointers to integer types with different sign
      [-Wpointer-sign]
    RedisModule_StringToLongLong(scursor, &lcursor);
                                          ^~~~~~~~
/Users/evan/projects/redex/src/rxkeys.c:150:43: warning: passing 'unsigned long long *' to parameter of type 'long long *' converts between pointers to integer types with different sign
      [-Wpointer-sign]
    RedisModule_StringToLongLong(scursor, &lcursor);
                                          ^~~~~~~~
/Users/evan/projects/redex/src/rxkeys.c:166:7: warning: expression result unused [-Wunused-value]
      (RedisModuleString *)&matches
      ^                    ~~~~~~~~
3 warnings generated.

Removing unsigned fixes the first two. I didn't reason about the third too much though, so not sure if it is really a problem or not.

diff --git a/src/rxkeys.c b/src/rxkeys.c
index ef66023..883153c 100644
--- a/src/rxkeys.c
+++ b/src/rxkeys.c
@@ -87,7 +87,7 @@ int PKeysCommand(RedisModuleCtx *ctx, RedisModuleString **argv, int argc) {
   RedisModule_ReplyWithArray(ctx, REDISMODULE_POSTPONED_ARRAY_LEN);
   size_t length = 0;
   RedisModuleString *scursor = RedisModule_CreateStringFromLongLong(ctx, 0);
-  unsigned long long lcursor;
+  long long lcursor;
   do {
     RedisModuleCallReply *rep = RedisModule_Call(ctx, "SCAN", "s", scursor);

@@ -139,7 +139,7 @@ int PDelCommand(RedisModuleCtx *ctx, RedisModuleString **argv, int argc) {

   /* Scan the keyspace. */
   RedisModuleString *scursor = RedisModule_CreateStringFromLongLong(ctx, 0);
-  unsigned long long lcursor;
+  long long lcursor;
   unsigned long long deleted = 0;
   do {
     RedisModuleCallReply *rep = RedisModule_Call(ctx, "SCAN", "s", scursor);
itamarhaber commented 8 years ago

Note to selves: switch between gcc and clang, Ubuntu 14.04

$ sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.8 100
update-alternatives: using /usr/bin/gcc-4.8 to provide /usr/bin/gcc (gcc) in auto mode
$ sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/clang-3.5 100
update-alternatives: using /usr/bin/clang-3.5 to provide /usr/bin/gcc (gcc) in auto mode
itamarhaber commented 8 years ago

@neomantra these warnings indeed also show when using clang on Linux. Interestingly, while it appears that both GCC and clang use the same gnu99 compatibility mode, the latter yields these warnings.

itamarhaber commented 8 years ago

@neomantra please verify that this too can be closed

neomantra commented 7 years ago

@itamarhaber I'm really sorry I missed your @ request on this over a year ago! I came back to the issues to pick up anything people had added and found this.

I've just tested the latest on Zesty with gcc-6 and clang-4 and they are both happy.