From 10c722dc95587b77be6d2e31052c0a989f276146 Mon Sep 17 00:00:00 2001 From: Jim Teeuwen Date: Sun, 7 Jul 2013 13:02:07 +0200 Subject: [PATCH] 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 --- stringwriter.go | 61 ++++++++++++++++++++++--------------------------- 1 file changed, 27 insertions(+), 34 deletions(-) diff --git a/stringwriter.go b/stringwriter.go index 11e191b..7c9c007 100644 --- a/stringwriter.go +++ b/stringwriter.go @@ -1,37 +1,30 @@ // This work is subject to the CC0 1.0 Universal (CC0 1.0) Public Domain Dedication // license. Its contents can be found at: // http://creativecommons.org/publicdomain/zero/1.0/ - -package main - -import ( - "fmt" - "io" -) - -var line = []byte("\"+\n\"") - -type StringWriter struct { - io.Writer - c int -} - -func (w *StringWriter) Write(p []byte) (n int, err error) { - if len(p) == 0 { - return - } - - for n = range p { - if w.c%16 == 0 { - w.Writer.Write(line) - w.c = 0 - } - - fmt.Fprintf(w.Writer, "\\x%02x", p[n]) - w.c++ - } - - n++ - - return -} + +package main + +import ( + "fmt" + "io" +) + +type StringWriter struct { + io.Writer + c int +} + +func (w *StringWriter) Write(p []byte) (n int, err error) { + if len(p) == 0 { + return + } + + for n = range p { + fmt.Fprintf(w.Writer, "\\x%02x", p[n]) + w.c++ + } + + n++ + + return +}