Web lists-archives.com

Bug with hack in bsdgames-2.17-26build1 - SIGSEGV when type 'i' after restoring a saved game - WITH A FIX!




Program hack core dumps when you restore a saved game and then enter 'i' to see Inventory.  The following patch to hack.o_init.c fixes the problem.  (Sorry if cut and paste changed tabs to spaces...)  I am running Ubuntu 17.10, but don't think platform matters.

*** hack.o_init.c.old    2003-12-16 20:47:37.000000000 -0600
--- hack.o_init.c    2018-03-25 20:35:59.362696144 -0600
***************
*** 184,191 ****
      bwrite(fd, (char *) bases, sizeof bases);
      bwrite(fd, (char *) objects, sizeof objects);
      /*
!      * as long as we use only one version of Hack/Quest we need not save
!      * oc_name and oc_descr, but we must save oc_uname for all objects
       */
      for (i = 0; i < SIZE(objects); i++) {
          if (objects[i].oc_uname) {
--- 184,190 ----
      bwrite(fd, (char *) bases, sizeof bases);
      bwrite(fd, (char *) objects, sizeof objects);
      /*
!      * Save oc_name, oc_descr, as well as oc_uname for all objects
       */
      for (i = 0; i < SIZE(objects); i++) {
          if (objects[i].oc_uname) {
***************
*** 193,198 ****
--- 192,207 ----
              bwrite(fd, (char *) &len, sizeof len);
              bwrite(fd, objects[i].oc_uname, len);
          }
+         if (objects[i].oc_name) {
+             len = strlen(objects[i].oc_name) + 1;
+             bwrite(fd, (char *) &len, sizeof len);
+             bwrite(fd, objects[i].oc_name, len);
+         }
+         if (objects[i].oc_descr) {
+             len = strlen(objects[i].oc_descr) + 1;
+             bwrite(fd, (char *) &len, sizeof len);
+             bwrite(fd, objects[i].oc_descr, len);
+         }
      }
  }

***************
*** 205,215 ****
--- 214,236 ----
      mread(fd, (char *) bases, sizeof bases);
      mread(fd, (char *) objects, sizeof objects);
      for (i = 0; i < SIZE(objects); i++)
+     {
          if (objects[i].oc_uname) {
              mread(fd, (char *) &len, sizeof len);
              objects[i].oc_uname = (char *) alloc(len);
              mread(fd, objects[i].oc_uname, len);
          }
+         if (objects[i].oc_name) {
+             mread(fd, (char *) &len, sizeof len);
+             objects[i].oc_name = (char *) alloc(len);
+             mread(fd, objects[i].oc_name, len);
+         }
+         if (objects[i].oc_descr) {
+             mread(fd, (char *) &len, sizeof len);
+             objects[i].oc_descr = (char *) alloc(len);
+             mread(fd, objects[i].oc_descr, len);
+         }
+     }
  }

  int