summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorchenyang8094 <chenyang8094@users.noreply.github.com>2022-04-04 23:38:18 +0800
committerOran Agra <oran@redislabs.com>2022-12-12 17:02:54 +0200
commit6029bd560e38d2f1c34c1f7ce5e3a394d4937c92 (patch)
tree00ca6063ae4112a1450b217a4f4fd54ff209c6be
parent39e5a6fa2f44ccec70511517a94199e37d6c9f5d (diff)
downloadredis-6029bd560e38d2f1c34c1f7ce5e3a394d4937c92.tar.gz
Fix null pointer subtraction warning (#10498)
The warning: ``` pqsort.c:106:7: warning: performing pointer subtraction with a null pointer has undefined behavior [-Wnull-pointer-subtraction] loop: SWAPINIT(a, es); ^~~~~~~~~~~~~~~ pqsort.c:65:47: note: expanded from macro 'SWAPINIT' #define SWAPINIT(a, es) swaptype = ((char *)a - (char *)NULL) % sizeof(long) || \ ``` Clang version: ``` Apple clang version 13.1.6 (clang-1316.0.21.2) Target: x86_64-apple-darwin21.3.0 Thread model: posix InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin ``` (cherry picked from commit cb625844bfe8fd8129a34bc2b7499e5735eb07ce)
-rw-r--r--src/pqsort.c4
1 files changed, 2 insertions, 2 deletions
diff --git a/src/pqsort.c b/src/pqsort.c
index 508c09f92..fab54e026 100644
--- a/src/pqsort.c
+++ b/src/pqsort.c
@@ -38,7 +38,7 @@
*/
#include <sys/types.h>
-
+#include <stdint.h>
#include <errno.h>
#include <stdlib.h>
@@ -62,7 +62,7 @@ static inline void swapfunc (char *, char *, size_t, int);
} while (--i > 0); \
}
-#define SWAPINIT(a, es) swaptype = ((char *)a - (char *)0) % sizeof(long) || \
+#define SWAPINIT(a, es) swaptype = (uintptr_t)a % sizeof(long) || \
es % sizeof(long) ? 2 : es == sizeof(long)? 0 : 1;
static inline void