[PATCH] Fixes divelogs.de upload error #483

Linus Torvalds torvalds at linux-foundation.org
Sat Apr 5 08:33:21 PDT 2014

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.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.hohndel.org/pipermail/subsurface/attachments/20140405/e872b941/attachment.html>

More information about the subsurface mailing list