From owner-freebsd-bugs@FreeBSD.ORG Wed Aug 31 12:40:14 2005 Return-Path: X-Original-To: freebsd-bugs@hub.freebsd.org Delivered-To: freebsd-bugs@hub.freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id A702716A41F for ; Wed, 31 Aug 2005 12:40:14 +0000 (GMT) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (freefall.freebsd.org [216.136.204.21]) by mx1.FreeBSD.org (Postfix) with ESMTP id 2A41943D46 for ; Wed, 31 Aug 2005 12:40:14 +0000 (GMT) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (gnats@localhost [127.0.0.1]) by freefall.freebsd.org (8.13.3/8.13.3) with ESMTP id j7VCeDY5036876 for ; Wed, 31 Aug 2005 12:40:14 GMT (envelope-from gnats@freefall.freebsd.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.13.3/8.13.1/Submit) id j7VCeDep036875; Wed, 31 Aug 2005 12:40:13 GMT (envelope-from gnats) Resent-Date: Wed, 31 Aug 2005 12:40:13 GMT Resent-Message-Id: <200508311240.j7VCeDep036875@freefall.freebsd.org> Resent-From: FreeBSD-gnats-submit@FreeBSD.org (GNATS Filer) Resent-To: freebsd-bugs@FreeBSD.org Resent-Reply-To: FreeBSD-gnats-submit@FreeBSD.org, Oliver Fromme Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 9351A16A41F for ; Wed, 31 Aug 2005 12:34:26 +0000 (GMT) (envelope-from olli@lurza.secnetix.de) Received: from lurza.secnetix.de (lurza.secnetix.de [83.120.8.8]) by mx1.FreeBSD.org (Postfix) with ESMTP id D482143D48 for ; Wed, 31 Aug 2005 12:34:25 +0000 (GMT) (envelope-from olli@lurza.secnetix.de) Received: from lurza.secnetix.de (venmbc@localhost [127.0.0.1]) by lurza.secnetix.de (8.13.1/8.13.1) with ESMTP id j7VCYNqh046381; Wed, 31 Aug 2005 14:34:23 +0200 (CEST) (envelope-from oliver.fromme@secnetix.de) Received: (from olli@localhost) by lurza.secnetix.de (8.13.1/8.13.1/Submit) id j7VCYNPN046380; Wed, 31 Aug 2005 14:34:23 +0200 (CEST) (envelope-from olli) Message-Id: <200508311234.j7VCYNPN046380@lurza.secnetix.de> Date: Wed, 31 Aug 2005 14:34:23 +0200 (CEST) From: Oliver Fromme To: FreeBSD-gnats-submit@FreeBSD.org X-Send-Pr-Version: 3.113 Cc: Oliver Fromme Subject: kern/85520: [patch] [trivial] Fix bug in kernel printf(9) formatting X-BeenThere: freebsd-bugs@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list Reply-To: Oliver Fromme List-Id: Bug reports List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 31 Aug 2005 12:40:14 -0000 >Number: 85520 >Category: kern >Synopsis: [patch] [trivial] Fix bug in kernel printf(9) formatting >Confidential: no >Severity: non-critical >Priority: low >Responsible: freebsd-bugs >State: open >Quarter: >Keywords: >Date-Required: >Class: sw-bug >Submitter-Id: current-users >Arrival-Date: Wed Aug 31 12:40:13 GMT 2005 >Closed-Date: >Last-Modified: >Originator: Oliver Fromme >Release: HEAD, RELENG_6 (6.0-BETA3), RELENG_5, RELENG_4 >Organization: secnetix GmbH & Co. KG, Munich, Germany >Environment: This patch applies to RELENG_4 and all later versions up to HEAD, including 6.0-BETA3. >Description: The left-padding (when ladjust is not set) does not work correctly in the kernel's printf(9) implementation which can be found in src/sys/kern/subr_prf.c. printf("%5d", -42); --> " -42" (correct) printf("%#5x", 12); --> " 0xc" (correct) printf("%05d", -42); --> "00-42" (should be "-0042") printf("%#05x", 12); --> "000xc" (should be "0x00c") Obviously, when zero-padding ('0' flag) is requested, the padding should occur _after_ any prefixes (sign, "0x"). Otherwise (space-padding), it should occur _before_ any prefixes. In the current (broken) implementation, the padding always happens first. The patch below fixes that behaviour. By the way, there are more bugs which this patch doesn't address yet: The '+' and ' ' (space) flags aren't handled correctly, the precision is not used for numeric conversions (in which case the '0' flag must be ignored), and possibly others. I'll try to fix those later. >How-To-Repeat: Insert a printf() in your kernel somewhere which prints a negative number (or a hex number with '#') with zero-padding. >Fix: --- src/sys/kern/subr_prf.c.orig Tue Jun 7 00:18:32 2005 +++ src/sys/kern/subr_prf.c Wed Aug 31 09:00:41 2005 @@ -755,7 +755,8 @@ if (neg) tmp++; - if (!ladjust && width && (width -= tmp) > 0) + if (!ladjust && padc != '0' && width + && (width -= tmp) > 0) while (width--) PCHAR(padc); if (neg) @@ -768,6 +769,9 @@ PCHAR('x'); } } + if (!ladjust && width && (width -= tmp) > 0) + while (width--) + PCHAR(padc); while (*p) PCHAR(*p--); >Release-Note: >Audit-Trail: >Unformatted: