mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Frederic Weisbecker <fweisbec@gmail.com>
To: linux-tip-commits@vger.kernel.org
Cc: linux-kernel@vger.kernel.org, hpa@zytor.com, mingo@redhat.com,
	torvalds@linux-foundation.org, sitsofe@yahoo.com,
	fweisbec@gmail.com, rostedt@goodmis.org, tglx@linutronix.de,
	laijs@cn.fujitsu.com, mingo@elte.hu
Subject: [tip:core/printk] vsprintf: fix bug in negative value printing
Date: Tue, 10 Mar 2009 12:18:32 GMT	[thread overview]
Message-ID: <tip-39e874f8afbdb3745e2406ce4ecbde9ac4cbaa78@git.kernel.org> (raw)
In-Reply-To: <20090309201503.GA5010@nowhere>

Commit-ID:  39e874f8afbdb3745e2406ce4ecbde9ac4cbaa78
Gitweb:     http://git.kernel.org/tip/39e874f8afbdb3745e2406ce4ecbde9ac4cbaa78
Author:     "Frederic Weisbecker" <fweisbec@gmail.com>
AuthorDate: Mon, 9 Mar 2009 21:15:04 +0100
Commit:     Ingo Molnar <mingo@elte.hu>
CommitDate: Tue, 10 Mar 2009 13:15:06 +0100

vsprintf: fix bug in negative value printing

Sitsofe Wheeler found and bisected that while unifying the
vsprintf format decoding in:

  fef20d9: vsprintf: unify the format decoding layer for its 3 users

The sign flag has been dropped out in favour of
precise types (ie: LONG/ULONG).

But the format helper number() still needs this flag to keep track of
the signedness unless it will consider all numbers as unsigned.

Also add an explicit cast to int (for %d) while parsing with va_arg()
to ensure the highest bit is well extended on the 64 bits number that
hosts the value in case of negative values.

Reported-Bisected-Tested-by: Sitsofe Wheeler <sitsofe@yahoo.com>
Signed-off-by: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Lai Jiangshan <laijs@cn.fujitsu.com>
Cc: Steven Rostedt <rostedt@goodmis.org>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
LKML-Reference: <20090309201503.GA5010@nowhere>
Signed-off-by: Ingo Molnar <mingo@elte.hu>


---
 lib/vsprintf.c |   13 ++++++-------
 1 files changed, 6 insertions(+), 7 deletions(-)

diff --git a/lib/vsprintf.c b/lib/vsprintf.c
index 25f0157..dc16743 100644
--- a/lib/vsprintf.c
+++ b/lib/vsprintf.c
@@ -768,7 +768,6 @@ static char *pointer(const char *fmt, char *buf, char *end, void *ptr,
 static int format_decode(const char *fmt, struct printf_spec *spec)
 {
 	const char *start = fmt;
-	bool sign = false;
 
 	/* we finished early by reading the field width */
 	if (spec->type == FORMAT_TYPE_WITDH) {
@@ -900,7 +899,7 @@ qualifier:
 
 	case 'd':
 	case 'i':
-		sign = true;
+		spec->flags |= SIGN;
 	case 'u':
 		break;
 
@@ -912,7 +911,7 @@ qualifier:
 	if (spec->qualifier == 'L')
 		spec->type = FORMAT_TYPE_LONG_LONG;
 	else if (spec->qualifier == 'l') {
-		if (sign)
+		if (spec->flags & SIGN)
 			spec->type = FORMAT_TYPE_LONG;
 		else
 			spec->type = FORMAT_TYPE_ULONG;
@@ -921,12 +920,12 @@ qualifier:
 	} else if (spec->qualifier == 't') {
 		spec->type = FORMAT_TYPE_PTRDIFF;
 	} else if (spec->qualifier == 'h') {
-		if (sign)
+		if (spec->flags & SIGN)
 			spec->type = FORMAT_TYPE_SHORT;
 		else
 			spec->type = FORMAT_TYPE_USHORT;
 	} else {
-		if (sign)
+		if (spec->flags & SIGN)
 			spec->type = FORMAT_TYPE_INT;
 		else
 			spec->type = FORMAT_TYPE_UINT;
@@ -1101,8 +1100,8 @@ int vsnprintf(char *buf, size_t size, const char *fmt, va_list args)
 			case FORMAT_TYPE_SHORT:
 				num = (short) va_arg(args, int);
 				break;
-			case FORMAT_TYPE_UINT:
-				num = va_arg(args, unsigned int);
+			case FORMAT_TYPE_INT:
+				num = (int) va_arg(args, int);
 				break;
 			default:
 				num = va_arg(args, unsigned int);

      parent reply	other threads:[~2009-03-10 12:19 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-03-08 23:18 [TIP,BISECTED] Negative nice values have become big positive numbers Sitsofe Wheeler
2009-03-08 23:49 ` Steven Rostedt
2009-03-09  7:08   ` Ingo Molnar
2009-03-09  8:41     ` Frederic Weisbecker
2009-03-09 12:56       ` Sitsofe Wheeler
2009-03-09  8:39   ` Sitsofe Wheeler
2009-03-09 20:15 ` Frederic Weisbecker
2009-03-10  0:12   ` Sitsofe Wheeler
2009-03-10 10:03     ` Frederic Weisbecker
2009-03-10 12:18   ` Frederic Weisbecker [this message]

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=tip-39e874f8afbdb3745e2406ce4ecbde9ac4cbaa78@git.kernel.org \
    --to=fweisbec@gmail.com \
    --cc=hpa@zytor.com \
    --cc=laijs@cn.fujitsu.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-tip-commits@vger.kernel.org \
    --cc=mingo@elte.hu \
    --cc=mingo@redhat.com \
    --cc=rostedt@goodmis.org \
    --cc=sitsofe@yahoo.com \
    --cc=tglx@linutronix.de \
    --cc=torvalds@linux-foundation.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

all inboxes | Powered by JetHome®