From c88e815b187cc71f0dff022e64ae60b68fe7b7f4 Mon Sep 17 00:00:00 2001 From: Jae Juang Date: Mon, 20 Mar 2023 13:31:19 +0800 Subject: [PATCH] Set errno to 0 before strtol Refer to https://man7.org/linux/man-pages/man3/strtol.3.html Fixes cases where calls to the PL/pgSQL functions http_set_curlopt() and http() keep failing after errno is set --- http.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/http.c b/http.c index 12e8de7..028acc1 100644 --- a/http.c +++ b/http.c @@ -786,7 +786,9 @@ set_curlopt(CURL* handle, const http_curlopt *opt) /* Argument is a long */ else if (opt->curlopt_type == CURLOPT_LONG) { - long value_long = strtol(opt->curlopt_val, NULL, 10); + long value_long; + errno = 0; + value_long = strtol(opt->curlopt_val, NULL, 10); if ( errno == EINVAL || errno == ERANGE ) elog(ERROR, "invalid integer provided for '%s'", opt->curlopt_str);