check_expected causes segfault.
GoogleCodeExporter opened this issue · comments
What steps will reproduce the problem?
1. Compile test-cmockery with
gcc -std=c99 -I/opt/include -L/opt/lib -lcmockery test-cmockery.c -o
test-cmockery
2. Run ./test-cmockery
What is the expected output? What do you see instead?
Expected output:
sizeof(unsigned long long): 8
sizeof(unsigned): 4
sizeof(char*): 8
4365541014
70573718
70573718
4365541014
test_demo: Starting test
test_demo: Test completed successfully.
All 1 tests passed
Actual output:
sizeof(unsigned long long): 8
sizeof(unsigned): 4
sizeof(char*): 8
4438503062
143535766
143535766
4438503062
test_demo: Starting test
Segmentation fault: 11
test_demo: Test failed.
1 out of 1 tests failed!
test_demo
What version of the product are you using? On what operating system?
Git commit: 1c63f1f479463d9cb5185681cf11799e8efa9092
on Macintosh OS X Mountain Lion 10.8.5
Please provide any additional information below.
By modifying the macro cast_to_largest_integral_type (cmockery.h, line 51), it
is possible to to remove the error and see the expected output. Specifically,
changing
#define cast_to_largest_integral_type(value) \
((LargestIntegralType)((unsigned)(value)))
to
#define cast_to_largest_integral_type(value) \
((LargestIntegralType)((unsigned long long)(value)))
removes the error. What is the purpose of casting a pointer (8 bytes on my
system), to an unsigned integer (4 bytes on my system), then back to an
unsigned long long (8 bytes on my system)?
Original issue reported on code.google.com by btjone...@gmail.com
on 4 Jun 2014 at 8:25
Attachments: