1
0
mirror of https://salsa.debian.org/games-team/bsdgames synced 2024-11-02 16:37:17 -04:00
bsdgames/debian/patches/0017-hack-Fix-segv-when-i-inventory-done-after-load-from-.patch
Dr. Tobias Quathamer 2991da7809 hack: Fix segv when 'i' (inventory) done after load from saved game.
Not all name information was saved or recovered leaving pointers to
nothing.

Thanks: Richard Henschel <rhenschel@accesscomm.ca>
2018-04-28 15:11:15 +02:00

68 lines
2.0 KiB
Diff

From: "Dr. Tobias Quathamer" <toddy@debian.org>
Date: Sat, 28 Apr 2018 15:09:16 +0200
Subject: hack: Fix segv when 'i' (inventory) done after load from saved game.
Not all name information was saved or recovered leaving pointers to
nothing.
Thanks: Richard Henschel <rhenschel@accesscomm.ca>
---
hack/hack.o_init.c | 25 +++++++++++++++++++++++--
1 file changed, 23 insertions(+), 2 deletions(-)
diff --git a/hack/hack.o_init.c b/hack/hack.o_init.c
index dc5bf93..fdab26e 100644
--- a/hack/hack.o_init.c
+++ b/hack/hack.o_init.c
@@ -184,8 +184,7 @@ savenames(fd)
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
+ * 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,6 +192,16 @@ savenames(fd)
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,11 +214,23 @@ restnames(fd)
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