GNU bug report logs - #13555
printf ignores length modifier

Previous Next

Package: coreutils;

Reported by: "Marcel Böhme" <hawkie <at> web.de>

Date: Sat, 26 Jan 2013 10:36:02 UTC

Severity: normal

Tags: notabug

Done: Assaf Gordon <assafgordon <at> gmail.com>

Bug is archived. No further changes may be made.

To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 13555 in the body.
You can then email your comments to 13555 AT debbugs.gnu.org in the normal way.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to bug-coreutils <at> gnu.org:
bug#13555; Package coreutils. (Sat, 26 Jan 2013 10:36:02 GMT) Full text and rfc822 format available.

Acknowledgement sent to "Marcel Böhme" <hawkie <at> web.de>:
New bug report received and forwarded. Copy sent to bug-coreutils <at> gnu.org. (Sat, 26 Jan 2013 10:36:02 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: "Marcel Böhme" <hawkie <at> web.de>
To: bug-coreutils <at> gnu.org
Subject: printf ignores length modifier
Date: Sat, 26 Jan 2013 10:41:59 +0100 (CET)
Dear all,

I've been looking into the semantic changes introduced to printf with the commit 62e1d5259df82155ae52201678093381a35d898e (08.07.2004) and found besides a lot of progression (conformance to C99 etc.) the following oddities:

The tool printf ignores length modifiers (cf. http://linux.die.net/man/3/printf)
In fact, any (combination of) length modifier is substituted by "ll" as length modifier. Is this intended?

$old/printf "%hi\n" 0xFFFF
-1
$printf "%hi\n" 0xFFFF
65535

$old/printf  "%hi\n" 0xFFF
4095
$old/printf  "%hhLljtzllhi\n" 0xFFF
printf: %h: invalid directive
$printf  "%hhLljtzllhi\n" 0xFFF
4095


On the on hand the comment reads:
 332   /* Create a null-terminated copy of the % directive, with an
 333      intmax_t-wide length modifier substituted for any existing
 334      integer length modifier.  */

On the other hand the commit comment reads:
> Add support for C99 'j', 't', 'z' length modifiers (like Bash).

Best regards,
 Marcel


PS: http://git.savannah.gnu.org/gitweb/?p=coreutils.git;a=commitdiff;h=62e1d5259df82155ae52201678093381a35d898e




Information forwarded to bug-coreutils <at> gnu.org:
bug#13555; Package coreutils. (Sat, 26 Jan 2013 16:38:02 GMT) Full text and rfc822 format available.

Message #8 received at 13555 <at> debbugs.gnu.org (full text, mbox):

From: Paul Eggert <eggert <at> cs.ucla.edu>
To: Marcel Böhme <hawkie <at> web.de>
Cc: 13555 <at> debbugs.gnu.org
Subject: Re: bug#13555: printf ignores length modifier
Date: Sat, 26 Jan 2013 08:37:42 -0800
On 01/26/2013 01:41 AM, Marcel Böhme wrote:
> $old/printf "%hi\n" 0xFFFF
> -1
> $printf "%hi\n" 0xFFFF
> 65535

None of these length modifiers are specified by POSIX,
so we're talking about what it's more useful for printf
to do, rather than whether this is a violation of
a standard.  coreutils printf should agree
with Bash printf, and Bash printf ignores the modifiers,
so if we change coreutils we should change Bash too.

I suppose that 'printf' could change its behavior, and
use (say) 32-bit int for '%li' on a x86 but 64-bit int
on x86-64, thus exposing the native machine widths to
the user.  However, for shell scripts I expect that more
people prefer portability to exposing the machine widths,
so the current behavior is better.





Information forwarded to bug-coreutils <at> gnu.org:
bug#13555; Package coreutils. (Sun, 27 Jan 2013 00:53:01 GMT) Full text and rfc822 format available.

Message #11 received at 13555 <at> debbugs.gnu.org (full text, mbox):

From: Marcel Boehme <hawkie <at> web.de>
To: Paul Eggert <eggert <at> cs.ucla.edu>
Cc: "13555 <at> debbugs.gnu.org" <13555 <at> debbugs.gnu.org>
Subject: Re: bug#13555: printf ignores length modifier
Date: Sun, 27 Jan 2013 08:55:26 +0800
Dear Paul,

Then, I suppose, the observed semantic change for the mentioned version pair was _intended_. Found it odd that I didn't find documented that / why length modifiers are 'suddenly' ignored.

Thanks for your follow-up!

Best regards,
Marcel



On 27 Jan, 2013, at 12:37 AM, Paul Eggert <eggert <at> cs.ucla.edu> wrote:

> On 01/26/2013 01:41 AM, Marcel Böhme wrote:
>> $old/printf "%hi\n" 0xFFFF
>> -1
>> $printf "%hi\n" 0xFFFF
>> 65535
> 
> None of these length modifiers are specified by POSIX,
> so we're talking about what it's more useful for printf
> to do, rather than whether this is a violation of
> a standard.  coreutils printf should agree
> with Bash printf, and Bash printf ignores the modifiers,
> so if we change coreutils we should change Bash too.
> 
> I suppose that 'printf' could change its behavior, and
> use (say) 32-bit int for '%li' on a x86 but 64-bit int
> on x86-64, thus exposing the native machine widths to
> the user.  However, for shell scripts I expect that more
> people prefer portability to exposing the machine widths,
> so the current behavior is better.
> 




Information forwarded to bug-coreutils <at> gnu.org:
bug#13555; Package coreutils. (Thu, 18 Oct 2018 23:29:01 GMT) Full text and rfc822 format available.

Message #14 received at 13555 <at> debbugs.gnu.org (full text, mbox):

From: Assaf Gordon <assafgordon <at> gmail.com>
To: Marcel Boehme <hawkie <at> web.de>, Paul Eggert <eggert <at> cs.ucla.edu>
Cc: "13555 <at> debbugs.gnu.org" <13555 <at> debbugs.gnu.org>
Subject: Re: bug#13555: printf ignores length modifier
Date: Thu, 18 Oct 2018 17:28:34 -0600
tags 13555 notabug
close 13555
stop

(triaging old bugs)

Hello,

> Paul Eggert <eggert <at> cs.ucla.edu> wrote:
>
>>  Marcel Böhme wrote:
>>> $old/printf "%hi\n" 0xFFFF
>>> -1
>>> $printf "%hi\n" 0xFFFF
>>> 65535
>>
>> None of these length modifiers are specified by POSIX,
>> so we're talking about what it's more useful for printf
>> to do, rather than whether this is a violation of
>> a standard.

On 26/01/13 05:55 PM, Marcel Boehme wrote:
> Then, I suppose, the observed semantic change for the mentioned version pair was _intended_. Found it odd that I didn't find documented that / why length modifiers are 'suddenly' ignored.
> 
> Thanks for your follow-up!

With no further comments in 5 years, I'm closing this bug.

-assaf




Added tag(s) notabug. Request was from Assaf Gordon <assafgordon <at> gmail.com> to control <at> debbugs.gnu.org. (Tue, 30 Oct 2018 09:29:01 GMT) Full text and rfc822 format available.

bug closed, send any further explanations to 13555 <at> debbugs.gnu.org and "Marcel Böhme" <hawkie <at> web.de> Request was from Assaf Gordon <assafgordon <at> gmail.com> to control <at> debbugs.gnu.org. (Tue, 30 Oct 2018 09:29:02 GMT) Full text and rfc822 format available.

bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Tue, 27 Nov 2018 12:24:09 GMT) Full text and rfc822 format available.

This bug report was last modified 6 years and 204 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.