File 1297-ei-Fix-some-possible-unused-variables-warnings.patch of Package erlang

From 0339cd76af5af32c930ea1c5826898dc6b023d58 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Lukas=20Backstr=C3=B6m?= <lukas@erlang.org>
Date: Tue, 13 May 2025 09:41:33 +0200
Subject: [PATCH 2/2] ei: Fix some possible unused variables warnings

---
 lib/erl_interface/src/misc/ei_portio.h |  6 ++++--
 lib/erl_interface/src/misc/eidef.h     | 10 ++++++++++
 lib/erl_interface/src/prog/erl_call.c  |  3 +++
 3 files changed, 17 insertions(+), 2 deletions(-)

diff --git a/lib/erl_interface/src/misc/ei_portio.h b/lib/erl_interface/src/misc/ei_portio.h
index 31ab00daad..effa9955c5 100644
--- a/lib/erl_interface/src/misc/ei_portio.h
+++ b/lib/erl_interface/src/misc/ei_portio.h
@@ -58,7 +58,7 @@ extern ei_socket_callbacks ei_default_socket_callbacks;
 
 #define EI_DFLT_CTX_TO_FD__(CTX, FD)                                    \
     ((intptr_t) (CTX) < 0                                               \
-     ? EBADF                                                            \
+     ? (EI_UNDEF(*(FD), -1), EBADF)                                     \
      : (*(FD) = (int) (intptr_t) (CTX), 0))
 
 #define EI_GET_FD__(CBS, CTX, FD)                                       \
@@ -95,7 +95,9 @@ extern int ei_plugin_socket_impl__;
     (EI_HAVE_PLUGIN_SOCKET_IMPL__                                       \
      ? ei_get_cbs_ctx__((CBS), (CTX), (FD))                             \
      : ((FD) < 0                                                        \
-        ? EBADF                                                         \
+        ? (EI_UNDEF(*(CBS), NULL),                                      \
+           EI_UNDEF(*(CTX), NULL),                                      \
+           EBADF)                                                       \
         : (*(CBS) = &ei_default_socket_callbacks,                       \
            *(CTX) = EI_FD_AS_CTX__((FD)),                               \
            0)))
diff --git a/lib/erl_interface/src/misc/eidef.h b/lib/erl_interface/src/misc/eidef.h
index 90d1501e42..3726143683 100644
--- a/lib/erl_interface/src/misc/eidef.h
+++ b/lib/erl_interface/src/misc/eidef.h
@@ -83,4 +83,14 @@ typedef signed   int   int32;
 #  define ASSERT(Cnd)
 #endif
 
+/* EI_UNDEF can be used to silence false warnings about
+ * "variable may be used uninitialized" while keeping the variable
+ * marked as undefined by valgrind.
+ */
+#ifdef VALGRIND
+#  define EI_UNDEF(V,I) do {} while(0)
+#else
+#  define EI_UNDEF(V,I) V = I
+#endif
+
 #endif /* _EIDEF_H */
diff --git a/lib/erl_interface/src/prog/erl_call.c b/lib/erl_interface/src/prog/erl_call.c
index 9a0a5c9aa9..367cbe3e98 100644
--- a/lib/erl_interface/src/prog/erl_call.c
+++ b/lib/erl_interface/src/prog/erl_call.c
@@ -1144,6 +1144,9 @@ static int rpc_print_node_stdout(ei_cnode* ec, int fd, char *mod,
     ei_term t;
     erlang_msg msg;
     char rex[MAXATOMLEN];
+#ifndef VALGRIND
+    index = -1;
+#endif
  
     if (ei_xrpc_to(ec, fd, mod, fun, inbuf, inbuflen, EI_RPC_FETCH_STDOUT) < 0) {
 	return ERL_ERROR;
-- 
2.43.0

openSUSE Build Service is sponsored by