From b9041e1f27b7b29b27ac3b873c7ba2922bccca01 Mon Sep 17 00:00:00 2001 From: Brooks Davis Date: Thu, 27 Oct 2022 23:28:03 +0100 Subject: [PATCH] Use intptr_t when storing an integer in a pointer Cast the integer type to (u)intptr_t before casting to "void *". In CHERI C/C++ we warn on bare casts from integers to pointers to catch attempts to create pointers our of thin air. We allow the warning to be supressed with a suitable cast through (u)intptr_t. Reviewed-by: Matthew Ahrens Reviewed-by: Richard Yao Signed-off-by: Brooks Davis Closes #14131 --- cmd/zstream/zstream_decompress.c | 2 +- module/zfs/zfs_vnops.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/cmd/zstream/zstream_decompress.c b/cmd/zstream/zstream_decompress.c index e5527777bc..6e0da0852b 100644 --- a/cmd/zstream/zstream_decompress.c +++ b/cmd/zstream/zstream_decompress.c @@ -146,7 +146,7 @@ zstream_do_decompress(int argc, char *argv[]) p = hsearch(e, ENTER); if (p == NULL) errx(1, "hsearch"); - p->data = (void*)type; + p->data = (void*)(intptr_t)type; } if (isatty(STDIN_FILENO)) { diff --git a/module/zfs/zfs_vnops.c b/module/zfs/zfs_vnops.c index c63076f90c..593249e12c 100644 --- a/module/zfs/zfs_vnops.c +++ b/module/zfs/zfs_vnops.c @@ -64,7 +64,7 @@ zfs_fsync(znode_t *zp, int syncflag, cred_t *cr) int error = 0; zfsvfs_t *zfsvfs = ZTOZSB(zp); - (void) tsd_set(zfs_fsyncer_key, (void *)zfs_fsync_sync_cnt); + (void) tsd_set(zfs_fsyncer_key, (void *)(uintptr_t)zfs_fsync_sync_cnt); if (zfsvfs->z_os->os_sync != ZFS_SYNC_DISABLED) { if ((error = zfs_enter_verify_zp(zfsvfs, zp, FTAG)) != 0)