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

warning: cast from pointer to integer of different size #84

Closed
reedjc opened this issue Oct 31, 2019 · 0 comments
Closed

warning: cast from pointer to integer of different size #84

reedjc opened this issue Oct 31, 2019 · 0 comments

Comments

@reedjc
Copy link
Contributor

reedjc commented Oct 31, 2019

On NetBSD I saw:
fltmod/nmsg_flt_sample.c: In function 'sample_thread_init':
fltmod/nmsg_flt_sample.c:223:65: warning: cast from pointer to integer of different size [-Wpointer-to-int-cast]
uint32_t seed = (unsigned) tv.tv_sec + (unsigned) tv.tv_usec + (unsigned) pthread_self();

I didn't see on LInux, both x86_64 architecture. Both with same sizes of pthread_t and unsigned and int and uintptr_t. (My NetBSD gcc is 5.5.0 and debian gcc is 6.3.0.)

My workaround is:

--- a/fltmod/nmsg_flt_sample.c
+++ b/fltmod/nmsg_flt_sample.c
@@ -220,7 +220,7 @@ sample_thread_init(void *mod_data, void **thr_data)
        /* Initialize state->xsubi, seed for this thread's random generator. */
        struct timeval tv = {0};
        gettimeofday(&tv, NULL);
-       uint32_t seed = (unsigned) tv.tv_sec + (unsigned) tv.tv_usec + (unsigned) pthread_self();
+       uint32_t seed = (unsigned) tv.tv_sec + (unsigned) tv.tv_usec + (uintptr_t) pthread_self();
        memcpy(state->xsubi, &seed, sizeof(seed));
cmikk added a commit that referenced this issue Sep 15, 2023
Cast pthread_t to uintptr_t to address pointer to smaller integer
cast warnings on systems where pthread_t is a pointer type.

Fixes #84
@reedjc reedjc closed this as completed in d27f1af Oct 12, 2023
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