1
0
mirror of https://salsa.debian.org/games-team/bsdgames synced 2024-11-02 16:37:17 -04:00

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>
This commit is contained in:
Dr. Tobias Quathamer 2018-04-28 15:11:15 +02:00
parent f0929c229b
commit 2991da7809
2 changed files with 68 additions and 0 deletions

View File

@ -0,0 +1,67 @@
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

View File

@ -14,3 +14,4 @@
0014-Add-Debian-acronyms.patch
0015-primes-Update-to-NetBSD-CVS-2018-02-03.patch
0016-Better-explanation-how-to-read-the-documentation.patch
0017-hack-Fix-segv-when-i-inventory-done-after-load-from-.patch