[PATCH] Fixes divelogs.de upload error #483

Venkatesh Shukla venkatesh.shukla.eee11 at iitbhu.ac.in
Sat Apr 5 08:59:34 PDT 2014


On Sat, Apr 5, 2014 at 9:03 PM, Linus Torvalds <
torvalds at linux-foundation.org> wrote:

>
> On Apr 5, 2014 1:45 AM, "Venkatesh Shukla" <
> venkatesh.shukla.eee11 at iitbhu.ac.in> wrote:
> >
> > Arguments 2 and 3 in fread() seemed to be exchanged because of which
> > only one character was read into the temp xml file.
>
> This explanation confused me, because the order of arguments ends up being
> totally immaterial to the number of characters read by fread().
>
> So the commit message is misleading.
>
> The reason the patch matters is not because it changes the amount if data
> read, but because it changes the return value. The fread function returns
> the number of elements read, not the number of bytes.
>
> So if the difference is that with the
>
>    streamsize, 1
>
> order, the return value ends up begin 1 for the "I read everything" case.
> And for the
>
>   1,  streamsize
>
> case it ends up returning 'streamsize'. Because in the first case it read
> *one* element of size 'streamsize' and in the second case it read
> 'streamsize' elements of a single char each.
>
> I personally think the fread/fwrite interfaces are stupid and much too
> easy to get wrong, but whatever. They are what they are.
>
> BTW, I don't think 'sizeof(char)' makes any sense. In C, that is just a
> complex way to write 1.  It doesn't matter how many bits 'char' has, sizeof
> is always in terms of char. That's the definition of sizeof.
>
> So if you were to have a machine with a sixteen bit char, and a 32-bit
> 'int' then sizeof(char) is still one, and sizeof(int) would be two.
>
>             Linus
>
Thank you Linus

I was ignorant of the above two facts. I'll keep them in mind.
I have attached the updated patch which includes correct explanation of
error.

Regards.
-- 

*Venkatesh Shukla *
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.hohndel.org/pipermail/subsurface/attachments/20140405/fc76642b/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0001-Fixes-divelogs.de-upload-error-483.patch
Type: text/x-patch
Size: 1311 bytes
Desc: not available
URL: <http://lists.hohndel.org/pipermail/subsurface/attachments/20140405/fc76642b/attachment.bin>


More information about the subsurface mailing list