Skip to content

Commit

Permalink
Use intptr_t when storing an integer in a pointer
Browse files Browse the repository at this point in the history
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 <mahrens@delphix.com>
Reviewed-by: Richard Yao <richard.yao@alumni.stonybrook.edu>
Signed-off-by: Brooks Davis <brooks.davis@sri.com>
Closes #14131
  • Loading branch information
brooksdavis authored and behlendorf committed Nov 3, 2022
1 parent 8777900 commit b9041e1
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion cmd/zstream/zstream_decompress.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down
2 changes: 1 addition & 1 deletion module/zfs/zfs_vnops.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit b9041e1

Please sign in to comment.