1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
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
|