musl - musl - an implementation of the standard library for Linux-based systems

index : musl
musl - an implementation of the standard library for Linux-based systems
summary refs log tree commit diff
path: root/include/sys/sysmacros.h
diff options
context:
space:
mode:
authorRich Felker <dalias@aerifal.cx>2013年06月29日 13:57:13 -0400
committerRich Felker <dalias@aerifal.cx>2013年06月29日 13:57:13 -0400
commit9b732fe51b814468a08c84d13238b4c83a42451a (patch)
treeba7d4fed8688a352ffb8904b2493839dd7ca0578 /include/sys/sysmacros.h
parent780cbbe63ad9e60ef30dbcb2d74271e899dae245 (diff)
downloadmusl-9b732fe51b814468a08c84d13238b4c83a42451a.tar.gz
fix shifts possibly larger than type in major() macro
in theory this should not be an issue, since major() should only be applied to type dev_t, which is 64-bit. however, it appears some applications are not using dev_t but a smaller integer type (which works on Linux because the kernel's dev_t is really only 32-bit). to avoid the undefined behavior, do it as two shifts.
Diffstat (limited to 'include/sys/sysmacros.h')
-rw-r--r--include/sys/sysmacros.h 2
1 files changed, 1 insertions, 1 deletions
diff --git a/include/sys/sysmacros.h b/include/sys/sysmacros.h
index d6c6aef6..07a3ef18 100644
--- a/include/sys/sysmacros.h
+++ b/include/sys/sysmacros.h
@@ -2,7 +2,7 @@
#define _SYS_SYSMACROS_H
#define major(x) \
- ((unsigned)( (((x)>>32) & 0xfffff000) | (((x)>>8) & 0x00000fff) ))
+ ((unsigned)( (((x)>>31>>1) & 0xfffff000) | (((x)>>8) & 0x00000fff) ))
#define minor(x) \
((unsigned)( (((x)>>12) & 0xffffff00) | ((x) & 0x000000ff) ))
generated by cgit v1.2.1 (git 2.18.0) at 2025年09月06日 07:23:11 +0000

AltStyle によって変換されたページ (->オリジナル) /