Skip to content

Commit

Permalink
Merge pull request #1004 from Cyan4973/usan_fix
Browse files Browse the repository at this point in the history
attempt to silence a recent ubsan warning with code reorganization
  • Loading branch information
Cyan4973 authored Jan 22, 2025
2 parents 1bf7bc4 + 71e797b commit f5a0b6f
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 8 deletions.
2 changes: 1 addition & 1 deletion cli/xsum_sanity_check.c
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ static XSUM_U32 XSUM_rand(void)
* Technically, XXH3_64bits_update is identical to XXH3_128bits_update as of
* v0.8.0, but we treat them as separate.
*/
typedef XXH_errorcode (*XSUM_XXH3_update_t)(XXH3_state_t* state, const void* input, size_t length);
typedef XXH_errorcode (*XSUM_XXH3_update_t)(XXH_NOESCAPE XXH3_state_t* state, XXH_NOESCAPE const void* input, size_t length);

/*
* Runs the passed XXH3_update variant on random lengths. This is to test the
Expand Down
2 changes: 1 addition & 1 deletion xxh_x86dispatch.c
Original file line number Diff line number Diff line change
Expand Up @@ -632,7 +632,7 @@ typedef XXH128_hash_t (*XXH3_dispatchx86_hashLong128_default)(XXH_NOESCAPE const

typedef XXH128_hash_t (*XXH3_dispatchx86_hashLong128_withSeed)(XXH_NOESCAPE const void* XXH_RESTRICT, size_t, XXH64_hash_t);

typedef XXH128_hash_t (*XXH3_dispatchx86_hashLong128_withSecret)(XXH_NOESCAPE const void* XXH_RESTRICT, size_t, const void* XXH_RESTRICT, size_t);
typedef XXH128_hash_t (*XXH3_dispatchx86_hashLong128_withSecret)(XXH_NOESCAPE const void* XXH_RESTRICT, size_t, XXH_NOESCAPE const void* XXH_RESTRICT, size_t);

typedef struct {
XXH3_dispatchx86_hashLong128_default hashLong128_default;
Expand Down
22 changes: 16 additions & 6 deletions xxhash.h
Original file line number Diff line number Diff line change
Expand Up @@ -1363,7 +1363,7 @@ XXH_PUBLIC_API XXH_errorcode XXH3_64bits_update (XXH_NOESCAPE XXH3_state_t* stat
*
* @see @ref streaming_example "Streaming Example"
*/
XXH_PUBLIC_API XXH_PUREF XXH64_hash_t XXH3_64bits_digest (XXH_NOESCAPE const XXH3_state_t* statePtr);
XXH_PUBLIC_API XXH_PUREF XXH64_hash_t XXH3_64bits_digest (XXH_NOESCAPE const XXH3_state_t* statePtr);
#endif /* !XXH_NO_STREAM */

/* note : canonical representation of XXH3 is the same as XXH64
Expand Down Expand Up @@ -6523,8 +6523,9 @@ XXH3_consumeStripes(xxh_u64* XXH_RESTRICT acc,
# define XXH3_STREAM_USE_STACK 1
# endif
#endif
/*
* Both XXH3_64bits_update and XXH3_128bits_update use this routine.
/* This function accepts f_acc and f_scramble as function pointers,
* making it possible to implement multiple variants with different acc & scramble stages.
* This is notably useful to implement multiple vector variants with different intrinsics.
*/
XXH_FORCE_INLINE XXH_errorcode
XXH3_update(XXH3_state_t* XXH_RESTRICT const state,
Expand Down Expand Up @@ -6605,12 +6606,21 @@ XXH3_update(XXH3_state_t* XXH_RESTRICT const state,
return XXH_OK;
}

/*
* Both XXH3_64bits_update and XXH3_128bits_update use this routine.
*/
XXH_NO_INLINE XXH_errorcode
XXH3_update_regular(XXH_NOESCAPE XXH3_state_t* state, XXH_NOESCAPE const void* input, size_t len)
{
return XXH3_update(state, (const xxh_u8*)input, len,
XXH3_accumulate, XXH3_scrambleAcc);
}

/*! @ingroup XXH3_family */
XXH_PUBLIC_API XXH_errorcode
XXH3_64bits_update(XXH_NOESCAPE XXH3_state_t* state, XXH_NOESCAPE const void* input, size_t len)
{
return XXH3_update(state, (const xxh_u8*)input, len,
XXH3_accumulate, XXH3_scrambleAcc);
return XXH3_update_regular(state, input, len);
}


Expand Down Expand Up @@ -7146,7 +7156,7 @@ XXH3_128bits_reset_withSecretandSeed(XXH_NOESCAPE XXH3_state_t* statePtr, XXH_NO
XXH_PUBLIC_API XXH_errorcode
XXH3_128bits_update(XXH_NOESCAPE XXH3_state_t* state, XXH_NOESCAPE const void* input, size_t len)
{
return XXH3_64bits_update(state, input, len);
return XXH3_update_regular(state, input, len);
}

/*! @ingroup XXH3_family */
Expand Down

0 comments on commit f5a0b6f

Please sign in to comment.