Closed liuqi-sun closed 3 years ago
Interesting. Probably time_t is defined as 32 bit integer..? Could you print sizeof now.tv_sec
?
I get timestamp by gettimeofday function, tv_sec * 10 is out of bound.
[2021-03-22 20:34:35.539][40124][info][wasm] [source/extensions/common/wasm/context.cc:1178] wasm log: now.tv_sec=1616470475, now.tv_usec=539285, now.tv_sec*10=-1015164434
time_t
is usually defined as long
, which in 32-bit WasmVM is going to be 32-bit, and that's the case in this SDK, which is based on Emscripten that includes musl, see: https://github.com/emscripten-core/emscripten/blob/2.0.7/system/lib/libc/musl/arch/emscripten/bits/alltypes.h#L75
Since the current tv_sec
value is a pretty high number, it's going to overflow and wrap-around if you multiply it by 10. This is pretty standard behavior in C/C++, and it's not unique to time_t
or Wasm.
If you want to multiply it by 10, then you need to cast it to int64_t
beforehand.
Interesting. Probably time_t is defined as 32 bit integer..? Could you print sizeof
now.tv_sec
?
thanks
I get timestamp by gettimeofday function, tv_sec 10 is out of bound. [2021-03-22 20:34:35.539][40124][info][wasm] [source/extensions/common/wasm/context.cc:1178] wasm log: now.tv_sec=1616470475, now.tv_usec=539285, now.tv_sec10=-1015164434
time_t
is usually defined aslong
, which in 32-bit WasmVM is going to be 32-bit, and that's the case in this SDK, which is based on Emscripten that includes musl, see: https://github.com/emscripten-core/emscripten/blob/2.0.7/system/lib/libc/musl/arch/emscripten/bits/alltypes.h#L75Since the current
tv_sec
value is a pretty high number, it's going to overflow and wrap-around if you multiply it by 10. This is pretty standard behavior in C/C++, and it's not unique totime_t
or Wasm.If you want to multiply it by 10, then you need to cast it to
int64_t
beforehand.
Thanks, I am aware of the problem too,
I get timestamp by gettimeofday function, tv_sec 10 is out of bound. [2021-03-22 20:34:35.539][40124][info][wasm] [source/extensions/common/wasm/context.cc:1178] wasm log: now.tv_sec=1616470475, now.tv_usec=539285, now.tv_sec10=-1015164434
time_t
is usually defined aslong
, which in 32-bit WasmVM is going to be 32-bit, and that's the case in this SDK, which is based on Emscripten that includes musl, see: https://github.com/emscripten-core/emscripten/blob/2.0.7/system/lib/libc/musl/arch/emscripten/bits/alltypes.h#L75Since the current
tv_sec
value is a pretty high number, it's going to overflow and wrap-around if you multiply it by 10. This is pretty standard behavior in C/C++, and it's not unique totime_t
or Wasm.If you want to multiply it by 10, then you need to cast it to
int64_t
beforehand.
Thanks, I am aware of the problem too, is there 64-bit WasmVM ?
@liuqi-sun how did you get the current UTC time ? I'm using getCurrentTimeNanoseconds
and it's giving me a time in 1980s. Any idea ?
@NomadXD you can use gettimeofday()
.
I get timestamp by gettimeofday function, tv_sec * 10 is out of bound.
[2021-03-22 20:34:35.539][40124][info][wasm] [source/extensions/common/wasm/context.cc:1178] wasm log: now.tv_sec=1616470475, now.tv_usec=539285, now.tv_sec*10=-1015164434