strange object vs generic objects

Try to fix a fuzzer issue.  I wasn't able to reproduce it so am not
sure whether this actually fixes it.  A mimic seemed to be mimicking
object #1 (generic ILLOBJ_CLASS object which shouldn't occur) rather
than #0 (strange object).  Strange object always has dknown==1 and
generic objects should always have dknown==0 but farlook of mystery
object #1 had its dknown flag set.

An earlier fix to force non-Null oc_name when formatting objects in
order to pacify the static analyzer might have been the reason that
the problem couldn't be reproduced.

This includes a few miscellaneous changes made while unsuccessfully
hunting for the problem.
This commit is contained in:
PatR
2023-01-15 01:45:14 -08:00
parent 6abb12aee0
commit 2e1f52e882
5 changed files with 25 additions and 19 deletions

View File

@@ -789,7 +789,7 @@ unknow_object(struct obj *obj)
obj->known = objects[obj->otyp].oc_uses_known ? 0 : 1;
}
/* mksobj(): create a specific type of object; result it always non-Null */
/* mksobj(): create a specific type of object; result is always non-Null */
struct obj *
mksobj(int otyp, boolean init, boolean artif)
{

View File

@@ -182,7 +182,9 @@ init_objects(void)
prevoclass = (int) oclass;
}
/* extra entry allows deriving the range of a class via
bases[class] through bases[class+1]-1 for all classes */
bases[class] through bases[class+1]-1 for all classes
(except for ILLOBJ_CLASS which is separated from WEAPON_CLASS
by generic objects) */
gb.bases[MAXOCLASSES] = NUM_OBJECTS;
/* hypothetically someone might remove all objects of some class,
or be adding a new class and not populated it yet, leaving gaps
@@ -228,13 +230,16 @@ init_oclass_probs(void)
int oclass;
for (oclass = 0; oclass < MAXOCLASSES; ++oclass) {
sum = 0;
/* note: for ILLOBJ_CLASS, bases[oclass+1]-1 isn't the last item
in the class; but all the generic items have probability 0 so
adding them to 'sum' has no impact */
for (i = gb.bases[oclass]; i < gb.bases[oclass + 1]; ++i) {
sum += objects[i].oc_prob;
}
if (sum <= 0 && oclass != ILLOBJ_CLASS
&& gb.bases[oclass] != gb.bases[oclass + 1]) {
impossible("zero or negative probability total for oclass %d",
oclass);
impossible("%s (%d) probability total for oclass %d",
!sum ? "zero" : "negative", sum, oclass);
/* gracefully fail by setting all members of this class to 1 */
for (i = gb.bases[oclass]; i < gb.bases[oclass + 1]; ++i) {
objects[i].oc_prob = 1;

View File

@@ -296,8 +296,10 @@ object_from_map(int glyph, coordxy x, coordxy y, struct obj **obj_p)
}
static void
look_at_object(char *buf, /* output buffer */
coordxy x, coordxy y, int glyph)
look_at_object(
char *buf, /* output buffer */
coordxy x, coordxy y,
int glyph)
{
struct obj *otmp = 0;
boolean fakeobj = object_from_map(glyph, x, y, &otmp);