From 25cda4e8b4844aecf8cdc70ffcab8e0adaab3486 Mon Sep 17 00:00:00 2001 From: "madmaxoft@gmail.com" Date: Sun, 12 May 2013 15:58:29 +0000 Subject: cItems: Added runtime bounds-checking to avoid server crashes with badly written plugins. git-svn-id: http://mc-server.googlecode.com/svn/trunk@1472 0a769ca7-a7f5-676a-18bf-c427514a06d6 --- source/Item.h | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) (limited to 'source/Item.h') diff --git a/source/Item.h b/source/Item.h index 570182bae..3b485d3de 100644 --- a/source/Item.h +++ b/source/Item.h @@ -92,8 +92,10 @@ public: -// This stupid construct is here only so that Lua can access cItems in an API +/** This class bridges a vector of cItem for safe access via Lua. It checks boundaries for all accesses +Note that this class is zero-indexed! +*/ class cItems // tolua_export : public std::vector { // tolua_export @@ -103,22 +105,19 @@ public: /// Need a Lua-accessible constructor cItems(void) {} - cItem & Get (int a_Idx) {return at(a_Idx); } - void Set (int a_Idx, const cItem & a_Item) {at(a_Idx) = a_Item; } + cItem * Get (int a_Idx); + void Set (int a_Idx, const cItem & a_Item); void Add (const cItem & a_Item) {push_back(a_Item); } - void Delete(int a_Idx) {erase(begin() + a_Idx); } + void Delete(int a_Idx); void Clear (void) {clear(); } int Size (void) {return size(); } + void Set (int a_Idx, ENUM_ITEM_ID a_ItemType, char a_ItemCount, short a_ItemDamage); void Add (ENUM_ITEM_ID a_ItemType, char a_ItemCount, short a_ItemDamage) { push_back(cItem(a_ItemType, a_ItemCount, a_ItemDamage)); } - void Set (int a_Idx, ENUM_ITEM_ID a_ItemType, char a_ItemCount, short a_ItemDamage) - { - at(a_Idx) = cItem(a_ItemType, a_ItemCount, a_ItemDamage); - } // tolua_end } ; // tolua_export -- cgit v1.2.3