From c8de2c0bd4148fec2a8c41d04cfa103af8edc841 Mon Sep 17 00:00:00 2001 From: Nicolas Sauzede Date: Thu, 7 Nov 2019 04:00:00 +0100 Subject: [PATCH] fix i64 overflow warning --- vlib/math/const.v | 5 ++++- vlib/os/os.v | 4 +++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/vlib/math/const.v b/vlib/math/const.v index 33f3dd7ff9..5da1548eeb 100644 --- a/vlib/math/const.v +++ b/vlib/math/const.v @@ -41,7 +41,10 @@ pub const ( min_i16 = -32768 max_i32 = 2147483647 min_i32 = -2147483648 - min_i64 = -9223372036854775808 + // -9223372036854775808 is wrong because C compilers parse litteral values + // without sign first, and 9223372036854775808 overflows i64, hence the + // consecutive subtraction by 1 + min_i64 = -9223372036854775807 - 1 max_i64 = 9223372036854775807 max_u8 = 255 max_u16 = 65535 diff --git a/vlib/os/os.v b/vlib/os/os.v index 6e017dbe10..85bc76e6f2 100644 --- a/vlib/os/os.v +++ b/vlib/os/os.v @@ -865,7 +865,9 @@ pub fn realpath(fpath string) string { res = int( C._fullpath( fullpath, fpath.str, MAX_PATH ) ) } $else{ - res = int( C.realpath( fpath.str, fullpath ) ) + // here we want an int==0 if realpath failed, in which case + // realpath would return NULL, and !isnil(NULL) would be false==0 + res = int( !isnil(C.realpath( fpath.str, fullpath )) ) } if res != 0 { return string(fullpath, vstrlen(fullpath))