On Tuesday 13 January 2026 13:39:23 LIU Hao wrote:
> 在 2025-12-29 02:01, Pali Rohár 写道:
> > This special case does not throw an exception from invalid parameter 
> > handler.
> > ---
> >   mingw-w64-crt/secapi/getenv_s.c                   | 6 +++---
> >   mingw-w64-libraries/winstorecompat/src/getenv_s.c | 6 +++---
> >   2 files changed, 6 insertions(+), 6 deletions(-)
> > 
> > diff --git a/mingw-w64-crt/secapi/getenv_s.c 
> > b/mingw-w64-crt/secapi/getenv_s.c
> > index b2731830df98..0b31f418833c 100644
> > --- a/mingw-w64-crt/secapi/getenv_s.c
> > +++ b/mingw-w64-crt/secapi/getenv_s.c
> > @@ -23,15 +23,15 @@ static errno_t __cdecl emu_getenv_s(size_t 
> > *pReturnValue, char *dstBuf, rsize_t
> >           return errno = EINVAL;
> >       }
> > +    /* After passing parameter validation, the errno is not changed. */
> > +
> >       if (!varName) {
> >           *pReturnValue = 0;
> >           if (dstBuf)
> >               dstBuf[0] = '\0';
> > -        return errno = EINVAL;
> > +        return 0;
> I don't think this change is correct. Microsoft doc says that `getenv_s()`
> returns `EINVAL` (and not zero) in this case: 
> https://learn.microsoft.com/en-us/cpp/c-runtime-library/reference/getenv-s-wgetenv-s?view=msvc-170#error-conditions

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.


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

Reply via email to