GNU bug report logs - #7325
new test failure due to non-portability of printf formats like %05.3s

Previous Next

Package: coreutils;

Reported by: Jim Meyering <jim <at> meyering.net>

Date: Wed, 3 Nov 2010 18:56:02 UTC

Severity: normal

Done: Pádraig Brady <P <at> draigBrady.com>

Bug is archived. No further changes may be made.

Full log


View this message in rfc822 format

From: Jim Meyering <jim <at> meyering.net>
To: Paul Eggert <eggert <at> cs.ucla.edu>
Cc: 7325 <at> debbugs.gnu.org, Eric Blake <eblake <at> redhat.com>
Subject: bug#7325: new test failure due to non-portability of printf formats like %05.3s
Date: Thu, 04 Nov 2010 08:56:54 +0100
Paul Eggert wrote:

> The test-case part of that looks OK, but the change to stat.c
> can be simplified.  Also, there's a similar problem with a format
> like %020X, which should be fixed too.
>
> While we're on the subject, there are other ways that stat invokers
> can exercise undefined behavior (in the C sense) by passing
> weird formats in.  This really should get fixed at some point.
> The patch proposed below addresses just the immediate issue.
>
>>From a24a9ce8f3711670a6413c60b5e9ebd3e51a4e06 Mon Sep 17 00:00:00 2001
> From: Paul Eggert <eggert <at> cs.ucla.edu>
> Date: Wed, 3 Nov 2010 15:49:50 -0700
> Subject: [PATCH] stat: handle leading '0' when formatting secs and ns
>
> * src/stat.c (epoch_sec): Remove. All callers changed to use
> out_epoch_sec instead.
> (out_ns): Use numeric format, not string format, to output
> the nanoseconds count; this avoids unportable use of (e.g.)
> %05s in a printf format.
> (out_epoch_sec): New function.  This also uses a numeric format,
> instead of a string format, to output a number.

However, what about Eric's example?

  $ src/stat-p -c '_%-0 010.4:X_' k  # yours
  _234       _
  $ src/stat-j -c '_%-0 010.4:X_' k  # mine
  _0234      _

and printf (note how it includes the leading space):

  $ env printf '_%-0 010.4d_\n' 234
  _ 0234     _




This bug report was last modified 14 years and 191 days ago.

Previous Next


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