shithub: cstory

Download patch

ref: aad200801cf7c07990afcb195b0cdc6cf1c7e417
parent: 02939dfa316431d9b6488d8b30ca480ebb7eaee9
author: Gabriel Ravier <[email protected]>
date: Fri Jan 31 18:55:59 EST 2020

Removed UB in PutArmsEnergy

Signed-off-by: Gabriel Ravier <[email protected]>

--- a/src/MycParam.cpp
+++ b/src/MycParam.cpp
@@ -271,6 +271,9 @@
 	RECT rcExpFlash = {40, 80, 80, 88};
 
 	int lv = gArmsData[gSelectedArms].level - 1;
+	if (lv < 0)	// Detect the case where the level is 0 (no weapon)
+		lv = 0;	// Set lv to a safe value
+
 	int arms_code = gArmsData[gSelectedArms].code;
 	int exp_now = gArmsData[gSelectedArms].exp;
 	int exp_next = gArmsLevelTable[arms_code].exp[lv];