erofs-utils: avoid unsigned long if possible (incomplete)
PATCH 1/1 erofs-utils: avoid unsigned long if possible (incomplete)
long is always 32 bits on Windows, even on 64-bit systems.
Link https://github.com/erofs/go-erofs/blob/main/.github/workflows/patches/erofs-utils/001-windows.patch
Signed-off-by Gao Xiang <[email protected]>
--- include/erofs/err.h | 9 +++++---- include/erofs/internal.h | 2 +- lib/dedupe.c | 31 +++++++++++++++---------------- lib/inode.c | 4 ++-- lib/kite_deflate.c | 3 +-- 5 files changed, 24 insertions(+), 25 deletions(-)
include/erofs/err.h +5 -4
@@ -13,6 +13,7 @@ extern "C"#endif #include <errno.h> +#include <stdint.h> #include <string.h> #include <stdio.h>
@@ -30,7 +31,7 @@ static inline const char *erofs_strerror(int err)#define MAX_ERRNO (4095)#define IS_ERR_VALUE (x) \ - ((unsigned long)(void *)(x) >= (unsigned long)-MAX_ERRNO) + ((uintptr_t)(void *)(x) >= (uintptr_t)-MAX_ERRNO)static inline void *ERR_PTR (long error) {
@@ -39,18 +40,18 @@ static inline void *ERR_PTR(long error)static inline int IS_ERR (const void *ptr) { -return IS_ERR_VALUE ((unsigned long )ptr); +return IS_ERR_VALUE ((uintptr_t )ptr); }static inline long PTR_ERR (const void *ptr) { -return (long ) ptr; +return (intptr_t )ptr; }static inline void *ERR_CAST (const void *ptr) {/* cast away the const */ -return (void *) ptr; +return (void *)ptr; }/* EROFS-specific error codes */
include/erofs/internal.h +1 -1
@@ -348,7 +348,7 @@ static inline unsigned int erofs_inode_datalayout(unsigned int ifmt)static inline struct erofs_inode *erofs_parent_inode (struct erofs_inode *inode) { -return (struct erofs_inode *)((unsigned long )inode->i_parent & ~1UL ); +return (struct erofs_inode *)((uintptr_t )inode->i_parent & ~(uintptr_t )1 ); }#define IS_ROOT (x) ((x) == erofs_parent_inode(x))
lib/dedupe.c +15 -16
@@ -9,18 +9,17 @@#include "liberofs_xxhash.h" #include "liberofs_sha256.h" -unsigned long erofs_memcmp2 (const u8 *s1,const u8 *s2, -unsigned long sz) +uintptr_t erofs_memcmp2 (const u8 *s1,const u8 *s2,uintptr_t sz) { -const unsigned long *a1, *a2; -unsigned long n = sz; +const uintptr_t *a1, *a2; +uintptr_t n = sz; -if (sz <sizeof (long )) +if (sz <sizeof (uintptr_t )) goto out_bytes; -if (((long )s1 & (sizeof (long ) -1 )) == - ((long )s2 & (sizeof (long ) -1 ))) { -while ((long )s1 & (sizeof (long ) -1 )) { +if (((uintptr_t )s1 & (sizeof (uintptr_t ) -1 )) == + ((uintptr_t )s2 & (sizeof (uintptr_t ) -1 ))) { +while ((uintptr_t )s1 & (sizeof (uintptr_t ) -1 )) {if (*s1 != *s2)break ; ++s1;
@@ -28,25 +27,25 @@ unsigned long erofs_memcmp2(const u8 *s1, const u8 *s2, --sz; } - a1 = (const unsigned long *)s1; - a2 = (const unsigned long *)s2; -while (sz >=sizeof (long )) { + a1 = (const uintptr_t *)s1; + a2 = (const uintptr_t *)s2; +while (sz >=sizeof (uintptr_t )) {if (*a1 != *a2)break ; ++a1; ++a2; - sz -=sizeof (long ); + sz -=sizeof (uintptr_t ); } }else { - a1 = (const unsigned long *)s1; - a2 = (const unsigned long *)s2; + a1 = (const uintptr_t *)s1; + a2 = (const uintptr_t *)s2;do {if (get_unaligned (a1) !=get_unaligned (a2))break ; ++a1; ++a2; - sz -=sizeof (long ); - }while (sz >=sizeof (long )); + sz -=sizeof (uintptr_t ); + }while (sz >=sizeof (uintptr_t )); } s1 = (const u8 *)a1; s2 = (const u8 *)a2;
lib/inode.c +2 -2
@@ -2169,13 +2169,13 @@ static int erofs_mkfs_handle_inode(const struct erofs_mkfs_btctx *ctx,static bool erofs_inode_visited (struct erofs_inode *inode) { -return (unsigned long )inode->i_parent &1UL ; +return (uintptr_t )inode->i_parent &1 ; }static void erofs_mark_parent_inode (struct erofs_inode *inode,struct erofs_inode *dir) { - inode->i_parent = (void *)((unsigned long )dir |1 ); + inode->i_parent = (void *)((uintptr_t )dir |1 ); }static int erofs_mkfs_dump_tree (const struct erofs_mkfs_btctx *ctx)
lib/kite_deflate.c +1 -2
@@ -13,8 +13,7 @@#include <ctype.h> #include <stdio.h> -unsigned long erofs_memcmp2 (const u8 *s1,const u8 *s2, -unsigned long sz); +uintptr_t erofs_memcmp2 (const u8 *s1,const u8 *s2,uintptr_t sz);#ifdef TEST #define kite_dbg (x, ...) fprintf(stderr, x "\n", ##__VA_ARGS__)
Signature · 1 line
2.50.1 (Apple Git-155)