Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MAP: replace strncpy with strncpy_s #2417

Closed
wants to merge 2 commits into from

Conversation

andrew-platt
Copy link
Collaborator

Ready to merge (need someone with actual C knowledge to review it though).

Feature or improvement description
The intel c++ w_oneAPI_2021.1.1.99 compiler does not like the strncpy function and won't compile. Changing to strncpy_s.

Related issue, if one exists
See comment here: 93e2d27#r14664285 from PR #2394
Impacted areas of the software
Compilation of MAP with some compilers.

@sanguinariojoe, can you check this?

The intel c++ w_oneAPI_2021.1.1.99 compiler does not like the `strncpy`
function and won't compile.  Changing to `strncpy_s`.
@andrew-platt
Copy link
Collaborator Author

Of course, changing to strncpy_s doesn't work with gcc... back to the drawing board I guess.

@bjonkman
Copy link
Contributor

I had an issue with this a few days ago using the Visual Studio 2022 v143 C/C++ compiler. I added the _CRT_NONSTDC_NO_WARNINGS definition in the code when using MSVC:

#define _CRT_SECURE_NO_WARNINGS

but Visual Studio had also turned on the compiling option Additional Security Development Lifecycle (SDL) recommended checks, which made the warning an error. When I removed the \SDL option, it was able to build with the strncpy routine.

image

This may be helpful: https://stackoverflow.com/questions/22450423/how-to-use-crt-secure-no-warnings

@sanguinariojoe
Copy link

sanguinariojoe commented Sep 13, 2024

Microsoft is a truck load of shit... Anyway, I would say the smartest solution would be replacing the offending line --and the following one-- by:

size_t n = strnlen(input_txt_line, sizeof(init_type->library_input_str)) - 1; 
*((char *)memcpy(init_type->library_input_str, input_txt_line, n) + n) = '\0';

Checkout the critics of Ulrich Drepper to strlcpy.

I wrote that code directly here, on GitHub. It is not even tested.

this should work with all compilers

Co-authored-by: Derek Slaughter <deslaughter@gmail.com>
@andrew-platt
Copy link
Collaborator Author

In trying out @deslaughter's suggestion, I discovered there is a MAP_STRCPY macro that already handles switching from strcpy and strcpy_s depending on compiler setup. Going to switch over to that instead -- will replace this PR with a PR from a new branch.

@andrew-platt
Copy link
Collaborator Author

Thanks @bjonkman for the workaround in VS. I think the new solution in #2420 is a bit simpler for end users, so we'll pursue that route.

@andrew-platt andrew-platt deleted the b/map_strncpy branch September 13, 2024 21:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants