From f2c4ffeb60f6049980a1e829b0e44ce8fe574881 Mon Sep 17 00:00:00 2001 From: jasonch35 Date: Wed, 29 Jan 2025 23:53:27 +0800 Subject: [PATCH] Allocate only required number of rows retrieved from SQL - Limit rows to MAX_STORAGE, as additional rows are unnecessary. - Loops based on capped number of rows so we avoid iterating empty items --- src/char/int_storage.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/char/int_storage.c b/src/char/int_storage.c index db3b488ba89..f9d447759e1 100644 --- a/src/char/int_storage.c +++ b/src/char/int_storage.c @@ -188,10 +188,12 @@ static int inter_storage_fromsql(int account_id, int storage_id, struct storage_ StrBuf->Destroy(&buf); - if (SQL->NumRows(inter->sql_handle) > 0) { - VECTOR_ENSURE(p->item, MAX_STORAGE, 1); + int num_rows = SQL->NumRows(inter->sql_handle) > MAX_STORAGE ? MAX_STORAGE : (int)SQL->NumRows(inter->sql_handle); - for (int j = 0; j < MAX_STORAGE && SQL_SUCCESS == SQL->NextRow(inter->sql_handle); ++j) { + if (num_rows > 0) { + VECTOR_ENSURE(p->item, num_rows, 1); + + for (int j = 0; j < num_rows && SQL_SUCCESS == SQL->NextRow(inter->sql_handle); ++j) { struct item item = { 0 }; SQL->GetData(inter->sql_handle, 0, &data, NULL); item.id = atoi(data); SQL->GetData(inter->sql_handle, 1, &data, NULL); item.nameid = atoi(data);