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

Can't compile with GCC 7.1.1 #179

Closed
Rubonnek opened this issue Jun 4, 2017 · 8 comments
Closed

Can't compile with GCC 7.1.1 #179

Rubonnek opened this issue Jun 4, 2017 · 8 comments

Comments

@Rubonnek
Copy link

Rubonnek commented Jun 4, 2017

Compiling latest release (v1.5.3) or the latest git commit 00d5e22 yields the following:

...
[ 72%] Building C object tests/CMakeFiles/parse_with_opts.dir/parse_with_opts.c.o
In file included from /path_to_src/cJSON-1.5.3/tests/unity/src/unity.h:16:0,
                 from /path_to_src/cJSON-1.5.3/tests/parse_hex4.c:28:
/path_to_src/cJSON-1.5.3/tests/parse_hex4.c: In function ‘parse_hex4_should_parse_all_combinations’:
/path_to_src/cJSON-1.5.3/tests/parse_hex4.c:39:42: error: ‘sprintf’ may write a terminating nul past the end of the destination [-Werror=format-overflow=]
         TEST_ASSERT_EQUAL_INT_MESSAGE(4, sprintf((char*)digits_lower, "%.4x", number), "sprintf failed.");
/path_to_src/cJSON-1.5.3/tests/unity/src/unity_internals.h:640:156: note: in definition of macro ‘UNITY_TEST_ASSERT_EQUAL_INT’
 #define UNITY_TEST_ASSERT_EQUAL_INT(expected, actual, line, message)                             UnityAssertEqualNumber((UNITY_INT)(expected), (UNITY_INT)(actual), (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_INT)
                                                                                                                                                            ^~~~~~
/path_to_src/cJSON-1.5.3/tests/parse_hex4.c:39:9: note: in expansion of macro ‘TEST_ASSERT_EQUAL_INT_MESSAGE’
         TEST_ASSERT_EQUAL_INT_MESSAGE(4, sprintf((char*)digits_lower, "%.4x", number), "sprintf failed.");
         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/path_to_src/cJSON-1.5.3/tests/parse_hex4.c:39:42: note: ‘sprintf’ output between 5 and 6 bytes into a destination of size 5
         TEST_ASSERT_EQUAL_INT_MESSAGE(4, sprintf((char*)digits_lower, "%.4x", number), "sprintf failed.");
/path_to_src/cJSON-1.5.3/tests/unity/src/unity_internals.h:640:156: note: in definition of macro ‘UNITY_TEST_ASSERT_EQUAL_INT’
 #define UNITY_TEST_ASSERT_EQUAL_INT(expected, actual, line, message)                             UnityAssertEqualNumber((UNITY_INT)(expected), (UNITY_INT)(actual), (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_INT)
                                                                                                                                                            ^~~~~~
/path_to_src/cJSON-1.5.3/tests/parse_hex4.c:39:9: note: in expansion of macro ‘TEST_ASSERT_EQUAL_INT_MESSAGE’
         TEST_ASSERT_EQUAL_INT_MESSAGE(4, sprintf((char*)digits_lower, "%.4x", number), "sprintf failed.");
         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/path_to_src/cJSON-1.5.3/tests/parse_hex4.c:40:42: error: ‘sprintf’ may write a terminating nul past the end of the destination [-Werror=format-overflow=]
         TEST_ASSERT_EQUAL_INT_MESSAGE(4, sprintf((char*)digits_upper, "%.4X", number), "sprintf failed.");
/path_to_src/cJSON-1.5.3/tests/unity/src/unity_internals.h:640:156: note: in definition of macro ‘UNITY_TEST_ASSERT_EQUAL_INT’
 #define UNITY_TEST_ASSERT_EQUAL_INT(expected, actual, line, message)                             UnityAssertEqualNumber((UNITY_INT)(expected), (UNITY_INT)(actual), (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_INT)
                                                                                                                                                            ^~~~~~
/path_to_src/cJSON-1.5.3/tests/parse_hex4.c:40:9: note: in expansion of macro ‘TEST_ASSERT_EQUAL_INT_MESSAGE’
         TEST_ASSERT_EQUAL_INT_MESSAGE(4, sprintf((char*)digits_upper, "%.4X", number), "sprintf failed.");
         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/path_to_src/cJSON-1.5.3/tests/parse_hex4.c:40:42: note: ‘sprintf’ output between 5 and 6 bytes into a destination of size 5
         TEST_ASSERT_EQUAL_INT_MESSAGE(4, sprintf((char*)digits_upper, "%.4X", number), "sprintf failed.");
/path_to_src/cJSON-1.5.3/tests/unity/src/unity_internals.h:640:156: note: in definition of macro ‘UNITY_TEST_ASSERT_EQUAL_INT’
 #define UNITY_TEST_ASSERT_EQUAL_INT(expected, actual, line, message)                             UnityAssertEqualNumber((UNITY_INT)(expected), (UNITY_INT)(actual), (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_INT)
                                                                                                                                                            ^~~~~~
/path_to_src/cJSON-1.5.3/tests/parse_hex4.c:40:9: note: in expansion of macro ‘TEST_ASSERT_EQUAL_INT_MESSAGE’
         TEST_ASSERT_EQUAL_INT_MESSAGE(4, sprintf((char*)digits_upper, "%.4X", number), "sprintf failed.");
         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@FSMaxB
Copy link
Collaborator

FSMaxB commented Jun 4, 2017

I can't reproduce this using GCC 7.1.1 on Archlinux x86_64. Can you please provide some information about your build environment.

@Rubonnek
Copy link
Author

Rubonnek commented Jun 4, 2017

I'm also using Archlinux x86_64. I just updated all the packages today. I also removed /etc/makepkg.conf and reinstalled a default one, and I still got that same message.

@Rubonnek
Copy link
Author

Rubonnek commented Jun 4, 2017

By the way, I tried installing it using the packages cjson and cjson-git from the AUR.

@FSMaxB
Copy link
Collaborator

FSMaxB commented Jun 4, 2017

That's strange, when building from the AUR I get the same error. I'll investigate!

@Rubonnek
Copy link
Author

Rubonnek commented Jun 4, 2017

Whoa, you're right. I just cloned the repository and I was able to build it manually, but building through the AUR doesn't work.

@FSMaxB
Copy link
Collaborator

FSMaxB commented Jun 4, 2017

I found the reason: The build only fails when compiling with -O2 (or possibly other optimization levels), which makepkg sets by default.

Should be an easy fix, just checking for format-overlow support and disabling it and reporting the issue with cUnity upstream (if it's not already fixed).

Working on it!

@FSMaxB
Copy link
Collaborator

FSMaxB commented Jun 4, 2017

Fixed and AUR packages updated! Thanks for reporting.

I'm still not sure though why GCC was complaining, this shouldn't be an overflow, maybe I have to file a bug.

@Rubonnek
Copy link
Author

Rubonnek commented Jun 4, 2017

Thanks a lot!

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

No branches or pull requests

2 participants