Skip to content

Commit

Permalink
Don't throw TMI in OpDuplicateN to remove mishap message discrepancy
Browse files Browse the repository at this point in the history
  • Loading branch information
vgskye committed Aug 24, 2024
1 parent 82ac41c commit 1b1ffca
Showing 1 changed file with 5 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,20 @@ import at.petrak.hexcasting.api.casting.castables.ConstMediaAction
import at.petrak.hexcasting.api.casting.eval.CastingEnvironment
import at.petrak.hexcasting.api.casting.getPositiveInt
import at.petrak.hexcasting.api.casting.iota.Iota
import at.petrak.hexcasting.api.casting.mishaps.MishapStackSize
import at.petrak.hexcasting.common.lib.hex.HexIotaTypes

object OpDuplicateN : ConstMediaAction {
override val argc: Int
get() = 2

override fun execute(args: List<Iota>, env: CastingEnvironment): List<Iota> {
val count = args.getPositiveInt(1, argc)
var count = args.getPositiveInt(1, argc)

if (count > HexIotaTypes.MAX_SERIALIZATION_TOTAL) {
throw MishapStackSize()
// If we throw here, the message will point to us, which usually doesn't happen.
// So ensure that this check has no user-facing effects, just cap to MAX_SERIALIZATION_TOTAL,
// which will unconditionally trigger Too Many Iotas after we return.
count = HexIotaTypes.MAX_SERIALIZATION_TOTAL
}

return (List(count) { args[0] })
Expand Down

0 comments on commit 1b1ffca

Please sign in to comment.