summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLance <Lance@54d463be-8e91-2dee-dedb-b68131a5f0ec>2006-06-12 16:18:08 +0000
committerLance <Lance@54d463be-8e91-2dee-dedb-b68131a5f0ec>2006-06-12 16:18:08 +0000
commit9cddcb73499f17c5e8a08cd0720e53e933167589 (patch)
tree6b8f32245a9d0acbae99b2cb42175b192dbcbf2d
parent93ac49f9c60ecc0f2ed0d4f13c05af2711558568 (diff)
downloadhercules-9cddcb73499f17c5e8a08cd0720e53e933167589.tar.gz
hercules-9cddcb73499f17c5e8a08cd0720e53e933167589.tar.bz2
hercules-9cddcb73499f17c5e8a08cd0720e53e933167589.tar.xz
hercules-9cddcb73499f17c5e8a08cd0720e53e933167589.zip
* [Optimized]:
- buildin_npcshopitem memory allocation to calculate before reallocating. git-svn-id: https://rathena.svn.sourceforge.net/svnroot/rathena/trunk@7105 54d463be-8e91-2dee-dedb-b68131a5f0ec
-rw-r--r--Changelog-Trunk.txt3
-rw-r--r--src/map/script.c12
2 files changed, 10 insertions, 5 deletions
diff --git a/Changelog-Trunk.txt b/Changelog-Trunk.txt
index 87fa2c2d3..d128c53f1 100644
--- a/Changelog-Trunk.txt
+++ b/Changelog-Trunk.txt
@@ -4,6 +4,9 @@ AS OF SVN REV. 5091, WE ARE NOW USING TRUNK. ALL UNTESTED BUGFIXES/FEATURES GO
IF YOU HAVE A WORKING AND TESTED BUGFIX PUT IT INTO STABLE AS WELL AS TRUNK.
2006/06/12
+ * [Optimized]:
+ - buildin_npcshopitem memory allocation to calculate before reallocating.
+ [Lance]
* Made guild member exp an unsigned int. [Skotlex]
* Various cleanups to the npc clicking related functions. Should fix quite
some possible crashes from crafted packets. [Skotlex]
diff --git a/src/map/script.c b/src/map/script.c
index 4bb550a13..6c6f0a624 100644
--- a/src/map/script.c
+++ b/src/map/script.c
@@ -10119,7 +10119,7 @@ int buildin_npcshopitem(struct script_state *st)
struct npc_data *nd= NULL;
int n = 0;
int i = 3;
- int itemid, value;
+ int itemid, value, amount;
char* npcname = conv_str(st, & (st->stack->stack_data[st->start + 2]));
nd = npc_name2id(npcname);
@@ -10129,11 +10129,13 @@ int buildin_npcshopitem(struct script_state *st)
#endif
if(nd && nd->bl.subtype==SHOP){
+ amount = (st->end-2)/2;
+ // st->end - 2 = nameid + value # ... / 2 = number of items ... + 1 just in case
nd = (struct npc_data *)aRealloc(nd,sizeof(struct npc_data) +
- sizeof(nd->u.shop_item[0]) * (MAX_SHOPITEM + 1));
+ sizeof(nd->u.shop_item[0]) * amount);
// Reset sell list.
- for(;nd->u.shop_item[n].nameid && n < MAX_SHOPITEM; n++){
+ for(;nd->u.shop_item[n].nameid && n < amount; n++){
nd->u.shop_item[n].nameid = 0;
nd->u.shop_item[n].value = 0;
}
@@ -10150,8 +10152,8 @@ int buildin_npcshopitem(struct script_state *st)
n++;
}
- nd = (struct npc_data *)aRealloc(nd,sizeof(struct npc_data) +
- sizeof(nd->u.shop_item[0]) * n);
+ //nd = (struct npc_data *)aRealloc(nd,sizeof(struct npc_data) +
+ // sizeof(nd->u.shop_item[0]) * n);
map_addiddb(&nd->bl);