Re: SOLUTION (Re: Style question: comparison between signed and unsigned?)

Harald Koenig (koenig@tat.physik.uni-tuebingen.de)
Fri, 26 Sep 1997 14:09:25 +0200


On Sep 26, Morten Welinder wrote:

> A modest proposal. If the code in question is
>
> int i = read(socket, buffer, sizeof(buffer));
> /* check for errors */
> if (i == -1)
> return i;
> /* check that we got a valid packet */
> if (i < sizeof(struct pkthdr))
> return SHORT_PACKET;
>
> then why don't we simply turn that "<" into "!="? I have the feeling

this is not the same! what happens if read() returns only 512 bytes
instead of 10240 or similar ?!

> that a lot of the sizeof-based problems/non-problems (depending on
> your point of view) will then disappear.
>
> (A function like read isn't supposed to return a count larger than
> the buffer size. If it does, we are in deep s. anyway.)

but it is supposed to return less than buffer size (but more then zero bytes)...

Harald

--
All SCSI disks will from now on                     ___       _____
be required to send an email notice                0--,|    /OOOOOOO\
24 hours prior to complete hardware failure!      <_/  /  /OOOOOOOOOOO\
                                                    \  \/OOOOOOOOOOOOOOO\
                                                      \ OOOOOOOOOOOOOOOOO|//
Harald Koenig,                                         \/\/\/\/\/\/\/\/\/
Inst.f.Theoret.Astrophysik                              //  /     \\  \
koenig@tat.physik.uni-tuebingen.de                     ^^^^^       ^^^^^