From 8e7cbdda70d771f5a918fcd841019000bcd285e1 Mon Sep 17 00:00:00 2001 From: Peter Veenstra Date: Sun, 15 May 2011 20:25:28 +0000 Subject: [PATCH] Stay within array limits Imported-from: https://svn.code.sf.net/p/dosbox/code-0/dosbox/trunk@3712 --- src/debug/debug.cpp | 5 ++++- src/dosbox.cpp | 5 +++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/debug/debug.cpp b/src/debug/debug.cpp index a73d86c4..992ed4a4 100644 --- a/src/debug/debug.cpp +++ b/src/debug/debug.cpp @@ -1725,7 +1725,10 @@ Bit32u DEBUG_CheckKeys(void) { } if (ret<0) return ret; if (ret>0) { - ret=(*CallBack_Handlers[ret])(); + if (GCC_UNLIKELY(ret >= CB_MAX)) + ret = 0; + else + ret = (*CallBack_Handlers[ret])(); if (ret) { exitLoop=true; CPU_Cycles=CPU_CycleLeft=0; diff --git a/src/dosbox.cpp b/src/dosbox.cpp index 34e848fd..d95de3f8 100644 --- a/src/dosbox.cpp +++ b/src/dosbox.cpp @@ -128,10 +128,11 @@ static Bitu Normal_Loop(void) { Bits ret; while (1) { if (PIC_RunQueue()) { - ret=(*cpudecoder)(); + ret = (*cpudecoder)(); if (GCC_UNLIKELY(ret<0)) return 1; if (ret>0) { - Bitu blah=(*CallBack_Handlers[ret])(); + if (GCC_UNLIKELY(ret >= CB_MAX)) return 0; + Bitu blah = (*CallBack_Handlers[ret])(); if (GCC_UNLIKELY(blah)) return blah; } #if C_DEBUG