mailing list of musl libc
 help / color / mirror / code / Atom feed
* Use of size_t and ssize_t in mseek
@ 2013-06-27  3:52 Matthew Fernandez
  2013-06-27  4:10 ` Rich Felker
  0 siblings, 1 reply; 32+ messages in thread
From: Matthew Fernandez @ 2013-06-27  3:52 UTC (permalink / raw)
  To: musl

Hi all,

My question refers to the latest git commit at time of writing,
b17c75a4d539d7ec5b81cc7ce7ce6b065a87e7a6. My issue was encountered on
ARM, but it applies to most 32-bit platforms.

The function mseek() accesses a size_t variable, c->size, and casts this
to a ssize_t. I know there aren't strong standards on what to expect
from ssize_t, but the Musl C constants SIZE_MAX (== UINT32_MAX) and
SSIZE_MAX (== LONG_MAX) seem to imply that you would be wise to assume
ssize_t is signed and the same width as size_t.

As a result, the cast I mentioned produces some unexpected results when
operating on a file of size greater than SSIZE_MAX. In my case I had an
in-memory file of size SIZE_MAX and was surprised to find I couldn't
fseek this file.

Is the code in mseek() correct? If so, I would recommend failing
fmemopen() when the requested size is greater than SSIZE_MAX. OTOH
perhaps I'm misunderstanding something more subtle here. If so, please
correct me.

Thanks,
Matthew

[It is perhaps worth noting that, yes, a UINT32_MAX-sized in-memory file
on a 32-bit platform is a bit odd. In my case I don't know how big the
file is until I've read its header. You could object that this is
unwise, but either way I believe fmemopen/mseek should handle this case.]

________________________________

The information in this e-mail may be confidential and subject to legal professional privilege and/or copyright. National ICT Australia Limited accepts no liability for any damage caused by this email or its attachments.


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

end of thread, other threads:[~2013-07-04 15:26 UTC | newest]

Thread overview: 32+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-06-27  3:52 Use of size_t and ssize_t in mseek Matthew Fernandez
2013-06-27  4:10 ` Rich Felker
2013-06-27  4:16   ` Matthew Fernandez
2013-06-27  4:23     ` Rich Felker
2013-06-27  4:31       ` Matthew Fernandez
2013-06-27 15:34         ` Rich Felker
2013-06-28  0:49           ` Matthew Fernandez
2013-06-28  1:22             ` Rich Felker
2013-06-28  1:34               ` Matthew Fernandez
2013-06-28  1:48                 ` Rich Felker
2013-06-28  1:56                   ` Matthew Fernandez
2013-06-29  4:13                     ` Rich Felker
2013-06-29 13:38                       ` Matthew Fernandez
2013-06-29 14:17                         ` Rich Felker
2013-06-29 14:56                           ` Jens Gustedt
2013-06-29 15:48                             ` Rich Felker
2013-06-29 16:01                               ` Jens Gustedt
2013-06-29 16:13                                 ` Rich Felker
2013-06-29 16:39                                   ` Jens Gustedt
2013-07-04  1:28                                     ` Rich Felker
2013-07-04  6:11                                       ` Jens Gustedt
2013-07-04  6:37                                         ` Rich Felker
2013-07-04  7:11                                           ` Jens Gustedt
2013-07-04  8:12                                             ` Rich Felker
2013-07-04  8:45                                               ` Jens Gustedt
2013-07-04 15:24                                                 ` Rich Felker
2013-07-04 11:10                                               ` Szabolcs Nagy
2013-07-04 11:58                                                 ` Jens Gustedt
2013-07-04 15:26                                                 ` Rich Felker
2013-06-27 10:35       ` Szabolcs Nagy
2013-06-27 15:05         ` Rich Felker
2013-06-27 16:47       ` Rich Felker

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/musl/

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