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

cast_to_largest_integral_type() strips 64-bits values down to 32-bits #34

Open
jeremfg opened this issue Sep 29, 2017 · 0 comments
Open

Comments

@jeremfg
Copy link

jeremfg commented Sep 29, 2017

When compiling on Windows, we use MinGW32, which compiles a 32-bit executable.
As such, the type "size_t" is 32-bit wide even thought the largest type supported (uintmax_t) is 64-bit wide.

So whenever we call "will_return" or "assert_int_equal" and similar macros, we cannot pass a 64-bit value as it gets stripped down to 32-bit by the first cast to size_t. I've copied the culprit macro below, notice the double casting happening there.

// Perform an unsigned cast to uintmax_t.
#define cast_to_largest_integral_type(value) \
    ((uintmax_t)((size_t)(value)))

We've thus far circumvented the problem by creating a local "cmockery.h" file with the following content:

#include <setjmp.h>
#include <stdarg.h>
#include <stddef.h>
#include <stdint.h>
#include_next "cmockery.h"

/* Needed because original function "will_return" does a call to cast_to_largest_integral_type(),
 * which strips the upper 32-bits of a 64-bit integer. This happens because there is an intermediate
 * cast using size_t
 */
#define will_return64(function, value)          \
    _will_return(#function, __FILE__, __LINE__, \
                 value, 1)

/* Needed because original function "assert_int_equal" does some call to cast_to_largest_integral_type(),
 * which strips the upper 32-bits of a 64-bit integer. This happens because there is an intermediate
 * cast using size_t
 */
#define assert_int_equal64(a, b) \
    _assert_int_equal((uintmax_t) a, (uintmax_t) b, __FILE__, __LINE__)
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

1 participant