git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
* [PATCH] read_cache: cast types from stat to ce_cache
@ 2010-06-10  9:15 Michael J Gruber
  2010-06-10 15:54 ` Junio C Hamano
  0 siblings, 1 reply; 5+ messages in thread
From: Michael J Gruber @ 2010-06-10  9:15 UTC (permalink / raw)
  To: git; +Cc: Junio C Hamano

Cast the system dependent entries of struct stat to unsigned integers
for struct ce_cache just like in other places where we do this already,
to protect against any type conversion issues.

Signed-off-by: Michael J Gruber <git@drmicha.warpmail.net>
---
This does not fix the "filesystem boundary issue" I reported, but I spotted
this when digging through read-cache.c. My device ids would have issues
when int = short.

 read-cache.c |   10 +++++-----
 1 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/read-cache.c b/read-cache.c
index e381ea5..aa9b847 100644
--- a/read-cache.c
+++ b/read-cache.c
@@ -72,11 +72,11 @@ void fill_stat_cache_info(struct cache_entry *ce, struct stat *st)
 	ce->ce_mtime.sec = (unsigned int)st->st_mtime;
 	ce->ce_ctime.nsec = ST_CTIME_NSEC(*st);
 	ce->ce_mtime.nsec = ST_MTIME_NSEC(*st);
-	ce->ce_dev = st->st_dev;
-	ce->ce_ino = st->st_ino;
-	ce->ce_uid = st->st_uid;
-	ce->ce_gid = st->st_gid;
-	ce->ce_size = st->st_size;
+	ce->ce_dev = (unsigned int)st->st_dev;
+	ce->ce_ino = (unsigned int)st->st_ino;
+	ce->ce_uid = (unsigned int)st->st_uid;
+	ce->ce_gid = (unsigned int)st->st_gid;
+	ce->ce_size = (unsigned int)st->st_size;
 
 	if (assume_unchanged)
 		ce->ce_flags |= CE_VALID;
-- 
1.7.1.501.g23b46

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

* Re: [PATCH] read_cache: cast types from stat to ce_cache
  2010-06-10  9:15 [PATCH] read_cache: cast types from stat to ce_cache Michael J Gruber
@ 2010-06-10 15:54 ` Junio C Hamano
  2010-06-11 13:32   ` Michael J Gruber
  0 siblings, 1 reply; 5+ messages in thread
From: Junio C Hamano @ 2010-06-10 15:54 UTC (permalink / raw)
  To: Michael J Gruber; +Cc: git

Michael J Gruber <git@drmicha.warpmail.net> writes:

> -	ce->ce_dev = st->st_dev;
> -	ce->ce_ino = st->st_ino;
> -	ce->ce_uid = st->st_uid;
> -	ce->ce_gid = st->st_gid;
> -	ce->ce_size = st->st_size;
> +	ce->ce_dev = (unsigned int)st->st_dev;
> +	ce->ce_ino = (unsigned int)st->st_ino;
> +	ce->ce_uid = (unsigned int)st->st_uid;
> +	ce->ce_gid = (unsigned int)st->st_gid;
> +	ce->ce_size = (unsigned int)st->st_size;

I haven't had my morning coffee yet, but wouldn't the conversion be
automatic by assignment anyway?

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

* Re: [PATCH] read_cache: cast types from stat to ce_cache
  2010-06-10 15:54 ` Junio C Hamano
@ 2010-06-11 13:32   ` Michael J Gruber
  2010-06-11 14:15     ` Erik Faye-Lund
  0 siblings, 1 reply; 5+ messages in thread
From: Michael J Gruber @ 2010-06-11 13:32 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: git

Junio C Hamano venit, vidit, dixit 10.06.2010 17:54:
> Michael J Gruber <git@drmicha.warpmail.net> writes:
> 
>> -	ce->ce_dev = st->st_dev;
>> -	ce->ce_ino = st->st_ino;
>> -	ce->ce_uid = st->st_uid;
>> -	ce->ce_gid = st->st_gid;
>> -	ce->ce_size = st->st_size;
>> +	ce->ce_dev = (unsigned int)st->st_dev;
>> +	ce->ce_ino = (unsigned int)st->st_ino;
>> +	ce->ce_uid = (unsigned int)st->st_uid;
>> +	ce->ce_gid = (unsigned int)st->st_gid;
>> +	ce->ce_size = (unsigned int)st->st_size;
> 
> I haven't had my morning coffee yet, but wouldn't the conversion be
> automatic by assignment anyway?

Well, we do cast from dev_t etc. to unsigned int in all other places in
read_cache.c.

In any case, enjoy your coffee :)

Michael

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

* Re: [PATCH] read_cache: cast types from stat to ce_cache
  2010-06-11 13:32   ` Michael J Gruber
@ 2010-06-11 14:15     ` Erik Faye-Lund
  2010-06-11 14:59       ` Michael J Gruber
  0 siblings, 1 reply; 5+ messages in thread
From: Erik Faye-Lund @ 2010-06-11 14:15 UTC (permalink / raw)
  To: Michael J Gruber; +Cc: Junio C Hamano, Git Mailing List

On Fri, Jun 11, 2010 at 3:32 PM, Michael J Gruber
<git@drmicha.warpmail.net> wrote:
> Junio C Hamano venit, vidit, dixit 10.06.2010 17:54:
>> Michael J Gruber <git@drmicha.warpmail.net> writes:
>>
>>> -    ce->ce_dev = st->st_dev;
>>> -    ce->ce_ino = st->st_ino;
>>> -    ce->ce_uid = st->st_uid;
>>> -    ce->ce_gid = st->st_gid;
>>> -    ce->ce_size = st->st_size;
>>> +    ce->ce_dev = (unsigned int)st->st_dev;
>>> +    ce->ce_ino = (unsigned int)st->st_ino;
>>> +    ce->ce_uid = (unsigned int)st->st_uid;
>>> +    ce->ce_gid = (unsigned int)st->st_gid;
>>> +    ce->ce_size = (unsigned int)st->st_size;
>>
>> I haven't had my morning coffee yet, but wouldn't the conversion be
>> automatic by assignment anyway?
>
> Well, we do cast from dev_t etc. to unsigned int in all other places in
> read_cache.c.
>

The only cases where we cast anything to unsigned in on assignment in
read-cache.h is where we assign the second-part of the ce_ctime and
ce_mtime members:
	ce->ce_ctime.sec = (unsigned int)st->st_ctime;
	ce->ce_mtime.sec = (unsigned int)st->st_mtime;

These are indeed superfluous (as yours are) as far as I can tell.
There's also some casts on comparison, and I think they also are
superfluous. The current casts originate from commits fba2f38a,
5bcf109c, e1afca4f and 7a51ed66.

They don't do any harm though, so I don't think it makes much sense to
remove them.

-- 
Erik "kusma" Faye-Lund

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

* Re: [PATCH] read_cache: cast types from stat to ce_cache
  2010-06-11 14:15     ` Erik Faye-Lund
@ 2010-06-11 14:59       ` Michael J Gruber
  0 siblings, 0 replies; 5+ messages in thread
From: Michael J Gruber @ 2010-06-11 14:59 UTC (permalink / raw)
  To: kusmabite; +Cc: Erik Faye-Lund, Junio C Hamano, Git Mailing List

Erik Faye-Lund venit, vidit, dixit 11.06.2010 16:15:
> On Fri, Jun 11, 2010 at 3:32 PM, Michael J Gruber
> <git@drmicha.warpmail.net> wrote:
>> Junio C Hamano venit, vidit, dixit 10.06.2010 17:54:
>>> Michael J Gruber <git@drmicha.warpmail.net> writes:
>>>
>>>> -    ce->ce_dev = st->st_dev;
>>>> -    ce->ce_ino = st->st_ino;
>>>> -    ce->ce_uid = st->st_uid;
>>>> -    ce->ce_gid = st->st_gid;
>>>> -    ce->ce_size = st->st_size;
>>>> +    ce->ce_dev = (unsigned int)st->st_dev;
>>>> +    ce->ce_ino = (unsigned int)st->st_ino;
>>>> +    ce->ce_uid = (unsigned int)st->st_uid;
>>>> +    ce->ce_gid = (unsigned int)st->st_gid;
>>>> +    ce->ce_size = (unsigned int)st->st_size;
>>>
>>> I haven't had my morning coffee yet, but wouldn't the conversion be
>>> automatic by assignment anyway?
>>
>> Well, we do cast from dev_t etc. to unsigned int in all other places in
>> read_cache.c.
>>
> 
> The only cases where we cast anything to unsigned in on assignment in
> read-cache.h is where we assign the second-part of the ce_ctime and
> ce_mtime members:
> 	ce->ce_ctime.sec = (unsigned int)st->st_ctime;
> 	ce->ce_mtime.sec = (unsigned int)st->st_mtime;
> 
> These are indeed superfluous (as yours are) as far as I can tell.
> There's also some casts on comparison, and I think they also are
> superfluous. The current casts originate from commits fba2f38a,
> 5bcf109c, e1afca4f and 7a51ed66.
> 
> They don't do any harm though, so I don't think it makes much sense to
> remove them.
> 

OK, then we can leave them resp. leave them out until a compiler complains.

I just stumbled upon this "inconsistency" when hunting down that fs
boundary warning.

Michael

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

end of thread, other threads:[~2010-06-11 14:59 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-06-10  9:15 [PATCH] read_cache: cast types from stat to ce_cache Michael J Gruber
2010-06-10 15:54 ` Junio C Hamano
2010-06-11 13:32   ` Michael J Gruber
2010-06-11 14:15     ` Erik Faye-Lund
2010-06-11 14:59       ` Michael J Gruber

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).