Navigation Menu

Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fmt: Printf panic #6777

Closed
gopherbot opened this issue Nov 16, 2013 · 7 comments
Closed

fmt: Printf panic #6777

gopherbot opened this issue Nov 16, 2013 · 7 comments
Milestone

Comments

@gopherbot
Copy link

by foru607:

fmt package BUG:
------------------------------
package main

import (
    "fmt"
)

func main() {
    fmt.Printf("%#064x\n", 1) // fail, panic
    fmt.Printf("%#064b\n", 1) // ok
    fmt.Printf("%#064o\n", 1) // ok
    fmt.Printf("%#064d\n", 1) // ok

    fmt.Printf("%#070x\n", -1) // fail, panic
    fmt.Printf("%#070b\n", -1) // fail, panic
    fmt.Printf("%#070o\n", -1) // fail, panic
    fmt.Printf("%#070d\n", -1) // fail, panic
}
------------------------------



My environment:
------------------------------
Ubuntu 12.04
go1.2rc4.linux-386.tar.gz
------------------------------



Bug fix approach:
------------------------------
file: go/src/pkg/fmt/format.go
line: 13
change to: nByte = 67

file: go/src/pkg/fmt/format.go
line: 185
add:
if prec > nByte-3 {
    prec = nByte - 3
    f.zero = false
}
------------------------------



Correct results:
------------------------------
0x0000000000000000000000000000000000000000000000000000000000000001
0000000000000000000000000000000000000000000000000000000000000001
0000000000000000000000000000000000000000000000000000000000000001
0000000000000000000000000000000000000000000000000000000000000001
   -0x0000000000000000000000000000000000000000000000000000000000000001
     -0000000000000000000000000000000000000000000000000000000000000001
     -0000000000000000000000000000000000000000000000000000000000000001
     -0000000000000000000000000000000000000000000000000000000000000001
------------------------------
@robpike
Copy link
Contributor

robpike commented Nov 16, 2013

Comment 1:

Labels changed: added priority-soon, packagebug, removed priority-triage.

Owner changed to @robpike.

Status changed to Accepted.

@rsc
Copy link
Contributor

rsc commented Nov 27, 2013

Comment 2:

Labels changed: added go1.3maybe.

@dsymonds
Copy link
Contributor

dsymonds commented Dec 2, 2013

Comment 3:

Labels changed: added go1.3, removed go1.3maybe.

@rsc
Copy link
Contributor

rsc commented Dec 4, 2013

Comment 4:

Labels changed: added release-go1.3.

@rsc
Copy link
Contributor

rsc commented Dec 4, 2013

Comment 5:

Labels changed: removed go1.3.

@rsc
Copy link
Contributor

rsc commented Dec 4, 2013

Comment 6:

Labels changed: added repo-main.

@robpike
Copy link
Contributor

robpike commented Jan 16, 2014

Comment 7:

This issue was closed by revision fc908a0.

Status changed to Fixed.

@rsc rsc added this to the Go1.3 milestone Apr 14, 2015
@rsc rsc removed the release-go1.3 label Apr 14, 2015
@golang golang locked and limited conversation to collaborators Jun 25, 2016
@rsc rsc unassigned robpike Jun 22, 2022
This issue was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants