在 2026-2-14 02:29, Pali Rohár 写道:
On Saturday 17 January 2026 13:43:02 Pali Rohár wrote:
Here is simple test which proves that it returns 0 in this case:
https://godbolt.org/z/8sTeWY4dv

I can send a test file with all of those special combinations, so would
be sure how it really behaves.

Do you still think that this change is really incorrect?
Or do you need some other tests from me?

I have observed the same on Visual Studio 2026. Indeed, unlike `getenv()` and `dupenv_s()` which fail with null variable name pointers, `getenv_s()` succeeds and reports a length of zero.

So this should be accepted; however there need be a comment which says that the contradiction with Microsoft documentation is by design, so it's not our bug. I have pushed this patches with this change:


diff --git a/mingw-w64-crt/secapi/getenv_s.c b/mingw-w64-crt/secapi/getenv_s.c
index 0b31f4188..07ea3ac49 100644
--- a/mingw-w64-crt/secapi/getenv_s.c
+++ b/mingw-w64-crt/secapi/getenv_s.c
@@ -29,6 +29,7 @@ static errno_t __cdecl emu_getenv_s(size_t *pReturnValue, 
char *dstBuf, rsize_t
         *pReturnValue = 0;
         if (dstBuf)
             dstBuf[0] = '\0';
+        /* UCRT `getenv_s()` reports success in this case. */
         return 0;
     }

diff --git a/mingw-w64-libraries/winstorecompat/src/getenv_s.c b/mingw-w64-libraries/winstorecompat/src/getenv_s.c
index 66a8368df..93db31ba0 100644
--- a/mingw-w64-libraries/winstorecompat/src/getenv_s.c
+++ b/mingw-w64-libraries/winstorecompat/src/getenv_s.c
@@ -30,6 +30,7 @@ errno_t __cdecl getenv_s(size_t *pReturnValue, char *dstBuf, 
rsize_t dstSize, co
         *pReturnValue = 0;
         if (dstBuf)
             dstBuf[0] = '\0';
+        /* UCRT `getenv_s()` reports success in this case. */
         return 0;
     }





--
Best regards,
LIU Hao

Attachment: OpenPGP_signature.asc
Description: OpenPGP digital signature

_______________________________________________
Mingw-w64-public mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/mingw-w64-public

Reply via email to