[PATCH] benchtests: Avoid truncation in random memcpy/memset benchmarks

Carlos O'Donell carlos@redhat.com
Tue Aug 12 02:17:42 GMT 2025


On 7/29/25 10:36 AM, Wilco Dijkstra wrote:
> 
> Use uint16_t rather than uint8_t for the size arrays.
> 
> OK for commit?

The test data distribution may overflow uint8_t by storing a uint16_t value.

This skews the distribution, but doesn't inherently break the the testing, it
just doesn't make it possible to adjust the distribution in any meaningful way.

I'm surprised the compiler didn't complain.

Reviewed-by: Carlos O'Donell <carlos@redhat.com>

> ---
> 
> diff --git a/benchtests/bench-memcpy-random.c b/benchtests/bench-memcpy-random.c
> index d17c784eb67809dfbb0e30100156bdd6d4e6d487..0734bc84aea937dff1efec1faa251a83a6db20b7 100644
> --- a/benchtests/bench-memcpy-random.c
> +++ b/benchtests/bench-memcpy-random.c
> @@ -34,7 +34,7 @@ typedef struct { uint8_t align; uint16_t freq; } align_data_t;
>   
>   #define SIZE_NUM 65536
>   #define SIZE_MASK (SIZE_NUM-1)
> -static uint8_t size_arr[SIZE_NUM];
> +static uint16_t size_arr[SIZE_NUM];

OK. Since size_arr may store freq_data_t size which is uint16_t.

>   
>   /* Frequency data for memcpy of less than 4096 bytes based on SPEC2017.  */
>   static freq_data_t size_freq[] =
> diff --git a/benchtests/bench-memset-random.c b/benchtests/bench-memset-random.c
> index 642bf411d482944949b6451f2426363e0de5115c..758c53bc6f5031dabd972a493ae800b50df5bb69 100644
> --- a/benchtests/bench-memset-random.c
> +++ b/benchtests/bench-memset-random.c
> @@ -39,7 +39,7 @@ typedef struct { uint8_t align; uint16_t freq; } align_data_t;
>   
>   #define SIZE_NUM 65536
>   #define SIZE_MASK (SIZE_NUM-1)
> -static uint8_t len_arr[SIZE_NUM];
> +static uint16_t len_arr[SIZE_NUM];

OK. Since len_arr may store freq_data_t size which is unit16_t.

>   
>   /* Frequency data for memset sizes up to 4096 bytes based on SPEC2017.  */
>   static freq_data_t memset_len_freq[] =
> 
> 


-- 
Cheers,
Carlos.



More information about the Libc-alpha mailing list