From: Josh Triplett <josh@freedesktop.org>
To: Damien Lespiau <damien.lespiau@gmail.com>
Cc: linux-sparse@vger.kernel.org
Subject: Re: [PATCH] Fix compilation warning on 64 bits platforms
Date: Sun, 20 May 2007 17:28:37 -0700 [thread overview]
Message-ID: <4650E7B5.4030207@freedesktop.org> (raw)
In-Reply-To: <11797058752907-git-send-email-damien.lespiau@gmail.com>
[-- Attachment #1: Type: text/plain, Size: 1244 bytes --]
Damien Lespiau wrote:
> Fix: format '%d' expects type 'int', but argument 2 has type 'long int'
[...]
> @@ -461,7 +461,7 @@ const char *show_instruction(struct instruction *insn)
> }
>
> if (buf >= buffer + sizeof(buffer))
> - die("instruction buffer overflowed %d\n", buf - buffer);
> + die("instruction buffer overflowed %d\n", (int)(buf - buffer));
A cast doesn't seem like the right fix. The difference between two pointers
has type ptrdiff_t. sizeof(ptrdiff_t) == 8 on 64-bit platforms, leading to
the legitimate warning you saw. This cast would truncate the difference to 32
bits. glibc supplies a "t" length modifier for ptrdiff_t, but I don't think
sparse can't portably use that. I don't think we can portably use %llu
either, even though we use long long. On the other hand, sparse already seems
to use %llu.
Obviously 32-bit overflow seems unlikely here, but I don't like using a cast
to shut GCC up when it has a legitimate complaint; I'd prefer to have the
right fix.
The ideal fix, so we don't have to worry about printf format-string
portability: change this function to cleanly *prevent* instruction buffer
overflows rather than detecting them after the fact. :)
- Josh Triplett
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 252 bytes --]
next prev parent reply other threads:[~2007-05-21 0:28 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-05-21 0:04 [PATCH] Fix compilation warning on 64 bits platforms Damien Lespiau
2007-05-21 0:28 ` Josh Triplett [this message]
2007-05-21 0:33 ` Al Viro
2007-05-21 0:36 ` Josh Triplett
2007-05-22 18:06 ` Damien Lespiau
2007-05-22 21:20 ` Josh Triplett
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=4650E7B5.4030207@freedesktop.org \
--to=josh@freedesktop.org \
--cc=damien.lespiau@gmail.com \
--cc=linux-sparse@vger.kernel.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.