Bengt Gunne

The annotation for getenv_s and _wgetenv_s does not allow NULL to be passed in for the buffer (_DstBuf) parameter.

Code Block

_CRTIMP __checkReturn_wat errno_t __cdecl _wgetenv_s(__out size_t * _ReturnSize, __out_ecount_z(_DstSizeInWords) wchar_t * _DstBuf, __in size_t _DstSizeInWords, __in_z const wchar_t * _VarName);

According to the documentation the parameter can be NULL when the size parameter (_DstSizeInWords) is zero. In addition, the example in the documentation contains the following code:

Code Block

getenv_s( &requiredSize, NULL, 0, "LIB");

I think the correct declaration should be:

Code Block

_CRTIMP __checkReturn_wat errno_t __cdecl _wgetenv_s(__out size_t * _ReturnSize, __out_ecount_z_opt(_DstSizeInWords) wchar_t * _DstBuf, __in size_t _DstSizeInWords, __in_z const wchar_t * _VarName);

Regards

Bengt



Re: Visual Studio Code Analysis and Code Metrics Annotation for getenv_s

Dave Bartolomeo - MSFT

Yes, it looks like this annotation is too strict. I've notified the CRT owners.





Re: Visual Studio Code Analysis and Code Metrics Annotation for getenv_s

Bengt Gunne

Thanks!