On Sun, 13 Nov 2011 m...@freebsd.org wrote:
On Sun, Nov 13, 2011 at 2:46 PM, Garrett Cooper <yaneg...@gmail.com> wrote:
On Sun, Nov 13, 2011 at 2:08 PM, Pawel Jakub Dawidek <p...@freebsd.org> wrote:
On Sat, Nov 12, 2011 at 12:16:23PM -0800, Garrett Cooper wrote:
On Sat, Nov 12, 2011 at 12:01 PM, Alexander Motin <m...@freebsd.org> wrote:
Author: mav
Date: Sat Nov 12 20:01:30 2011
New Revision: 227473
URL: http://svn.freebsd.org/changeset/base/227473
Log:
?Fix build on some archs after r227464.
Modified:
?head/sbin/geom/class/multipath/geom_multipath.c
Modified: head/sbin/geom/class/multipath/geom_multipath.c
==============================================================================
--- head/sbin/geom/class/multipath/geom_multipath.c ? ? Sat Nov 12 19:55:48
2011 ? ? ? ?(r227472)
+++ head/sbin/geom/class/multipath/geom_multipath.c ? ? Sat Nov 12 20:01:30
2011 ? ? ? ?(r227473)
@@ -133,7 +133,8 @@ mp_label(struct gctl_req *req)
? ? ? ?uint8_t *sector, *rsector;
? ? ? ?char *ptr;
? ? ? ?uuid_t uuid;
- ? ? ? uint32_t secsize = 0, ssize, status;
+ ? ? ? ssize_t secsize = 0, ssize;
+ ? ? ? uint32_t status;
? ? ? ?const char *name, *name2, *mpname;
? ? ? ?int error, i, nargs, fd;
@@ -161,8 +162,8 @@ mp_label(struct gctl_req *req)
? ? ? ? ? ? ? ? ? ? ? ?disksize = msize;
? ? ? ? ? ? ? ?} else {
? ? ? ? ? ? ? ? ? ? ? ?if (secsize != ssize) {
- ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? gctl_error(req, "%s sector size %u different.",
- ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? name, ssize);
+ ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? gctl_error(req, "%s sector size %ju different.",
+ ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? name, (intmax_t)ssize);
Shouldn't that be uintmax_t, not intmax_t ?
No, ssize_t is signed. Although the best would be to use %zd for
ssize_t.
Thanks... Missed the leading s.
... except that the cast and conversion specifier aren't in sync. The
cast is signed; the conversion specifier is unsigned. %zd is still
best, since it's the conversion specifier for the variable's type.
Next best is %jd and cast to intmax_t, since the signedness is
preserved.
But ssize_t is still a nonsense type for representing a sector size.
ssize_t is for the return type of read(2) and write(2) and not much
more. On 64-bit arches it is (bogusly) int64_t, although read() and
write() are still limited to INT_MAX for historical reasons (buggy
standards may require ssize_t to have this wrong type and SSIZE_MAX
to have the corresponding wrong value INT64_MAX (equal to the maximum
value representable by this wrong type and not equal to the maximum
value that read() and write() actually support). These bugs were
missing in V7 where read() and write() took and returned plain int
sizes. Portable code must still call them with a size <= INT_MAX,
else it may break, for example on FreeBSD.
When ssize_t is misused for something unrelated to read() and write(),
it mainly gives printf format complications since it tends to be larger
than necessary. Here it gives a printf format complication of a cast
to intmax_t, and a printf format error since intmax_t doesn't match
the format %ju, and it gives the nonsense that sectors of size >= 2GB
are "supported" on 64-bit systems but not on 32-bit systems. Testing
this support is difficult even with virtual disks.
But in the end it doesn't matter a lot since whatever is printed in
the error message, it's likely derivable from reading the code what
the actual value used was.
Even when the value is truncated, provided the behaviour is defined or
benign.
Bruce
_______________________________________________
svn-src-head@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"