Fixes bug in StringWriter, which causes the compiler to

generate a segfault when there are too many string
concatenations. This happens when we convert a file of
about 100kb or larger.

The fix modifies the StringWriter to write the file data
out into a single, long string, without concatenations.

This addresses issue #5
This commit is contained in:
Jim Teeuwen 2013-07-07 13:02:07 +02:00
parent 0877d93299
commit 10c722dc95

View File

@ -1,37 +1,30 @@
// This work is subject to the CC0 1.0 Universal (CC0 1.0) Public Domain Dedication // This work is subject to the CC0 1.0 Universal (CC0 1.0) Public Domain Dedication
// license. Its contents can be found at: // license. Its contents can be found at:
// http://creativecommons.org/publicdomain/zero/1.0/ // http://creativecommons.org/publicdomain/zero/1.0/
package main package main
import ( import (
"fmt" "fmt"
"io" "io"
) )
var line = []byte("\"+\n\"") type StringWriter struct {
io.Writer
type StringWriter struct { c int
io.Writer }
c int
} func (w *StringWriter) Write(p []byte) (n int, err error) {
if len(p) == 0 {
func (w *StringWriter) Write(p []byte) (n int, err error) { return
if len(p) == 0 { }
return
} for n = range p {
fmt.Fprintf(w.Writer, "\\x%02x", p[n])
for n = range p { w.c++
if w.c%16 == 0 { }
w.Writer.Write(line)
w.c = 0 n++
}
return
fmt.Fprintf(w.Writer, "\\x%02x", p[n]) }
w.c++
}
n++
return
}