From 0e859748a4e00cfad3bc50e386a06622066ee994 Mon Sep 17 00:00:00 2001 From: Jo-Philipp Wich Date: Sun, 6 Mar 2022 23:08:35 +0100 Subject: uloop: clear errno before integer conversion attempts In some cases, errno contains stale values from prior function invocations which might lead to random failures in uc_uloop_run(), uc_uloop_timer_set() and uc_uloop_timer(). Solve this issue by explicitly initializing errno to 0. Signed-off-by: Jo-Philipp Wich --- lib/uloop.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib/uloop.c b/lib/uloop.c index 8b5adff..bc57336 100644 --- a/lib/uloop.c +++ b/lib/uloop.c @@ -111,6 +111,7 @@ uc_uloop_run(uc_vm_t *vm, size_t nargs) uc_value_t *timeout = uc_fn_arg(0); int t, rv; + errno = 0; t = timeout ? (int)ucv_int64_get(timeout) : -1; if (errno) @@ -182,6 +183,7 @@ uc_uloop_timer_set(uc_vm_t *vm, size_t nargs) if (!timer || !*timer) err_return(EINVAL); + errno = 0; t = timeout ? (int)ucv_int64_get(timeout) : -1; if (errno) @@ -243,6 +245,7 @@ uc_uloop_timer(uc_vm_t *vm, size_t nargs) uc_value_t *res; int t; + errno = 0; t = timeout ? ucv_int64_get(timeout) : -1; if (errno) -- cgit v1.2.3