If the GetEnvironmentVariable was called with NULL buffer then the return
value is buffer size including its terminating null character.
This differs from the case when GetEnvironmentVariable succeeds, then it
returns size without the terminating null character.
CRT getenv_s function always returns size with terminating null character.
---
mingw-w64-libraries/winstorecompat/src/getenv_s.c | 7 +++++++
1 file changed, 7 insertions(+)
diff --git a/mingw-w64-libraries/winstorecompat/src/getenv_s.c
b/mingw-w64-libraries/winstorecompat/src/getenv_s.c
index ed7c52523279..5988082fab32 100644
--- a/mingw-w64-libraries/winstorecompat/src/getenv_s.c
+++ b/mingw-w64-libraries/winstorecompat/src/getenv_s.c
@@ -63,6 +63,13 @@ errno_t __cdecl getenv_s(size_t *pReturnValue, char *dstBuf,
rsize_t dstSize, co
if (dstBuf)
dstBuf[0] = '\0';
return ERANGE;
+ } else if (dstSize == 0) {
+ /* If the GetEnvironmentVariable was called with NULL buffer then
+ * the return value is same as above case: buffer size including its
+ * terminating null character.
+ */
+ *pReturnValue = ret;
+ return 0;
} else {
/* If the GetEnvironmentVariable succeeds, the return value is the
* number of characters stored in the buffer, not including the
--
2.20.1
_______________________________________________
Mingw-w64-public mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/mingw-w64-public