File 0361-erts-Fix-buggy-calls-to-erts_sys_explicit_8bit_geten.patch of Package erlang

From 7603a4fb82f72a72045eed26dd55de3067cfe344 Mon Sep 17 00:00:00 2001
From: Sverker Eriksson <sverker@erlang.org>
Date: Fri, 6 Jul 2018 20:12:28 +0200
Subject: [PATCH 1/7] erts: Fix buggy calls to erts_sys_explicit_8bit_getenv

Two of them only affect valgrind builds
and the one for ERL_CRASH_DUMP_NICE seems benign.

Return value changed in c2d70945dce9cb09d5d7120d6e9ddf7faac8d230
old -> new
-1 ->  0  not found
 0 ->  1  found ok
 1 -> -1  found but too big
---
 erts/emulator/beam/dist.c         | 2 +-
 erts/emulator/beam/erl_bif_info.c | 2 +-
 erts/emulator/sys/unix/sys.c      | 4 ++--
 3 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/erts/emulator/beam/dist.c b/erts/emulator/beam/dist.c
index 70474898b2..db35137e92 100644
--- a/erts/emulator/beam/dist.c
+++ b/erts/emulator/beam/dist.c
@@ -1099,7 +1099,7 @@ erts_dsig_send_group_leader(ErtsDSigData *dsdp, Eterm leader, Eterm remote)
 #  define PURIFY_MSG(msg)                                                    \
     do {								     \
 	char buf__[1]; size_t bufsz__ = sizeof(buf__);			     \
-	if (erts_sys_getenv_raw("VALGRIND_LOG_XML", buf__, &bufsz__) >= 0) { \
+	if (erts_sys_getenv_raw("VALGRIND_LOG_XML", buf__, &bufsz__) != 0) { \
 	    VALGRIND_PRINTF_XML("<erlang_error_log>"			     \
 			    "%s, line %d: %s</erlang_error_log>\n",	     \
 			    __FILE__, __LINE__, msg);			     \
diff --git a/erts/emulator/beam/erl_bif_info.c b/erts/emulator/beam/erl_bif_info.c
index 5789fa8e71..39442e52c6 100644
--- a/erts/emulator/beam/erl_bif_info.c
+++ b/erts/emulator/beam/erl_bif_info.c
@@ -1776,7 +1776,7 @@ static int check_if_xml(void)
 {
     char buf[1];
     size_t bufsz = sizeof(buf);
-    return erts_sys_getenv_raw("VALGRIND_LOG_XML", buf, &bufsz) >= 0;
+    return erts_sys_getenv_raw("VALGRIND_LOG_XML", buf, &bufsz) != 0;
 }
 #else
 #define check_if_xml() 0
diff --git a/erts/emulator/sys/unix/sys.c b/erts/emulator/sys/unix/sys.c
index 189ca083d7..36579ffdb4 100644
--- a/erts/emulator/sys/unix/sys.c
+++ b/erts/emulator/sys/unix/sys.c
@@ -637,9 +637,9 @@ prepare_crash_dump(int secs)
 
     envsz = sizeof(env);
     i = erts_sys_getenv__("ERL_CRASH_DUMP_NICE", env, &envsz);
-    if (i >= 0) {
+    if (i != 0) {
 	int nice_val;
-	nice_val = i != 0 ? 0 : atoi(env);
+	nice_val = (i != 1) ? 0 : atoi(env);
 	if (nice_val > 39) {
 	    nice_val = 39;
 	}
-- 
2.16.4