qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: "M. Warner Losh" <imp@bsdimp.com>
To: qemu-devel@nongnu.org, paul@codesourcery.com
Subject: Re: [Qemu-devel] [PATCH] support >2TB SCSI disks
Date: Wed, 28 Jan 2009 09:28:42 -0700 (MST)	[thread overview]
Message-ID: <20090128.092842.-1889956563.imp@bsdimp.com> (raw)
In-Reply-To: <200901281230.29455.paul@codesourcery.com>

In message: <200901281230.29455.paul@codesourcery.com>
            Paul Brook <paul@codesourcery.com> writes:
: >      case 0:
: > -        lba = buf[3] | (buf[2] << 8) | ((buf[1] & 0x1f) << 16);
: > +        lba = (uint64_t) buf[3] | ((uint64_t) buf[2] << 8) |
: > +              (((uint64_t) buf[1] & 0x1f) << 16);
: 
: This is not required, though I guess it's harmless.

Actually, I think it is required.  ANSI-C promotion rules say that a
char or unsigned char is promoted to an int when used in an
expression.  This causes the result to be a 32-bit number which is
sign-extended to a 64-bit number before being assigned to lba.

I've hit this "bug" in C before many times, and the patch specifically
called it out as a problem.

Warner

  parent reply	other threads:[~2009-01-28 16:30 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-01-28  3:46 [Qemu-devel] [PATCH] support >2TB SCSI disks Rik van Riel
2009-01-28 12:30 ` Paul Brook
2009-01-28 14:13   ` Rik van Riel
2009-01-28 16:28   ` M. Warner Losh [this message]
2009-01-29 15:04     ` Paul Brook

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20090128.092842.-1889956563.imp@bsdimp.com \
    --to=imp@bsdimp.com \
    --cc=paul@codesourcery.com \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).