Opened 3 years ago

Closed 3 years ago

#7457 closed bug (fixed)

printf's * doesn't like negative numbers

Reported by: elaforge Owned by:
Priority: normal Milestone: 7.8.1
Component: libraries/base Version: 7.6.1
Keywords: Cc: augustss
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: None/Unknown Test Case: libraries/base/tests/T7457
Blocked By: Blocking:
Related Tickets: Differential Revisions:

Description

Text.Printf.printf has a bug where it doesn't like negative numbers for * modifiers:

Prelude Text.Printf> printf "%*sx\n" (-3) "hi"
hix

In the C printf, this would be

hi x

From looking at the source, it's a pretty easy bug to fix. Patch attached. I also included a patch to turn the mixed tabs and spaces into just spaces since I hate that stuff.

Attachments (2)

bug.patch (448 bytes) - added by elaforge 3 years ago.
allow precision to be negative
tabs.patch (7.7 KB) - added by elaforge 3 years ago.
replace tabs with spaces

Download all attachments as: .zip

Change History (5)

comment:1 Changed 3 years ago by simonmar

  • Cc augustss added
  • difficulty set to Unknown
  • Milestone set to 7.8.1

Looking at the patch, it appears to remove some deliberate checks. CC'ing Lennart, who wrote the code.

Changed 3 years ago by elaforge

allow precision to be negative

Changed 3 years ago by elaforge

replace tabs with spaces

comment:2 Changed 3 years ago by elaforge

I was really confused until I realized the patch is backwards. It *adds* the 'abs n' line, not removes. I think the tabs patch was also messed up. I replaced the patches with less backwards ones.

Sorry for the confusion!

comment:3 Changed 3 years ago by simonmar

  • Resolution set to fixed
  • Status changed from new to closed
  • Test Case set to libraries/base/tests/T7457

Committed; thanks

commit 63202b9df64041e1c17603ad5f06fec3c51f357d
Author: Simon Marlow <[email protected]>
Date:   Mon Jan 28 09:38:06 2013 +0000

    fix negative numbers for * modifiers (#7457)

commit 2c52ae2eb3720da2a01f6d6cb08c1a6449819a29
Author: Simon Marlow <[email protected]>
Date:   Mon Jan 28 09:38:19 2013 +0000

    tabs -> spaces
Note: See TracTickets for help on using tickets.