Skip to content

Commit

Permalink
Avoid panic when book text content is empty
Browse files Browse the repository at this point in the history
As mentioned in the README, the generated book will most likely still
be malformed, but at least the panic can be fixed.
  • Loading branch information
leotaku committed Oct 28, 2023
1 parent 7d62d03 commit aba409b
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion mobi.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,10 @@ func (m Book) Realize() pdb.Database {
}

// Padding
lastLength := textRecords[len(textRecords)-1].Length()
lastLength := 0
if len(textRecords) > 0 {
lastLength = textRecords[len(textRecords)-1].Length()
}
if lastLength%4 != 0 {
pad := make(pdb.RawRecord, lastLength%4)
db.AddRecord(pad)
Expand Down

0 comments on commit aba409b

Please sign in to comment.