[dpdk-dev,v4,05/23] /lib/librte_eal: stage cast from uint64 to long

Message ID 152627459268.53156.2149755990250830416.stgit@localhost.localdomain (mailing list archive)
State Superseded, archived
Delegated to: Thomas Monjalon
Headers

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/Intel-compilation success Compilation OK

Commit Message

Andy Green May 14, 2018, 5:09 a.m. UTC
  /projects/lagopus/src/dpdk/build/include/rte_random.h:
In function 'rte_srand':
/projects/lagopus/src/dpdk/build/include/rte_random.h:34:10:
warning: conversion to 'long int' from 'long unsigned int'
may change the sign of the result [-Wsign-conversion]
  srand48((long unsigned int)seedval);

/projects/lagopus/src/dpdk/build/include/rte_random.h:51:8:
warning: conversion to 'uint64_t' {aka 'long unsigned int'}
from 'long int' may change the sign of the result
[-Wsign-conversion]
  val = lrand48();
        ^~~~~~~
/projects/lagopus/src/dpdk/build/include/rte_random.h:53:6:
warning: conversion to 'long unsigned int' from 'long int'
may change the sign of the result [-Wsign-conversion]
  val += lrand48();

Signed-off-by: Andy Green <andy@warmcat.com>
---
 lib/librte_eal/common/include/rte_random.h |    6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
  

Comments

Bruce Richardson May 17, 2018, 10:47 a.m. UTC | #1
On Mon, May 14, 2018 at 01:09:52PM +0800, Andy Green wrote:
> /projects/lagopus/src/dpdk/build/include/rte_random.h:
> In function 'rte_srand':
> /projects/lagopus/src/dpdk/build/include/rte_random.h:34:10:
> warning: conversion to 'long int' from 'long unsigned int'
> may change the sign of the result [-Wsign-conversion]
>   srand48((long unsigned int)seedval);
> 
> /projects/lagopus/src/dpdk/build/include/rte_random.h:51:8:
> warning: conversion to 'uint64_t' {aka 'long unsigned int'}
> from 'long int' may change the sign of the result
> [-Wsign-conversion]
>   val = lrand48();
>         ^~~~~~~
> /projects/lagopus/src/dpdk/build/include/rte_random.h:53:6:
> warning: conversion to 'long unsigned int' from 'long int'
> may change the sign of the result [-Wsign-conversion]
>   val += lrand48();
> 
> Signed-off-by: Andy Green <andy@warmcat.com>
> ---
>  lib/librte_eal/common/include/rte_random.h |    6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)
> 
> diff --git a/lib/librte_eal/common/include/rte_random.h b/lib/librte_eal/common/include/rte_random.h
> index 63bb28088..e30777b83 100644
> --- a/lib/librte_eal/common/include/rte_random.h
> +++ b/lib/librte_eal/common/include/rte_random.h
> @@ -31,7 +31,7 @@ extern "C" {
>  static inline void
>  rte_srand(uint64_t seedval)
>  {
> -	srand48((long unsigned int)seedval);
> +	srand48((long)(unsigned long)seedval);

Is double-cast necessary here? Can we not just cast straight to long?

>  }
>  
>  /**
> @@ -48,9 +48,9 @@ static inline uint64_t
>  rte_rand(void)
>  {
>  	uint64_t val;
> -	val = lrand48();
> +	val = (uint64_t)lrand48();
>  	val <<= 32;
> -	val += lrand48();
> +	val += (uint64_t)lrand48();
>  	return val;
>  }
>  
> 

Apart from the one minor comment above LGTM

Acked-by: Bruce Richardson <bruce.richardson@intel.com>
  
Andy Green May 17, 2018, 12:56 p.m. UTC | #2
On 05/17/2018 06:47 PM, Bruce Richardson wrote:
> On Mon, May 14, 2018 at 01:09:52PM +0800, Andy Green wrote:
>> /projects/lagopus/src/dpdk/build/include/rte_random.h:
>> In function 'rte_srand':
>> /projects/lagopus/src/dpdk/build/include/rte_random.h:34:10:
>> warning: conversion to 'long int' from 'long unsigned int'
>> may change the sign of the result [-Wsign-conversion]
>>    srand48((long unsigned int)seedval);
>>
>> /projects/lagopus/src/dpdk/build/include/rte_random.h:51:8:
>> warning: conversion to 'uint64_t' {aka 'long unsigned int'}
>> from 'long int' may change the sign of the result
>> [-Wsign-conversion]
>>    val = lrand48();
>>          ^~~~~~~
>> /projects/lagopus/src/dpdk/build/include/rte_random.h:53:6:
>> warning: conversion to 'long unsigned int' from 'long int'
>> may change the sign of the result [-Wsign-conversion]
>>    val += lrand48();
>>
>> Signed-off-by: Andy Green <andy@warmcat.com>
>> ---
>>   lib/librte_eal/common/include/rte_random.h |    6 +++---
>>   1 file changed, 3 insertions(+), 3 deletions(-)
>>
>> diff --git a/lib/librte_eal/common/include/rte_random.h b/lib/librte_eal/common/include/rte_random.h
>> index 63bb28088..e30777b83 100644
>> --- a/lib/librte_eal/common/include/rte_random.h
>> +++ b/lib/librte_eal/common/include/rte_random.h
>> @@ -31,7 +31,7 @@ extern "C" {
>>   static inline void
>>   rte_srand(uint64_t seedval)
>>   {
>> -	srand48((long unsigned int)seedval);
>> +	srand48((long)(unsigned long)seedval);
> 
> Is double-cast necessary here? Can we not just cast straight to long?

You're right, it can just go straight to long.

I'm going through adding the compiler errors into the patches that have 
them missing and doing this kind of small change, and I'll reissue in an 
hour or two (.

-Andy

>>   }
>>   
>>   /**
>> @@ -48,9 +48,9 @@ static inline uint64_t
>>   rte_rand(void)
>>   {
>>   	uint64_t val;
>> -	val = lrand48();
>> +	val = (uint64_t)lrand48();
>>   	val <<= 32;
>> -	val += lrand48();
>> +	val += (uint64_t)lrand48();
>>   	return val;
>>   }
>>   
>>
> 
> Apart from the one minor comment above LGTM
> 
> Acked-by: Bruce Richardson <bruce.richardson@intel.com>
>
  

Patch

diff --git a/lib/librte_eal/common/include/rte_random.h b/lib/librte_eal/common/include/rte_random.h
index 63bb28088..e30777b83 100644
--- a/lib/librte_eal/common/include/rte_random.h
+++ b/lib/librte_eal/common/include/rte_random.h
@@ -31,7 +31,7 @@  extern "C" {
 static inline void
 rte_srand(uint64_t seedval)
 {
-	srand48((long unsigned int)seedval);
+	srand48((long)(unsigned long)seedval);
 }
 
 /**
@@ -48,9 +48,9 @@  static inline uint64_t
 rte_rand(void)
 {
 	uint64_t val;
-	val = lrand48();
+	val = (uint64_t)lrand48();
 	val <<= 32;
-	val += lrand48();
+	val += (uint64_t)lrand48();
 	return val;
 }