diff --git a/librhash/algorithms.c b/librhash/algorithms.c index 22f87f0d..243a5da9 100644 --- a/librhash/algorithms.c +++ b/librhash/algorithms.c @@ -181,6 +181,11 @@ void rhash_init_algorithms(void) rhash_gost94_init_table(); #endif table_init_sha_ext(); + +#if defined(_MSC_VER) + /* ensure that (LONG*)&algorithms_initialized_flag is valid */ + RHASH_ASSERT(sizeof(LONG) == sizeof(unsigned)); +#endif atomic_compare_and_swap(&algorithms_initialized_flag, 0, 1); } diff --git a/librhash/util.h b/librhash/util.h index 1b38e8e5..f2ac4bc2 100644 --- a/librhash/util.h +++ b/librhash/util.h @@ -22,7 +22,8 @@ extern "C" { #elif defined(_MSC_VER) # define WIN32_LEAN_AND_MEAN # include -# define atomic_compare_and_swap(ptr, oldval, newval) InterlockedCompareExchange(ptr, newval, oldval) +# define atomic_compare_and_swap(ptr, oldval, newval) \ + InterlockedCompareExchange((LONG volatile*)(ptr), (LONG)(newval), (LONG)(oldval)) #elif defined(__sun) # include # define atomic_compare_and_swap(ptr, oldval, newval) atomic_cas_32(ptr, oldval, newval)