ben-strasser / fast-cpp-csv-parser

fast-cpp-csv-parser
BSD 3-Clause "New" or "Revised" License
2.13k stars 441 forks source link

C4996 (function or variable may be unsafe) error for strncpy and fopen #138

Closed amuuu closed 1 year ago

amuuu commented 1 year ago

Hello,

I'm trying to integrate the header in my code but it gives me these errors:

C4996 'strncpy': This function or variable may be unsafe. Consider using `strncpy_s` instead. To disable deprecation, use `_CRT_SECURE_NO_WARNINGS`. See online help for details.   

C4996 'fopen': This function or variable may be unsafe. Consider using `fopen_s` instead. To disable deprecation, use `_CRT_SECURE_NO_WARNINGS`. See online help for details.   

I don't want to disable deprecation preferably.

I tried to change the header to use strncpy_s and fopen_s but it gave the error that std doesn't contain those functions. The global namespace has those functions but they have different headers.

Any idea how can I make it work?

Thanks in advance.

(Note, I'm using VS2022,17.4.4, C++17)

ben-strasser commented 1 year ago

There is no good solution here.

Both usages in the code base are perfectly fine and safe and it's a false positive on the side of your compiler.

The strncpy_s and fopen_s are newer than their counterpart and switching might therefore break other users. I will not potentially break users to suppress false positives for some users.

The strncpy usage could be "solved" by writing the loop by hand... but that does not really make things better.

I think the easiest way is to selectively suppress the warning using https://learn.microsoft.com/en-us/cpp/preprocessor/warning

amuuu commented 1 year ago

Thank you so much 🙏🏽👊🏽