mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
checker: restrict numeric promotions to cases where no data is lost
This commit is contained in:
@@ -19,7 +19,7 @@ pub fn getenv(key string) string {
|
||||
return string_from_wide(s)
|
||||
} $else {
|
||||
s := C.getenv(key.str)
|
||||
if s == 0 {
|
||||
if s == voidptr(0) {
|
||||
return ''
|
||||
}
|
||||
// NB: C.getenv *requires* that the result be copied.
|
||||
|
||||
@@ -35,19 +35,19 @@ pub fn inode(path string) FileMode {
|
||||
C.stat(path.str, &attr)
|
||||
|
||||
mut typ := FileType.regular
|
||||
if attr.st_mode & C.S_IFMT == C.S_IFDIR {
|
||||
if attr.st_mode & u32(C.S_IFMT) == u32(C.S_IFDIR) {
|
||||
typ = .directory
|
||||
}
|
||||
$if !windows {
|
||||
if attr.st_mode & C.S_IFMT == C.S_IFCHR {
|
||||
if attr.st_mode & u32(C.S_IFMT) == u32(C.S_IFCHR) {
|
||||
typ = .character_device
|
||||
} else if attr.st_mode & C.S_IFMT == C.S_IFBLK {
|
||||
} else if attr.st_mode & u32(C.S_IFMT) == u32(C.S_IFBLK) {
|
||||
typ = .block_device
|
||||
} else if attr.st_mode & C.S_IFMT == C.S_IFIFO {
|
||||
} else if attr.st_mode & u32(C.S_IFMT) == u32(C.S_IFIFO) {
|
||||
typ = .fifo
|
||||
} else if attr.st_mode & C.S_IFMT == C.S_IFLNK {
|
||||
} else if attr.st_mode & u32(C.S_IFMT) == u32(C.S_IFLNK) {
|
||||
typ = .symbolic_link
|
||||
} else if attr.st_mode & C.S_IFMT == C.S_IFSOCK {
|
||||
} else if attr.st_mode & u32(C.S_IFMT) == u32(C.S_IFSOCK) {
|
||||
typ = .socket
|
||||
}
|
||||
}
|
||||
@@ -56,38 +56,38 @@ pub fn inode(path string) FileMode {
|
||||
return FileMode{
|
||||
typ: typ
|
||||
owner: FilePermission{
|
||||
read: bool(attr.st_mode & C.S_IREAD)
|
||||
write: bool(attr.st_mode & C.S_IWRITE)
|
||||
execute: bool(attr.st_mode & C.S_IEXEC)
|
||||
read: bool(attr.st_mode & u32(C.S_IREAD))
|
||||
write: bool(attr.st_mode & u32(C.S_IWRITE))
|
||||
execute: bool(attr.st_mode & u32(C.S_IEXEC))
|
||||
}
|
||||
group: FilePermission{
|
||||
read: bool(attr.st_mode & C.S_IREAD)
|
||||
write: bool(attr.st_mode & C.S_IWRITE)
|
||||
execute: bool(attr.st_mode & C.S_IEXEC)
|
||||
read: bool(attr.st_mode & u32(C.S_IREAD))
|
||||
write: bool(attr.st_mode & u32(C.S_IWRITE))
|
||||
execute: bool(attr.st_mode & u32(C.S_IEXEC))
|
||||
}
|
||||
others: FilePermission{
|
||||
read: bool(attr.st_mode & C.S_IREAD)
|
||||
write: bool(attr.st_mode & C.S_IWRITE)
|
||||
execute: bool(attr.st_mode & C.S_IEXEC)
|
||||
read: bool(attr.st_mode & u32(C.S_IREAD))
|
||||
write: bool(attr.st_mode & u32(C.S_IWRITE))
|
||||
execute: bool(attr.st_mode & u32(C.S_IEXEC))
|
||||
}
|
||||
}
|
||||
} $else {
|
||||
return FileMode{
|
||||
typ: typ
|
||||
owner: FilePermission{
|
||||
read: bool(attr.st_mode & C.S_IRUSR)
|
||||
write: bool(attr.st_mode & C.S_IWUSR)
|
||||
execute: bool(attr.st_mode & C.S_IXUSR)
|
||||
read: bool(attr.st_mode & u32(C.S_IRUSR))
|
||||
write: bool(attr.st_mode & u32(C.S_IWUSR))
|
||||
execute: bool(attr.st_mode & u32(C.S_IXUSR))
|
||||
}
|
||||
group: FilePermission{
|
||||
read: bool(attr.st_mode & C.S_IRGRP)
|
||||
write: bool(attr.st_mode & C.S_IWGRP)
|
||||
execute: bool(attr.st_mode & C.S_IXGRP)
|
||||
read: bool(attr.st_mode & u32(C.S_IRGRP))
|
||||
write: bool(attr.st_mode & u32(C.S_IWGRP))
|
||||
execute: bool(attr.st_mode & u32(C.S_IXGRP))
|
||||
}
|
||||
others: FilePermission{
|
||||
read: bool(attr.st_mode & C.S_IROTH)
|
||||
write: bool(attr.st_mode & C.S_IWOTH)
|
||||
execute: bool(attr.st_mode & C.S_IXOTH)
|
||||
read: bool(attr.st_mode & u32(C.S_IROTH))
|
||||
write: bool(attr.st_mode & u32(C.S_IWOTH))
|
||||
execute: bool(attr.st_mode & u32(C.S_IXOTH))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1090,12 +1090,12 @@ pub fn real_path(fpath string) string {
|
||||
mut fullpath := vcalloc(max_path_len)
|
||||
mut ret := charptr(0)
|
||||
$if windows {
|
||||
ret = C._fullpath(fullpath, fpath.str, max_path_len)
|
||||
ret = charptr(C._fullpath(fullpath, fpath.str, max_path_len))
|
||||
if ret == 0 {
|
||||
return fpath
|
||||
}
|
||||
} $else {
|
||||
ret = C.realpath(fpath.str, fullpath)
|
||||
ret = charptr(C.realpath(fpath.str, fullpath))
|
||||
if ret == 0 {
|
||||
return fpath
|
||||
}
|
||||
@@ -1324,7 +1324,7 @@ pub fn open(path string) ?File {
|
||||
}
|
||||
*/
|
||||
cfile := vfopen(path, 'rb')
|
||||
if cfile == 0 {
|
||||
if cfile == voidptr(0) {
|
||||
return error('failed to open file "$path"')
|
||||
}
|
||||
fd := fileno(cfile)
|
||||
@@ -1361,7 +1361,7 @@ pub fn create(path string) ?File {
|
||||
}
|
||||
*/
|
||||
cfile := vfopen(path, 'wb')
|
||||
if cfile == 0 {
|
||||
if cfile == voidptr(0) {
|
||||
return error('failed to create file "$path"')
|
||||
}
|
||||
fd := fileno(cfile)
|
||||
|
||||
@@ -146,7 +146,7 @@ pub fn mkdir(path string) ?bool {
|
||||
// get_file_handle retrieves the operating-system file handle that is associated with the specified file descriptor.
|
||||
pub fn get_file_handle(path string) HANDLE {
|
||||
cfile := vfopen(path, 'rb')
|
||||
if cfile == 0 {
|
||||
if cfile == voidptr(0) {
|
||||
return HANDLE(invalid_handle_value)
|
||||
}
|
||||
handle := HANDLE(C._get_osfhandle(fileno(cfile))) // CreateFile? - hah, no -_-
|
||||
|
||||
Reference in New Issue
Block a user