Skip to content

Commit 843bd24

Browse files
committed
This closes #677 and closes #679, fix panic when enabling compiler inline flags
1 parent fcbc7e3 commit 843bd24

File tree

3 files changed

+5
-12
lines changed

3 files changed

+5
-12
lines changed

lib.go

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ import (
2020
"io"
2121
"strconv"
2222
"strings"
23-
"unsafe"
2423
)
2524

2625
// ReadZipReader can be used to read the spreadsheet in memory without touching the
@@ -251,17 +250,11 @@ func namespaceStrictToTransitional(content []byte) []byte {
251250
StrictNameSpaceSpreadSheet: NameSpaceSpreadSheet.Value,
252251
}
253252
for s, n := range namespaceTranslationDic {
254-
content = bytesReplace(content, stringToBytes(s), stringToBytes(n), -1)
253+
content = bytesReplace(content, []byte(s), []byte(n), -1)
255254
}
256255
return content
257256
}
258257

259-
// stringToBytes cast a string to bytes pointer and assign the value of this
260-
// pointer.
261-
func stringToBytes(s string) []byte {
262-
return *(*[]byte)(unsafe.Pointer(&s))
263-
}
264-
265258
// bytesReplace replace old bytes with given new.
266259
func bytesReplace(s, old, new []byte, n int) []byte {
267260
if n == 0 {
@@ -366,7 +359,7 @@ func getXMLNamespace(space string, attr []xml.Attr) string {
366359
// replaceNameSpaceBytes provides a function to replace the XML root element
367360
// attribute by the given component part path and XML content.
368361
func (f *File) replaceNameSpaceBytes(path string, contentMarshal []byte) []byte {
369-
var oldXmlns = stringToBytes(`xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main">`)
362+
var oldXmlns = []byte(`xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main">`)
370363
var newXmlns = []byte(templateNamespaceIDMap)
371364
if attr, ok := f.xmlAttr[path]; ok {
372365
newXmlns = []byte(genXMLNamespace(attr))

sheet.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -213,8 +213,8 @@ func (f *File) setAppXML() {
213213
// strict requirements about the structure of the input XML. This function is
214214
// a horrible hack to fix that after the XML marshalling is completed.
215215
func replaceRelationshipsBytes(content []byte) []byte {
216-
oldXmlns := stringToBytes(`xmlns:relationships="http://schemas.openxmlformats.org/officeDocument/2006/relationships" relationships`)
217-
newXmlns := stringToBytes("r")
216+
oldXmlns := []byte(`xmlns:relationships="http://schemas.openxmlformats.org/officeDocument/2006/relationships" relationships`)
217+
newXmlns := []byte("r")
218218
return bytesReplace(content, oldXmlns, newXmlns, -1)
219219
}
220220

stream.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,7 @@ func writeCell(buf *bufferedWriter, c xlsxC) {
367367
buf.WriteString(`>`)
368368
if c.V != "" {
369369
buf.WriteString(`<v>`)
370-
xml.EscapeText(buf, stringToBytes(c.V))
370+
xml.EscapeText(buf, []byte(c.V))
371371
buf.WriteString(`</v>`)
372372
}
373373
buf.WriteString(`</c>`)

0 commit comments

Comments
 (0)