stb icon indicating copy to clipboard operation
stb copied to clipboard

Ignore C4996

Open patYczakus opened this issue 10 months ago • 9 comments

Is your feature request related to a problem? Please describe. Well, I know to have support older functions, but MSVS blocks running because of sprintf. I think it will be better to turn off this warning.

Describe the solution you'd like Add #pragma warning(disable : 4996) to file.

Describe alternatives you've considered I think it is no other solution.

Additional context None

patYczakus avatar Feb 26 '25 18:02 patYczakus

have you tried setting the define _CRT_SECURE_NO_WARNINGS? (i.e. /D_CRT_SECURE_NO_WARNINGS ) This can be used to suppress the MSVC warnings like this: error C4996: 'strncpy': This function or variable may be unsafe. Consider using strncpy_s instead.

foxblock avatar Mar 05 '25 13:03 foxblock

have you tried setting the define _CRT_SECURE_NO_WARNINGS? (i.e. /D_CRT_SECURE_NO_WARNINGS )

Yea, but to be honest, is it make sense to define this all the time? Better for me if it's defined on file at start

patYczakus avatar Mar 05 '25 18:03 patYczakus

Not everyone uses MSVS. If you add the define prior to the include, you'll have no issue.

RobLoach avatar Mar 10 '25 00:03 RobLoach

We generally prefer to avoid using _CRT_SECURE_NO_WARNINGS since that will affect compilation of the user's code, and similarly we prefer to avoid using #pragmas to disable warnings, and instead fix the code to avoid the warnings.

Please specify what library is triggering the warning.

nothings avatar Mar 10 '25 00:03 nothings

[...] we prefer to avoid using #pragmas to disable warnings, and instead fix the code to avoid the warnings.

You have a point, but I think there is no code fix. MSVS "shouts" at me that one function is deprecated and not secure, and this library use that function (which function? I mentioned before - sprintf). If I am right, it is used to support other devices that they don't support suggested alternative (sprintf_s).

Please specify what library is triggering the warning.

stb_image_write.h causes the warning.

patYczakus avatar Mar 10 '25 16:03 patYczakus

This used to work differently, see #744.

I'm not really sure how any of this is supposed to work.

Also, just to be clear, I assume you're using "MSVS" to refer to Microsoft Visual Studio C/C++ compiler, and it's not some other weird compiler I've never heard of. Google autocorrects the search MSVS compiler to MSVC compiler.

nothings avatar Mar 10 '25 17:03 nothings

Okay, I was busy at that time, so sorry that I am answering rn

This used to work differently, see https://github.com/nothings/stb/issues/744.

I'm not really sure how any of this is supposed to work.

To be honest, I don't know that too. The funniest thing is that I have sprintf_s. Just made this test:

char buffer[50];
int result = sprintf_s(buffer, sizeof(buffer), "Test: %d", 123);
if (result >= 0) {
    printf("sprintf_s working fine: %s\n", buffer);
    return 0;
}
else {
    printf("sprintf_s is not enabled on this.\n");
    return 1;
}

...and the result is like that:

Image

Also, I checked if the sprintf_s in stb_image_write.h will work anyway:

Image

And the file was created... really, zero errors.

So to sum up, the problem is in __STDC_LIB_EXT1__.

I can upload the C++ file with the modified package. I also fixed there somehow the bug that min and max was duplicated when compiled.

Also, just to be clear, I assume you're using "MSVS" to refer to Microsoft Visual Studio C/C++ compiler, and it's not some other weird compiler I've never heard of. Google autocorrects the search MSVS compiler to MSVC compiler.

I think yea. I mean, I referred to Microsoft Visual Studio as a program, not as a compiler, but it can be my fault.

patYczakus avatar Apr 24 '25 21:04 patYczakus

Okay, I see #1257 pull request. I will check it probably tommorow, and I'll let you know.

patYczakus avatar Apr 24 '25 21:04 patYczakus

I also met this warning on MSVC. Is it ok to use __STDC_SECURE_LIB__ to check if sprintf_s exists on MSVC? But I haven't found any official document talking about this macro

lumina37 avatar Aug 25 '25 03:08 lumina37