From 4cbfeec1f5d072affdec74a60c9388e22f72ffdc Mon Sep 17 00:00:00 2001 From: Marcin Kolny Date: Tue, 29 Nov 2022 10:45:07 +0000 Subject: [PATCH] Fix scenario where the timeout for atomic wait is set to negative number (#1767) The code, when received -1, performed -1/1000 operation which rounds to 0, i.e. no wait (instead of infinite wait) --- core/iwasm/common/wasm_shared_memory.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/core/iwasm/common/wasm_shared_memory.c b/core/iwasm/common/wasm_shared_memory.c index 4ae88e89..862bbe96 100644 --- a/core/iwasm/common/wasm_shared_memory.c +++ b/core/iwasm/common/wasm_shared_memory.c @@ -385,10 +385,8 @@ wasm_runtime_atomic_wait(WASMModuleInstanceCommon *module, void *address, /* condition wait start */ os_mutex_lock(&wait_node->wait_lock); - if (timeout < 0) - timeout = BHT_WAIT_FOREVER; os_cond_reltimedwait(&wait_node->wait_cond, &wait_node->wait_lock, - timeout / 1000); + timeout < 0 ? BHT_WAIT_FOREVER : timeout / 1000); os_mutex_unlock(&wait_node->wait_lock);