tech@mandoc.bsd.lv
 help / color / mirror / Atom feed
* Re: mdocml: The st_size member of struct stat is off_t, which is signed, all
       [not found] ` <20150310214738.GA20964@britannica.bec.de>
@ 2015-03-11  1:10   ` Ingo Schwarze
  2015-03-11  1:18     ` Joerg Sonnenberger
  0 siblings, 1 reply; 3+ messages in thread
From: Ingo Schwarze @ 2015-03-11  1:10 UTC (permalink / raw)
  To: Joerg Sonnenberger; +Cc: tech

[ Moving this to tech@ ]

Hi Joerg,

Joerg Sonnenberger wrote on Tue, Mar 10, 2015 at 10:47:38PM +0100:
> On Tue, Mar 10, 2015 at 09:18:22AM -0500, schwarze@mdocml.bsd.lv wrote:

>> Log Message:
>> -----------
>> The st_size member of struct stat is off_t, which is signed,
>> all required by POSIX.  So don't compare it against against 
>> an unsigned constant.

> Well, the change truncates the value.

How so?  The actual width of size_t will hardly be narrower
than the width of off_t on any sane platform, or am i mistaken?

The values of off_t are positive, so the range of size_t
completely covers the range of off_t that can occur.

> Wouldn't it make more sense to use just use 0x7fffffff
> as constant instead? I think POSIX ensures that int is 32bit.

That seems completely equivalent to me, but maybe i'm missing
something?

Arguably, a comparison to 0x7fffffff is easier to understand
than a cast plus a comparison to (1 << 31), though - hmm...

Yours,
  Ingo
--
 To unsubscribe send an email to tech+unsubscribe@mdocml.bsd.lv

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

* Re: mdocml: The st_size member of struct stat is off_t, which is signed, all
  2015-03-11  1:10   ` mdocml: The st_size member of struct stat is off_t, which is signed, all Ingo Schwarze
@ 2015-03-11  1:18     ` Joerg Sonnenberger
  2015-03-11 13:30       ` Ingo Schwarze
  0 siblings, 1 reply; 3+ messages in thread
From: Joerg Sonnenberger @ 2015-03-11  1:18 UTC (permalink / raw)
  To: tech

On Wed, Mar 11, 2015 at 02:10:32AM +0100, Ingo Schwarze wrote:
> [ Moving this to tech@ ]
> 
> Hi Joerg,
> 
> Joerg Sonnenberger wrote on Tue, Mar 10, 2015 at 10:47:38PM +0100:
> > On Tue, Mar 10, 2015 at 09:18:22AM -0500, schwarze@mdocml.bsd.lv wrote:
> 
> >> Log Message:
> >> -----------
> >> The st_size member of struct stat is off_t, which is signed,
> >> all required by POSIX.  So don't compare it against against 
> >> an unsigned constant.
> 
> > Well, the change truncates the value.
> 
> How so?  The actual width of size_t will hardly be narrower
> than the width of off_t on any sane platform, or am i mistaken?

Most 32bit platforms are exactly like that. size_t will be 32bit, off_t
will be 64bit. So casting the off_t to size_t will rip out the higher
bits.

Joerg
--
 To unsubscribe send an email to tech+unsubscribe@mdocml.bsd.lv

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

* Re: mdocml: The st_size member of struct stat is off_t, which is signed, all
  2015-03-11  1:18     ` Joerg Sonnenberger
@ 2015-03-11 13:30       ` Ingo Schwarze
  0 siblings, 0 replies; 3+ messages in thread
From: Ingo Schwarze @ 2015-03-11 13:30 UTC (permalink / raw)
  To: Joerg Sonnenberger; +Cc: tech

Hi Joerg,

Joerg Sonnenberger wrote on Wed, Mar 11, 2015 at 02:18:01AM +0100:
> On Wed, Mar 11, 2015 at 02:10:32AM +0100, Ingo Schwarze wrote:
>> Joerg Sonnenberger wrote on Tue, Mar 10, 2015 at 10:47:38PM +0100:
>>> On Tue, Mar 10, 2015 at 09:18:22AM -0500, schwarze@mdocml.bsd.lv wrote:

>>>> Log Message:
>>>> -----------
>>>> The st_size member of struct stat is off_t, which is signed,
>>>> all required by POSIX.  So don't compare it against against 
>>>> an unsigned constant.

>>> Well, the change truncates the value.

>> How so?  The actual width of size_t will hardly be narrower
>> than the width of off_t on any sane platform, or am i mistaken?

> Most 32bit platforms are exactly like that. size_t will be 32bit, off_t
> will be 64bit. So casting the off_t to size_t will rip out the higher
> bits.

Indeed, i misread header files.

So i changed the line in the way you proposed.

Thanks for the cluestick!
  Ingo
--
 To unsubscribe send an email to tech+unsubscribe@mdocml.bsd.lv

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

end of thread, other threads:[~2015-03-11 13:30 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <1281237932347383369.enqueue@fantadrom.bsd.lv>
     [not found] ` <20150310214738.GA20964@britannica.bec.de>
2015-03-11  1:10   ` mdocml: The st_size member of struct stat is off_t, which is signed, all Ingo Schwarze
2015-03-11  1:18     ` Joerg Sonnenberger
2015-03-11 13:30       ` Ingo Schwarze

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 NNTP newsgroup(s).