playwav: parser more resilient against fields with extra zeros

This commit is contained in:
minjaesong
2023-01-25 18:46:55 +09:00
parent 801ae0c29b
commit 1f0b8a0a8d
2 changed files with 22 additions and 4 deletions

View File

@@ -3,6 +3,7 @@ package net.torvald.tsvm
import kotlinx.coroutines.Job
import net.torvald.UnsafeHelper
import net.torvald.UnsafePtr
import net.torvald.terrarum.modulecomputers.virtualcomputer.tvd.toHex
import net.torvald.tsvm.peripheral.IOSpace
import net.torvald.tsvm.peripheral.PeriBase
import net.torvald.tsvm.peripheral.VMProgramRom
@@ -240,7 +241,7 @@ class VM(
if (size <= 0) throw IllegalArgumentException("Invalid malloc size: $size")
val allocBlocks = ceil(size.toDouble() / MALLOC_UNIT).toInt()
val blockStart = findEmptySpace(allocBlocks) ?: throw OutOfMemoryError()
val blockStart = findEmptySpace(allocBlocks) ?: throw OutOfMemoryError("No space for $allocBlocks blocks ($size bytes requested)")
allocatedBlockCount += allocBlocks
mallocSizes[blockStart] = allocBlocks
@@ -249,7 +250,7 @@ class VM(
internal fun free(ptr: Int) {
val index = ptr / MALLOC_UNIT
val count = mallocSizes[index] ?: throw OutOfMemoryError()
val count = mallocSizes[index] ?: throw OutOfMemoryError("No allocation for pointer 0x${ptr.toHex()}")
mallocMap.set(index, index + count, false)
mallocSizes.remove(index)