mirror of
https://github.com/golang/sys.git
synced 2026-01-29 07:02:06 +03:00
unix: convert major/minor to uint64 before shifting in Mkdev on Darwin/*BSD
Follow CL 63090 and change the Makedev function on Darwin and *BSD to convert to uint64 before shifting/masking. This avoids a potential overflow. Change-Id: I5b566329695cc5edcf82f0ff2366033011b0625b Reviewed-on: https://go-review.googlesource.com/63112 Reviewed-by: Ian Lance Taylor <iant@golang.org> Run-TryBot: Ian Lance Taylor <iant@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
This commit is contained in:
committed by
Ian Lance Taylor
parent
7a85bfad8b
commit
804a9fee62
@@ -20,5 +20,5 @@ func Minor(dev uint64) uint32 {
|
||||
// Mkdev returns a Darwin device number generated from the given major and minor
|
||||
// components.
|
||||
func Mkdev(major, minor uint32) uint64 {
|
||||
return uint64((major << 24) | minor)
|
||||
return (uint64(major) << 24) | uint64(minor)
|
||||
}
|
||||
|
||||
@@ -26,5 +26,5 @@ func Minor(dev uint64) uint32 {
|
||||
// Mkdev returns a DragonFlyBSD device number generated from the given major and
|
||||
// minor components.
|
||||
func Mkdev(major, minor uint32) uint64 {
|
||||
return uint64((major << 8) | minor)
|
||||
return (uint64(major) << 8) | uint64(minor)
|
||||
}
|
||||
|
||||
@@ -26,5 +26,5 @@ func Minor(dev uint64) uint32 {
|
||||
// Mkdev returns a FreeBSD device number generated from the given major and
|
||||
// minor components.
|
||||
func Mkdev(major, minor uint32) uint64 {
|
||||
return uint64((major << 8) | minor)
|
||||
return (uint64(major) << 8) | uint64(minor)
|
||||
}
|
||||
|
||||
@@ -22,8 +22,8 @@ func Minor(dev uint64) uint32 {
|
||||
// Mkdev returns a NetBSD device number generated from the given major and minor
|
||||
// components.
|
||||
func Mkdev(major, minor uint32) uint64 {
|
||||
dev := uint64((major << 8) & 0x000fff00)
|
||||
dev |= uint64((minor << 12) & 0xfff00000)
|
||||
dev |= uint64((minor << 0) & 0x000000ff)
|
||||
dev := (uint64(major) << 8) & 0x000fff00
|
||||
dev |= (uint64(minor) << 12) & 0xfff00000
|
||||
dev |= (uint64(minor) << 0) & 0x000000ff
|
||||
return dev
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user