Skip to content

Commit

Permalink
Merge commit 'refs/pull/1/head' of https://github.com/Nvveen/Gotty
Browse files Browse the repository at this point in the history
  • Loading branch information
Ian Campbell committed Apr 6, 2017
2 parents cd52737 + 6018b68 commit 44eeccf
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions gotty.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ package gotty
// TODO add more concurrency to name lookup, look for more opportunities.

import (
"bytes"
"encoding/binary"
"errors"
"fmt"
Expand Down Expand Up @@ -110,7 +111,7 @@ func (term *TermInfo) GetAttributeName(name string) (stacker, error) {
return term.GetAttribute(tc)
}

// A utility function that finds and returns the termcap equivalent of a
// A utility function that finds and returns the termcap equivalent of a
// variable name.
func GetTermcapName(name string) string {
// Termcap name
Expand Down Expand Up @@ -192,7 +193,9 @@ func readTermInfo(path string) (*TermInfo, error) {
}
}
// If the number of bytes read is not even, a byte for alignment is added
if len(byteArray)%2 != 0 {
// We know the header is an even number of bytes so only need to check the
// total of the names and booleans.
if (header[1]+header[2])%2 != 0 {
err = binary.Read(file, binary.LittleEndian, make([]byte, 1))
if err != nil {
return nil, err
Expand Down Expand Up @@ -228,9 +231,14 @@ func readTermInfo(path string) (*TermInfo, error) {
// We get an offset, and then iterate until the string is null-terminated
for i, offset := range shArray {
if offset > -1 {
r := offset
for ; byteArray[r] != 0; r++ {
if int(offset) >= len(byteArray) {
return nil, errors.New("array out of bounds reading string section")
}
r := bytes.IndexByte(byteArray[offset:], 0)
if r == -1 {
return nil, errors.New("missing nul byte reading string section")
}
r += int(offset)
term.strAttributes[StrAttr[i*2+1]] = string(byteArray[offset:r])
}
}
Expand Down

0 comments on commit 44eeccf

Please sign in to comment.