qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: "M. Warner Losh" <imp@bsdimp.com>
To: qemu-devel@nongnu.org, andreas.faerber@web.de
Subject: Re: [Qemu-devel] [PATCH] ensure all invocations to bdrv_{read, write} use (uint8_t *) for its third parameter
Date: Fri, 04 Jan 2008 10:10:44 -0700 (MST)	[thread overview]
Message-ID: <20080104.101044.-861066132.imp@bsdimp.com> (raw)
In-Reply-To: <9C6EAA0B-8DBC-4871-AC1B-6E21B31E92FC@web.de>

In message: <9C6EAA0B-8DBC-4871-AC1B-6E21B31E92FC@web.de>
            Andreas_Färber <andreas.faerber@web.de> writes:
: 
: Am 04.01.2008 um 15:00 schrieb Samuel Thibault:
: 
: > Andreas Färber, le Fri 04 Jan 2008 14:41:29 +0100, a écrit :
: >>
: >> Am 04.01.2008 um 14:20 schrieb Thiemo Seufer:
: >>
: >>> Carlo Marcelo Arenas Belon wrote:
: >>>> Trivial fix that ensures that all buffers used for bdrv_read or
: >>>> bdrv_write
: >>>> are from an array of the uint8_t type
: >>>
: >>> Do we have a host where this actually makes a difference?
: >>
: >> I believe Perl makes sizeof(char) checks, so there likely is some
: >> platform where sizeof(char) > 1.
: >
: > The C standard says
: >
: > `When applied to an operand that has type char, unsigned char, or  
: > signed
: > char, (or a qualified version thereof) the result is 1.'
: 
: The standard maybe. But Win64 violates the C standards, too. ;)
: 
: According to our department's ANSI C course, the only consistent rule is
: sizeof(char) <= sizeof(short) <= sizeof(int) <= sizeof(long)
: without any concrete numbers.
: 
: I'm not saying it should be changed or not in QEMU, just saying it may  
: not be completely out-of-the-world.

The problem is that sizeof(char) has to be 1, or a number of things
will down right fail.  The following code will fail if it doesn't:

     char *a = "abc";
     char *b = malloc(strlen(a) + 1);
     strcpy(b, a);

If sizeof(char) is really 2, then sizeof("abc") is going to be 6, not
3 that strlen returns and the strcpy will smash into memory it doesn't
own.  And *NOBODY*, not even ignorant students, adds a '*
sizeof(char)' to the strlen.  Such a compiler would break just about
every program out there of any significant size.

Now, there's a wchar_t which is the type of the characters in a L
string: "abc"L can be 4, 8, 12, 16 or more bytes in size, but that's
different, and not what's being discussed.

Warner

  parent reply	other threads:[~2008-01-04 17:12 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-01-04  8:10 [Qemu-devel] [PATCH] ensure all invocations to bdrv_{read, write} use (uint8_t *) for its third parameter Carlo Marcelo Arenas Belon
2008-01-04 13:20 ` Thiemo Seufer
2008-01-04 13:41   ` Andreas Färber
2008-01-04 14:00     ` Samuel Thibault
2008-01-04 14:46       ` Andreas Färber
2008-01-04 16:14         ` Thiemo Seufer
2008-01-04 17:10         ` M. Warner Losh [this message]
2008-01-04 18:29     ` Andreas Schwab
2008-01-05  0:39     ` Rob Landley
2008-01-05  2:01   ` Carlo Marcelo Arenas Belon

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=20080104.101044.-861066132.imp@bsdimp.com \
    --to=imp@bsdimp.com \
    --cc=andreas.faerber@web.de \
    --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).