1
0
mirror of https://github.com/garraflavatra/go-fmp.git synced 2025-06-27 20:15:11 +00:00

Add error handling for processChunks

This commit is contained in:
2025-06-13 20:40:34 +02:00
parent ae32067c68
commit 193f23a20c
2 changed files with 13 additions and 4 deletions

View File

@ -52,8 +52,12 @@ func OpenFile(path string) (*FmpFile, error) {
} }
ctx.Sectors = append(ctx.Sectors, sector) ctx.Sectors = append(ctx.Sectors, sector)
if sector.ID != 0 { if sector.ID != 0 {
sector.processChunks(ctx.Dictionary, &currentPath) err = sector.processChunks(ctx.Dictionary, &currentPath)
if err != nil {
return nil, err
}
ctx.Chunks = append(ctx.Chunks, sector.Chunks...) ctx.Chunks = append(ctx.Chunks, sector.Chunks...)
} }

View File

@ -10,7 +10,7 @@ func (sect *FmpSector) readChunks() error {
panic("chunks already read") panic("chunks already read")
} }
for { for {
pos := (sect.ID+2)*sectorSize - uint64(len(sect.Payload)) pos := sect.ID*sectorSize - uint64(len(sect.Payload))
chunk, err := sect.readChunk(sect.Payload) chunk, err := sect.readChunk(sect.Payload)
if chunk == nil { if chunk == nil {
@ -46,8 +46,12 @@ func (sect *FmpSector) readChunks() error {
return nil return nil
} }
func (sect *FmpSector) processChunks(dict *FmpDict, currentPath *[]uint64) { func (sect *FmpSector) processChunks(dict *FmpDict, currentPath *[]uint64) error {
sect.readChunks() err := sect.readChunks()
if err != nil {
return err
}
for _, chunk := range sect.Chunks { for _, chunk := range sect.Chunks {
switch chunk.Type { switch chunk.Type {
case FMP_CHUNK_PATH_PUSH: case FMP_CHUNK_PATH_PUSH:
@ -92,6 +96,7 @@ func (sect *FmpSector) processChunks(dict *FmpDict, currentPath *[]uint64) {
} }
} }
} }
return nil
} }
func (sect *FmpSector) readChunk(payload []byte) (*FmpChunk, error) { func (sect *FmpSector) readChunk(payload []byte) (*FmpChunk, error) {