From 58f71d97f5f55d081b269c088a6d6768312f49c0 Mon Sep 17 00:00:00 2001
From: Philippe Teuwen <phil@teuwen.org>
Date: Mon, 4 May 2020 01:18:26 +0200
Subject: [PATCH] silent some bad-function-cast

---
 Makefile.defs               | 4 ++--
 client/src/cmdhfmfhard.c    | 3 ++-
 client/src/cmdlfjablotron.c | 7 +++----
 client/src/pm3_binlib.c     | 3 ++-
 client/src/pm3_bitlib.c     | 6 ++++--
 client/src/whereami.c       | 3 ++-
 6 files changed, 15 insertions(+), 11 deletions(-)

diff --git a/Makefile.defs b/Makefile.defs
index a9d9328d3..2de8f88a3 100644
--- a/Makefile.defs
+++ b/Makefile.defs
@@ -47,9 +47,9 @@ endif
 
 DEFCFLAGS = -Wall -Werror -O3
 # Some more warnings we want as errors:
-DEFCFLAGS += -Wredundant-decls -Wmissing-prototypes -Wchar-subscripts -Wshadow -Wundef -Wwrite-strings -Wunused -Wuninitialized -Wpointer-arith -Winline -Wformat -Wformat-security -Winit-self -Wmissing-include-dirs -Wnested-externs -Wmissing-declarations
+DEFCFLAGS += -Wcast-align -Wbad-function-cast -Wredundant-decls -Wmissing-prototypes -Wchar-subscripts -Wshadow -Wundef -Wwrite-strings -Wunused -Wuninitialized -Wpointer-arith -Winline -Wformat -Wformat-security -Winit-self -Wmissing-include-dirs -Wnested-externs -Wmissing-declarations
 # Some more warnings we need first to eliminate, so temporarely tolerated:
-DEFCFLAGS += -Wbad-function-cast -Wno-error=bad-function-cast -Wcast-align -Wno-error=cast-align
+DEFCFLAGS += -Wno-error=cast-align
 # TODO?:
 #DEFCFLAGS += -Wextra -Wswitch-enum -Wold-style-definition
 
diff --git a/client/src/cmdhfmfhard.c b/client/src/cmdhfmfhard.c
index a32af3601..2a245df37 100644
--- a/client/src/cmdhfmfhard.c
+++ b/client/src/cmdhfmfhard.c
@@ -793,7 +793,8 @@ static void update_p_K(void) {
         }
         for (uint8_t sum_a8_idx = 0; sum_a8_idx < NUM_SUMS; sum_a8_idx++) {
             uint16_t sum_a8 = sums[sum_a8_idx];
-            my_p_K[sum_a8_idx] = (float)estimated_num_states_coarse(sum_a0, sum_a8) / total_count;
+            float f = estimated_num_states_coarse(sum_a0, sum_a8);
+            my_p_K[sum_a8_idx] = f / total_count;
         }
         // PrintAndLogEx(NORMAL, "my_p_K = [");
         // for (uint8_t sum_a8_idx = 0; sum_a8_idx < NUM_SUMS; sum_a8_idx++) {
diff --git a/client/src/cmdlfjablotron.c b/client/src/cmdlfjablotron.c
index 285ddca7d..3d586215e 100644
--- a/client/src/cmdlfjablotron.c
+++ b/client/src/cmdlfjablotron.c
@@ -12,7 +12,6 @@
 
 #include <string.h>
 #include <inttypes.h>
-#include <math.h>
 #include <stdlib.h>
 #include <ctype.h>
 
@@ -70,9 +69,9 @@ static uint64_t getJablontronCardId(uint64_t rawcode) {
     uint64_t id = 0;
     uint8_t bytes[] = {0, 0, 0, 0, 0};
     num_to_bytes(rawcode, 5, bytes);
-    for (int i = 4, j = 0; i > -1;  --i, j += 2) {
-        id += NIBBLE_LOW(bytes[i]) * (int)pow(10, j);
-        id += NIBBLE_HIGH(bytes[i]) * (int)pow(10, j + 1);
+    for (int i = 0; i < 5; i++) {
+        id *= 100;
+        id += NIBBLE_HIGH(bytes[i]) * 10 + NIBBLE_LOW(bytes[i]);
     }
     return id;
 }
diff --git a/client/src/pm3_binlib.c b/client/src/pm3_binlib.c
index f4e49c137..56d281636 100644
--- a/client/src/pm3_binlib.c
+++ b/client/src/pm3_binlib.c
@@ -203,7 +203,8 @@ static int l_unpack(lua_State *L) {       /** unpack(f,s, [init]) */
 #define PACKNUMBER(OP,T)                        \
     case OP:                                     \
     {                                            \
-        T a=(T)luaL_checknumber(L,i++);             \
+        lua_Number n = luaL_checknumber(L,i++);  \
+        T a=(T)n;                                \
         doswap(swap,&a,sizeof(a));                  \
         luaL_addlstring(&b,(char*)&a,sizeof(a));    \
         break;                                      \
diff --git a/client/src/pm3_bitlib.c b/client/src/pm3_bitlib.c
index b5ef6e0ae..064c0f3c9 100644
--- a/client/src/pm3_bitlib.c
+++ b/client/src/pm3_bitlib.c
@@ -92,16 +92,18 @@ typedef size_t lua_UInteger;
 #define LOGICAL_SHIFT(name, op)                                         \
     static int bit_ ## name(lua_State *L) {                               \
         lua_Number f;                                                       \
+        lua_Number n = luaL_checknumber(L, 2);                              \
         lua_pushinteger(L, BIT_TRUNCATE(BIT_TRUNCATE((lua_UInteger)TOBIT(L, 1, f)) op \
-                                        (unsigned)luaL_checknumber(L, 2))); \
+                                        (unsigned)n)); \
         return 1;                                                           \
     }
 
 #define ARITHMETIC_SHIFT(name, op)                                      \
     static int bit_ ## name(lua_State *L) {                               \
         lua_Number f;                                                       \
+        lua_Number n = luaL_checknumber(L, 2);                              \
         lua_pushinteger(L, BIT_TRUNCATE((lua_Integer)TOBIT(L, 1, f) op      \
-                                        (unsigned)luaL_checknumber(L, 2))); \
+                                        (unsigned)n)); \
         return 1;                                                           \
     }
 
diff --git a/client/src/whereami.c b/client/src/whereami.c
index 30d70c4d9..b725c4946 100644
--- a/client/src/whereami.c
+++ b/client/src/whereami.c
@@ -253,7 +253,8 @@ int WAI_PREFIX(getModulePath)(char *out, int capacity, int *dirname_length) {
                 break;
 
             if (sscanf(buffer, "%" SCNx64 "-%" SCNx64 " %s %" SCNx64 " %x:%x %u %s\n", &low, &high, perms, &offset, &major, &minor, &inode, path) == 8) {
-                uint64_t addr = (uint64_t)(uintptr_t)WAI_RETURN_ADDRESS();
+                void *addr_tmp = WAI_RETURN_ADDRESS();
+                uint64_t addr = (uint64_t)addr_tmp;
                 if (low <= addr && addr <= high) {
                     char *resolved;