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

Compiler warning -Werror=stringop-truncation fix for error.c #700

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

sbytnar
Copy link

@sbytnar sbytnar commented Sep 26, 2024

Hi. This warning is emitted by newer versions of gcc. The project I'm working with treats this particular warning as an error.
The fix below makes the compiler happy.

The full error message emitted looks like this:

| jansson/src/error.c: In function 'jsonp_error_set_source':
| jansson/src/error.c:25:9: error: '__builtin_strncpy' specified bound depends on the length of the source argument [-Werror=stringop-truncation]
|    25 |         strncpy(error->source, source, length + 1);
|       |         ^
| In function 'jsonp_error_set_source',
| jansson/src/error.c:17:6:
| jansson/src/error.c:23:14: note: length computed here
|    23 |     length = strlen(source);
|       |              ^~~~~~~~~~~~~~
| cc1: all warnings being treated as errors

Thank you.
--Steve

…und depends on the length of the source argument [-Werror=stringop-truncation]"
@sbytnar
Copy link
Author

sbytnar commented Sep 26, 2024

This would fix #630

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

Successfully merging this pull request may close these issues.

1 participant