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

-Wstringop-truncation warnings observed in core_http_client.c #133

Closed
SKZahidBasha-Silabs opened this issue Jul 19, 2022 · 11 comments
Closed

Comments

@SKZahidBasha-Silabs
Copy link

SKZahidBasha-Silabs commented Jul 19, 2022

image

Warnings related to strncpy are observed in the core_http_client.c file at the below lines of code. Attached the warnings snapshot :

Line 1:
( void ) strncpy( pBufferCur,
HTTP_HEADER_FIELD_SEPARATOR,
HTTP_HEADER_FIELD_SEPARATOR_LEN );

Line 2:
( void ) strncpy( pBufferCur,
HTTP_HEADER_END_INDICATOR,
HTTP_HEADER_END_INDICATOR_LEN );

Line 3:
( void ) strncpy( pBufferCur,
HTTP_HEADER_LINE_SEPARATOR,
HTTP_HEADER_LINE_SEPARATOR_LEN );

@SKZahidBasha-Silabs SKZahidBasha-Silabs changed the title -Wstringop-truncation warnings in core_http_client.c -Wstringop-truncation warnings observed in core_http_client.c Jul 19, 2022
@paulbartell
Copy link

@SKZahidBasha-Silabs : These warnings can be safely ignored since the target buffer is not necessarily a null terminated string.

You can mask these warnings locally with something like:

#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wstringop-truncation"
strncpy( ... )
#pragma GCC diagnostic pop

@alfred2g
Copy link
Contributor

@paulbartell, would be better if we use memcpy instead (since not null terminated) ?

@RichardBarry
Copy link

To help decide on the action to take - the code needs to compile without warnings with the -Wall and -Wextra GCC command line options.

@SKZahidBasha-Silabs
Copy link
Author

SKZahidBasha-Silabs commented Jul 20, 2022

Is it better to change strncpy() to memcpy() (or) use the pragmas as suggested above. I see memcpy() being used at some places in the same file.

@alfred2g
Copy link
Contributor

Better to change the strncpy to memcpy, GCC pragmas are not portable

@SKZahidBasha-Silabs
Copy link
Author

@alfred2g / @paulbartell / @RichardBarry so the fix for this would be to convert strncpy to memcpy, is that right? Shall we conclude on the fix approach please?

@alfred2g
Copy link
Contributor

@SKZahidBasha-Silabs, yeah that should be the fix, do you want to push a pull request, or you prefer if we do it ?

@SKZahidBasha-Silabs
Copy link
Author

SKZahidBasha-Silabs commented Jul 26, 2022

@alfred2g I guess you pushing the fix would be nicer for future tracking. Thanks for the confirmation on the approach!

@alfred2g
Copy link
Contributor

#134

@alfred2g
Copy link
Contributor

Code is merged, closing the issue

@SKZahidBasha-Silabs
Copy link
Author

Thanks, @alfred2g for fixing this!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants