diff --git a/src/kernel/equipment.c b/src/kernel/equipment.c index 150a70e65..bf3c354b2 100644 --- a/src/kernel/equipment.c +++ b/src/kernel/equipment.c @@ -142,15 +142,13 @@ void equip_unit_mask(struct unit *u, const struct equipment *eq, int mask) if (mask & EQUIP_SPELLS) { quicklist *ql = eq->spells; if (ql) { + int qi; sc_mage *m = get_mage(u); - if (m == NULL) { - assert(!"trying to equip spells on a non-mage!"); - } else { - int qi; - for (qi = 0; ql; ql_advance(&ql, &qi, 1)) { - spell *sp = (spell *) ql_get(ql, qi); - add_spell(get_spelllist(m, u->faction), sp); - } + + assert(m || !"trying to equip spells on a non-mage!"); + for (qi = 0; ql; ql_advance(&ql, &qi, 1)) { + spell *sp = (spell *) ql_get(ql, qi); + add_spell(&m->spells, sp); } } } diff --git a/src/util/quicklist.c b/src/util/quicklist.c index 42941f086..81bad276b 100644 --- a/src/util/quicklist.c +++ b/src/util/quicklist.c @@ -20,7 +20,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include #define QL_MAXSIZE 14 /* total struct is 64 bytes */ -#define QL_LIMIT 8 +#define QL_LIMIT 7 struct quicklist { struct quicklist *next; @@ -89,7 +89,7 @@ int ql_delete(quicklist ** qlp, int index) if (ql->num_elements == 0) { *qlp = ql->next; free(ql); - } else if (ql->next && ql->num_elements < QL_LIMIT) { + } else if (ql->next && ql->num_elements <= QL_LIMIT) { quicklist *qn = ql->next; if (ql->num_elements + qn->num_elements > QL_MAXSIZE) { memcpy(ql->elements + ql->num_elements, qn->elements, sizeof(void *)); @@ -124,10 +124,10 @@ int ql_insert(quicklist ** qlp, int index, void *data) quicklist *qn = (quicklist *) malloc(sizeof(quicklist)); qn->next = ql->next; ql->next = qn; - qn->num_elements = QL_LIMIT; - ql->num_elements -= QL_LIMIT; + qn->num_elements = ql->num_elements-QL_LIMIT; + ql->num_elements = QL_LIMIT; memcpy(qn->elements, ql->elements + ql->num_elements, - QL_LIMIT * sizeof(void *)); + qn->num_elements * sizeof(void *)); if (index <= ql->num_elements) { return ql_insert(qlp, index, data); } else {