Message ID | 7a3acf1b-ff2b-e298-bf4e-9e20f1974965@redhat.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
On 16 June 2016 at 17:29, Paolo Bonzini <pbonzini@redhat.com> wrote: > On 16/06/2016 18:02, Peter Maydell wrote: >> Hi. I'm afraid this generates format string warnings on OSX: > > Interesting, I did test clang this time. I'll fix it but really this > is a compiler bug. It's *impossible* to pass a short variable > argument, hence va_arg(ap, short) *must* be the same as va_arg(ap, int). This one's an OSX/Apple special -- it isn't part of the stock clang. (It has its good points -- this is the only 64-bit platform that will warn about format string issues that will break compile on 32-bit hosts.) I guess the point of the warning in this particular case is to say "you passed something that could be wider than a short but you used a format specifier which is for a short/unsigned short" (ie your format might be unintentionally dropping the top 16 bits of the data). thanks -- PMM
On 16/06/2016 18:55, Peter Maydell wrote: >> > Interesting, I did test clang this time. I'll fix it but really this >> > is a compiler bug. It's *impossible* to pass a short variable >> > argument, hence va_arg(ap, short) *must* be the same as va_arg(ap, int). > This one's an OSX/Apple special -- it isn't part of the stock clang. > (It has its good points -- this is the only 64-bit platform that > will warn about format string issues that will break compile on > 32-bit hosts.) > > I guess the point of the warning in this particular case is to > say "you passed something that could be wider than a short but > you used a format specifier which is for a short/unsigned short" > (ie your format might be unintentionally dropping the top 16 bits > of the data). Does it fire even of void f(unsigned short x) { printf ("%hx", x | 1); } ? Because technically that's an int too (and that's why I think this particular warning is not a great thing)... Paolo
On 16 June 2016 at 18:01, Paolo Bonzini <pbonzini@redhat.com> wrote: > Does it fire even of > > void f(unsigned short x) > { > printf ("%hx", x | 1); > } > > ? > > Because technically that's an int too (and that's why I think this > particular warning is not a great thing)... Yes, it does. If you want to shut it up then you can do (unsigned short)(x | 1). -- PMM
diff --git a/nbd/server.c b/nbd/server.c index ba950973..a677e26 100644 --- a/nbd/server.c +++ b/nbd/server.c @@ -576,7 +576,7 @@ static coroutine_fn int nbd_negotiate(NBDClientNewData *data) oldStyle = client->exp != NULL && !client->tlscreds; if (oldStyle) { assert ((client->exp->nbdflags & ~65535) == 0); - TRACE("advertising size %" PRIu64 " and flags %" PRIx16, + TRACE("advertising size %" PRIu64 " and flags %x", client->exp->size, client->exp->nbdflags | myflags); stq_be_p(buf + 8, NBD_CLIENT_MAGIC); stq_be_p(buf + 16, client->exp->size); @@ -607,7 +607,7 @@ static coroutine_fn int nbd_negotiate(NBDClientNewData *data) } assert ((client->exp->nbdflags & ~65535) == 0); - TRACE("advertising size %" PRIu64 " and flags %" PRIx16, + TRACE("advertising size %" PRIu64 " and flags %x", client->exp->size, client->exp->nbdflags | myflags); stq_be_p(buf + 18, client->exp->size); stw_be_p(buf + 26, client->exp->nbdflags | myflags);