Skip to content
This repository has been archived by the owner on May 2, 2018. It is now read-only.

Commit

Permalink
misc cleanup: gofmt + &x -> x[0:] conversion
Browse files Browse the repository at this point in the history
R=gri
CC=golang-dev
https://golang.org/cl/1620042
  • Loading branch information
rsc committed Jun 9, 2010
1 parent f29fb25 commit 6aaef04
Show file tree
Hide file tree
Showing 10 changed files with 149 additions and 141 deletions.
18 changes: 9 additions & 9 deletions src/pkg/debug/macho/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,11 +168,11 @@ func NewFile(r io.ReaderAt) (*File, os.Error) {
// Read and decode Mach magic to determine byte order, size.
// Magic32 and Magic64 differ only in the bottom bit.
var ident [4]byte
if _, err := r.ReadAt(&ident, 0); err != nil {
if _, err := r.ReadAt(ident[0:], 0); err != nil {
return nil, err
}
be := binary.BigEndian.Uint32(&ident)
le := binary.LittleEndian.Uint32(&ident)
be := binary.BigEndian.Uint32(ident[0:])
le := binary.LittleEndian.Uint32(ident[0:])
switch Magic32 &^ 1 {
case be &^ 1:
f.ByteOrder = binary.BigEndian
Expand Down Expand Up @@ -227,7 +227,7 @@ func NewFile(r io.ReaderAt) (*File, os.Error) {
s.LoadBytes = cmddat
s.Cmd = cmd
s.Len = siz
s.Name = cstring(&seg32.Name)
s.Name = cstring(seg32.Name[0:])
s.Addr = uint64(seg32.Addr)
s.Memsz = uint64(seg32.Memsz)
s.Offset = uint64(seg32.Offset)
Expand All @@ -243,8 +243,8 @@ func NewFile(r io.ReaderAt) (*File, os.Error) {
return nil, err
}
sh := new(Section)
sh.Name = cstring(&sh32.Name)
sh.Seg = cstring(&sh32.Seg)
sh.Name = cstring(sh32.Name[0:])
sh.Seg = cstring(sh32.Seg[0:])
sh.Addr = uint64(sh32.Addr)
sh.Size = uint64(sh32.Size)
sh.Offset = sh32.Offset
Expand All @@ -265,7 +265,7 @@ func NewFile(r io.ReaderAt) (*File, os.Error) {
s.LoadBytes = cmddat
s.Cmd = cmd
s.Len = siz
s.Name = cstring(&seg64.Name)
s.Name = cstring(seg64.Name[0:])
s.Addr = seg64.Addr
s.Memsz = seg64.Memsz
s.Offset = seg64.Offset
Expand All @@ -281,8 +281,8 @@ func NewFile(r io.ReaderAt) (*File, os.Error) {
return nil, err
}
sh := new(Section)
sh.Name = cstring(&sh64.Name)
sh.Seg = cstring(&sh64.Seg)
sh.Name = cstring(sh64.Name[0:])
sh.Seg = cstring(sh64.Seg[0:])
sh.Addr = sh64.Addr
sh.Size = sh64.Size
sh.Offset = sh64.Offset
Expand Down
4 changes: 2 additions & 2 deletions src/pkg/debug/proc/regs_linux_386.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ type _386Regs struct {
setter func(*syscall.PtraceRegs) os.Error
}

var names = [...]string{
var names = []string{
"eax",
"ebx",
"ecx",
Expand Down Expand Up @@ -55,7 +55,7 @@ func (r *_386Regs) SetSP(val Word) os.Error {
return r.setter(&r.PtraceRegs)
}

func (r *_386Regs) Names() []string { return &names }
func (r *_386Regs) Names() []string { return names }

func (r *_386Regs) Get(i int) Word {
switch i {
Expand Down
15 changes: 11 additions & 4 deletions src/pkg/http/triv.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,12 @@ package main

import (
"bytes"
"bufio"
"expvar"
"flag"
"fmt"
"http"
"io"
"log"
"net"
"os"
"strconv"
)
Expand Down Expand Up @@ -67,7 +66,7 @@ func FileServer(c *http.Conn, req *http.Request) {
fmt.Fprintf(c, "open %s: %v\n", path, err)
return
}
n, err1 := io.Copy(c, f)
n, _ := io.Copy(c, f)
fmt.Fprintf(c, "[%d bytes]\n", n)
f.Close()
}
Expand All @@ -89,7 +88,7 @@ func FlagServer(c *http.Conn, req *http.Request) {

// simple argument server
func ArgServer(c *http.Conn, req *http.Request) {
for i, s := range os.Args {
for _, s := range os.Args {
fmt.Fprint(c, s, " ")
}
}
Expand Down Expand Up @@ -138,6 +137,13 @@ func DateServer(c *http.Conn, req *http.Request) {
}
}

func Logger(c *http.Conn, req *http.Request) {
log.Stdout(req.URL.Raw)
c.WriteHeader(404)
c.Write([]byte("oops"))
}


func main() {
flag.Parse()

Expand All @@ -146,6 +152,7 @@ func main() {
http.Handle("/counter", ctr)
expvar.Publish("counter", ctr)

http.Handle("/", http.HandlerFunc(Logger))
http.Handle("/go/", http.HandlerFunc(FileServer))
http.Handle("/flags", http.HandlerFunc(FlagServer))
http.Handle("/args", http.HandlerFunc(ArgServer))
Expand Down
2 changes: 1 addition & 1 deletion src/pkg/json/stream_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ func TestRawMessage(t *testing.T) {
if err != nil {
t.Fatalf("Unmarshal: %v", err)
}
if string(*data.Id) != raw {
if string([]byte(*data.Id)) != raw {
t.Fatalf("Raw mismatch: have %#q want %#q", []byte(*data.Id), raw)
}
b, err := Marshal(&data)
Expand Down
8 changes: 4 additions & 4 deletions src/pkg/net/iprawsock.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ import (
func sockaddrToIP(sa syscall.Sockaddr) Addr {
switch sa := sa.(type) {
case *syscall.SockaddrInet4:
return &IPAddr{&sa.Addr}
return &IPAddr{sa.Addr[0:]}
case *syscall.SockaddrInet6:
return &IPAddr{&sa.Addr}
return &IPAddr{sa.Addr[0:]}
}
return nil
}
Expand Down Expand Up @@ -176,14 +176,14 @@ func (c *IPConn) ReadFromIP(b []byte) (n int, addr *IPAddr, err os.Error) {
n, sa, err := c.fd.ReadFrom(b)
switch sa := sa.(type) {
case *syscall.SockaddrInet4:
addr = &IPAddr{&sa.Addr}
addr = &IPAddr{sa.Addr[0:]}
if len(b) >= 4 { // discard ipv4 header
hsize := (int(b[0]) & 0xf) * 4
copy(b, b[hsize:])
n -= hsize
}
case *syscall.SockaddrInet6:
addr = &IPAddr{&sa.Addr}
addr = &IPAddr{sa.Addr[0:]}
}
return
}
Expand Down
4 changes: 2 additions & 2 deletions src/pkg/net/tcpsock.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ import (
func sockaddrToTCP(sa syscall.Sockaddr) Addr {
switch sa := sa.(type) {
case *syscall.SockaddrInet4:
return &TCPAddr{&sa.Addr, sa.Port}
return &TCPAddr{sa.Addr[0:], sa.Port}
case *syscall.SockaddrInet6:
return &TCPAddr{&sa.Addr, sa.Port}
return &TCPAddr{sa.Addr[0:], sa.Port}
}
return nil
}
Expand Down
8 changes: 4 additions & 4 deletions src/pkg/net/udpsock.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ import (
func sockaddrToUDP(sa syscall.Sockaddr) Addr {
switch sa := sa.(type) {
case *syscall.SockaddrInet4:
return &UDPAddr{&sa.Addr, sa.Port}
return &UDPAddr{sa.Addr[0:], sa.Port}
case *syscall.SockaddrInet6:
return &UDPAddr{&sa.Addr, sa.Port}
return &UDPAddr{sa.Addr[0:], sa.Port}
}
return nil
}
Expand Down Expand Up @@ -176,9 +176,9 @@ func (c *UDPConn) ReadFromUDP(b []byte) (n int, addr *UDPAddr, err os.Error) {
n, sa, err := c.fd.ReadFrom(b)
switch sa := sa.(type) {
case *syscall.SockaddrInet4:
addr = &UDPAddr{&sa.Addr, sa.Port}
addr = &UDPAddr{sa.Addr[0:], sa.Port}
case *syscall.SockaddrInet6:
addr = &UDPAddr{&sa.Addr, sa.Port}
addr = &UDPAddr{sa.Addr[0:], sa.Port}
}
return
}
Expand Down
Loading

0 comments on commit 6aaef04

Please sign in to comment.