printf count utf-8 chars like arrow wrong

Bug #1710981 reported by H.-Dirk Schmitt
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
bash (Debian)
New
Unknown
bash (Ubuntu)
New
Undecided
Unassigned
coreutils (Debian)
New
Unknown
coreutils (Ubuntu)
New
Undecided
Unassigned

Bug Description

The printf command in bash (builtin) and corutils /usb/bin/printf have an error in counting the length of a string, if a non-ascii character is involved.
Example is the arrow - type Alt+I.

Try the following commands:
printf -v r "%-2s X\n" '→' ; echo ${#r} # prints 4
printf -v r "%-2s X\n" ' ' ; echo ${#r} # prints 5

The coreutils version of printf has the same misbehaviour.

ProblemType: Bug
DistroRelease: Ubuntu 16.04
Package: coreutils 8.25-2ubuntu3~16.04
ProcVersionSignature: Ubuntu 4.10.0-32.36~16.04.1-generic 4.10.17
Uname: Linux 4.10.0-32-generic x86_64
ApportVersion: 2.20.1-0ubuntu2.10
Architecture: amd64
CurrentDesktop: GNOME
Date: Tue Aug 15 23:05:40 2017
SourcePackage: coreutils
UpgradeStatus: No upgrade log present (probably fresh install)

Revision history for this message
H.-Dirk Schmitt (dirk-computer42) wrote :
Revision history for this message
H.-Dirk Schmitt (dirk-computer42) wrote :

The bug leads to ugly output on the console if the data contains such characters.
See the 3rd song in the following play queue listing:

--------------------------------------------------------------------
Pos. Artist Title Dur.
--------------------------------------------------------------------
  1. Bryan Adams I'm Ready 4:26
  2. Toto Mrs. Johnson 3:48
  3. The Doobie Brothers Long Train Runnin’ 3:39
  4. Three Dog Night One 3:02
  5. Norman Greenbaum Spirit in the Sky 3:51
--------------------------------------------------------------------

Changed in bash (Debian):
status: Unknown → New
Changed in coreutils (Debian):
status: Unknown → New
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.