diff options
Diffstat (limited to 'src/map/clif.c')
-rw-r--r-- | src/map/clif.c | 23 |
1 files changed, 18 insertions, 5 deletions
diff --git a/src/map/clif.c b/src/map/clif.c index eb67723e2..80eb7796a 100644 --- a/src/map/clif.c +++ b/src/map/clif.c @@ -10534,16 +10534,29 @@ void clif_parse_NpcBuyListSend(int fd, struct map_session_data* sd) __attribute_ /// 00c8 <packet len>.W { <amount>.W <name id>.W }* void clif_parse_NpcBuyListSend(int fd, struct map_session_data* sd) { - int n = (RFIFOW(fd,2)-4) /4; + int n = ((int)RFIFOW(fd,2)-4) / 4; int result; + Assert_retv(n >= 0); + if( sd->state.trading || !sd->npc_shopid || pc_has_permission(sd,PC_PERM_DISABLE_STORE) ) { result = 1; } else { - unsigned short *item_list = aMalloc(sizeof(*item_list) * 2 * n); - memcpy(item_list, RFIFOP(fd,4), sizeof(*item_list) * 2 * n); - result = npc->buylist(sd,n,item_list); - aFree(item_list); + struct itemlist item_list = { 0 }; + int i; + + VECTOR_INIT(item_list); + VECTOR_ENSURE(item_list, n, 1); + for (i = 0; i < n; i++) { + struct itemlist_entry entry = { 0 }; + + entry.amount = RFIFOW(fd, 4 + 4 * i); + entry.id = RFIFOW(fd, 4 + 4 * i + 2); + + VECTOR_PUSH(item_list, entry); + } + result = npc->buylist(sd, &item_list); + VECTOR_CLEAR(item_list); } sd->npc_shopid = 0; //Clear shop data. |