git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
* [PATCH 1/4] git-compat-util.h: xsize_t() - avoid -Wsign-compare warnings
@ 2017-09-21 16:46 Ramsay Jones
  2017-09-21 18:49 ` Torsten Bögershausen
  0 siblings, 1 reply; 4+ messages in thread
From: Ramsay Jones @ 2017-09-21 16:46 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: Jeff King, GIT Mailing-list


Signed-off-by: Ramsay Jones <ramsay@ramsayjones.plus.com>
---
 git-compat-util.h | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/git-compat-util.h b/git-compat-util.h
index 9bc15b036..cedad4d58 100644
--- a/git-compat-util.h
+++ b/git-compat-util.h
@@ -898,9 +898,11 @@ static inline char *xstrdup_or_null(const char *str)
 
 static inline size_t xsize_t(off_t len)
 {
-	if (len > (size_t) len)
+	size_t size = (size_t) len;
+
+	if (len != (off_t) size)
 		die("Cannot handle files this big");
-	return (size_t)len;
+	return size;
 }
 
 __attribute__((format (printf, 3, 4)))
-- 
2.14.0

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH 1/4] git-compat-util.h: xsize_t() - avoid -Wsign-compare warnings
  2017-09-21 16:46 [PATCH 1/4] git-compat-util.h: xsize_t() - avoid -Wsign-compare warnings Ramsay Jones
@ 2017-09-21 18:49 ` Torsten Bögershausen
  2017-09-21 18:57   ` Stefan Beller
  2017-09-21 19:02   ` Ramsay Jones
  0 siblings, 2 replies; 4+ messages in thread
From: Torsten Bögershausen @ 2017-09-21 18:49 UTC (permalink / raw)
  To: Ramsay Jones, Junio C Hamano; +Cc: Jeff King, GIT Mailing-list

On 2017-09-21 18:46, Ramsay Jones wrote:
> 
> Signed-off-by: Ramsay Jones <ramsay@ramsayjones.plus.com>
> ---
>  git-compat-util.h | 6 ++++--
>  1 file changed, 4 insertions(+), 2 deletions(-)
> 
> diff --git a/git-compat-util.h b/git-compat-util.h
> index 9bc15b036..cedad4d58 100644
> --- a/git-compat-util.h
> +++ b/git-compat-util.h
> @@ -898,9 +898,11 @@ static inline char *xstrdup_or_null(const char *str)
>  
>  static inline size_t xsize_t(off_t len)
>  {
> -	if (len > (size_t) len)
> +	size_t size = (size_t) len;
> +
> +	if (len != (off_t) size)
>  		die("Cannot handle files this big");
> -	return (size_t)len;
> +	return size;

Hm, can someone help me out ?
Why is the cast not needed ?

>  }
>  
>  __attribute__((format (printf, 3, 4)))
> 


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH 1/4] git-compat-util.h: xsize_t() - avoid -Wsign-compare warnings
  2017-09-21 18:49 ` Torsten Bögershausen
@ 2017-09-21 18:57   ` Stefan Beller
  2017-09-21 19:02   ` Ramsay Jones
  1 sibling, 0 replies; 4+ messages in thread
From: Stefan Beller @ 2017-09-21 18:57 UTC (permalink / raw)
  To: Torsten Bögershausen
  Cc: Ramsay Jones, Junio C Hamano, Jeff King, GIT Mailing-list

On Thu, Sep 21, 2017 at 11:49 AM, Torsten Bögershausen <tboegi@web.de> wrote:
> On 2017-09-21 18:46, Ramsay Jones wrote:
>>
>> Signed-off-by: Ramsay Jones <ramsay@ramsayjones.plus.com>
>> ---
>>  git-compat-util.h | 6 ++++--
>>  1 file changed, 4 insertions(+), 2 deletions(-)
>>
>> diff --git a/git-compat-util.h b/git-compat-util.h
>> index 9bc15b036..cedad4d58 100644
>> --- a/git-compat-util.h
>> +++ b/git-compat-util.h
>> @@ -898,9 +898,11 @@ static inline char *xstrdup_or_null(const char *str)
>>
>>  static inline size_t xsize_t(off_t len)
>>  {
>> -     if (len > (size_t) len)
>> +     size_t size = (size_t) len;
>> +
>> +     if (len != (off_t) size)
>>               die("Cannot handle files this big");
>> -     return (size_t)len;
>> +     return size;
>
> Hm, can someone help me out ?
> Why is the cast not needed ?

Because 'size' is already size_t,
(cast was done in first line of the function:
    size_t size = (size_t) len;
), previously we cast len multiple times,
now we cast it once and use size thereafter.

>
>>  }
>>
>>  __attribute__((format (printf, 3, 4)))
>>
>

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH 1/4] git-compat-util.h: xsize_t() - avoid -Wsign-compare warnings
  2017-09-21 18:49 ` Torsten Bögershausen
  2017-09-21 18:57   ` Stefan Beller
@ 2017-09-21 19:02   ` Ramsay Jones
  1 sibling, 0 replies; 4+ messages in thread
From: Ramsay Jones @ 2017-09-21 19:02 UTC (permalink / raw)
  To: Torsten Bögershausen, Junio C Hamano; +Cc: Jeff King, GIT Mailing-list



On 21/09/17 19:49, Torsten Bögershausen wrote:
> On 2017-09-21 18:46, Ramsay Jones wrote:
>>
>> Signed-off-by: Ramsay Jones <ramsay@ramsayjones.plus.com>
>> ---
>>  git-compat-util.h | 6 ++++--
>>  1 file changed, 4 insertions(+), 2 deletions(-)
>>
>> diff --git a/git-compat-util.h b/git-compat-util.h
>> index 9bc15b036..cedad4d58 100644
>> --- a/git-compat-util.h
>> +++ b/git-compat-util.h
>> @@ -898,9 +898,11 @@ static inline char *xstrdup_or_null(const char *str)
>>  
>>  static inline size_t xsize_t(off_t len)
>>  {
>> -	if (len > (size_t) len)
>> +	size_t size = (size_t) len;
>> +
>> +	if (len != (off_t) size)
>>  		die("Cannot handle files this big");
>> -	return (size_t)len;
>> +	return size;
> 
> Hm, can someone help me out ?
> Why is the cast not needed ?

The cast in the return statement? If so, because the 'size' variable
has been declared with the size_t type. (The truncation, if any, would
happen when 'size' is initialised in the declaration).

Hope that helps.

ATB,
Ramsay Jones



^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2017-09-21 19:02 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-09-21 16:46 [PATCH 1/4] git-compat-util.h: xsize_t() - avoid -Wsign-compare warnings Ramsay Jones
2017-09-21 18:49 ` Torsten Bögershausen
2017-09-21 18:57   ` Stefan Beller
2017-09-21 19:02   ` Ramsay Jones

Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).