Menu ▾ ▴

#69 Segfault with IMPutSlot of subclass instance

1.0
closed
None
2022-01-08
2021-12-30
noxdafox
No

When executing the following code, in most of the cases a segfault follows. In some cases, a wrong value is set for the slot.

#include "clips.h"


int main()
{
    Environment *environment;
    Instance *instance;
    InstanceModifier *modifier;

    environment = CreateEnvironment();

    Build(environment,
          "(defclass MYCLASS (is-a USER)"
          "   (slot One))");
    Build(environment,
          "(defclass MYSUBCLASS (is-a MYCLASS)"
          "   (slot Two))");

    instance = MakeInstance(environment, "(p1 of MYSUBCLASS (One 1) (Two 2))");

    modifier = CreateInstanceModifier(environment, instance);
    IMPutSlotInteger(modifier, "One", 1);
    IMPutSlotInteger(modifier, "Two", 2);  // Segfault here

    IMModify(modifier);

    IMDispose(modifier);
    DestroyEnvironment(environment);
}

The segfault occurs when calling Release on oldValue. oldValue->header appears to be NULL. I suspect the issue being caused by FindInstanceTemplateSlot returning the wrong slot id (stored in whichSlot) in case of a subclass.

Discussion

  • Gary Riley

    Gary Riley - 2022-01-08
    • status: new --> closed
    • assigned_to: Gary Riley
     
  • Gary Riley

    Gary Riley - 2022-01-08

    Checked in a fix to the 64x branch of the sourceforge code repository.

     

Log in to post a comment.