mirror of
https://github.com/curioustorvald/tsvm.git
synced 2026-03-12 14:11:50 +09:00
playwav: parser more resilient against fields with extra zeros
This commit is contained in:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user