[dpdk-dev,v3,40/40] rte_string_fns.h: explicit cast for int return to size_t

Message ID 152592058043.119328.8002624265714725703.stgit@localhost.localdomain (mailing list archive)
State Superseded, archived
Headers

Checks

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

Commit Message

Andy Green May 10, 2018, 2:49 a.m. UTC
  Signed-off-by: Andy Green <andy@warmcat.com>
---
 lib/librte_eal/common/include/rte_string_fns.h |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
  

Comments

Stephen Hemminger May 10, 2018, 7:17 p.m. UTC | #1
On Thu, 10 May 2018 10:49:40 +0800
Andy Green <andy@warmcat.com> wrote:

> Signed-off-by: Andy Green <andy@warmcat.com>
> ---
>  lib/librte_eal/common/include/rte_string_fns.h |    2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/lib/librte_eal/common/include/rte_string_fns.h b/lib/librte_eal/common/include/rte_string_fns.h
> index fcbb42e00..51413a55e 100644
> --- a/lib/librte_eal/common/include/rte_string_fns.h
> +++ b/lib/librte_eal/common/include/rte_string_fns.h
> @@ -55,7 +55,7 @@ rte_strsplit(char *string, int stringlen,
>  static inline size_t
>  rte_strlcpy(char *dst, const char *src, size_t size)
>  {
> -	return snprintf(dst, size, "%s", src);
> +	return (size_t)(unsigned int)snprintf(dst, size, "%s", src);
>  }
>  
>  /* pull in a strlcpy function */
> 

I would rather see a proper version of strlcpy extracted from libbsd
  
Andy Green May 11, 2018, 12:13 a.m. UTC | #2
On 05/11/2018 03:17 AM, Stephen Hemminger wrote:
> On Thu, 10 May 2018 10:49:40 +0800
> Andy Green <andy@warmcat.com> wrote:
> 
>> Signed-off-by: Andy Green <andy@warmcat.com>
>> ---
>>   lib/librte_eal/common/include/rte_string_fns.h |    2 +-
>>   1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/lib/librte_eal/common/include/rte_string_fns.h b/lib/librte_eal/common/include/rte_string_fns.h
>> index fcbb42e00..51413a55e 100644
>> --- a/lib/librte_eal/common/include/rte_string_fns.h
>> +++ b/lib/librte_eal/common/include/rte_string_fns.h
>> @@ -55,7 +55,7 @@ rte_strsplit(char *string, int stringlen,
>>   static inline size_t
>>   rte_strlcpy(char *dst, const char *src, size_t size)
>>   {
>> -	return snprintf(dst, size, "%s", src);
>> +	return (size_t)(unsigned int)snprintf(dst, size, "%s", src);
>>   }
>>   
>>   /* pull in a strlcpy function */
>>
> 
> I would rather see a proper version of strlcpy extracted from libbsd

I also have done this and will push later.  It's not inline any more.

-Andy
  

Patch

diff --git a/lib/librte_eal/common/include/rte_string_fns.h b/lib/librte_eal/common/include/rte_string_fns.h
index fcbb42e00..51413a55e 100644
--- a/lib/librte_eal/common/include/rte_string_fns.h
+++ b/lib/librte_eal/common/include/rte_string_fns.h
@@ -55,7 +55,7 @@  rte_strsplit(char *string, int stringlen,
 static inline size_t
 rte_strlcpy(char *dst, const char *src, size_t size)
 {
-	return snprintf(dst, size, "%s", src);
+	return (size_t)(unsigned int)snprintf(dst, size, "%s", src);
 }
 
 /* pull in a strlcpy function */