projects
/
open-adventure.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
87c6d3f
)
Use the '=' operator (not memcpy()) to shallow-copy structs.
262/head
author
Jason S. Ninneman
<jsn@mbar.us>
Thu, 3 Aug 2017 19:41:35 +0000
(12:41 -0700)
committer
Jason S. Ninneman
<jsn@mbar.us>
Thu, 3 Aug 2017 19:41:35 +0000
(12:41 -0700)
main.c
patch
|
blob
|
history
saveresume.c
patch
|
blob
|
history
diff --git
a/main.c
b/main.c
index 0eab6e8d19bacb4b49d0e89a655fed530f4633e9..f2e107515a70d212a678a7f47757746d7c01562c 100644
(file)
--- a/
main.c
+++ b/
main.c
@@
-1051,8
+1051,7
@@
Lclearobj:
game.knfloc = 0;
/* Preserve state from last command for reuse when required */
game.knfloc = 0;
/* Preserve state from last command for reuse when required */
- command_t preserve;
- memcpy(&preserve, &command, sizeof(command_t));
+ command_t preserve = command;
// Get command input from user
if (!get_command_input(&command))
// Get command input from user
if (!get_command_input(&command))
@@
-1123,8
+1122,7
@@
Lclearobj:
}
if ((command.word[0].id == WATER || command.word[0].id == OIL) && (command.word[1].id == PLANT || command.word[1].id == DOOR)) {
if (AT(command.word[1].id)) {
}
if ((command.word[0].id == WATER || command.word[0].id == OIL) && (command.word[1].id == PLANT || command.word[1].id == DOOR)) {
if (AT(command.word[1].id)) {
- memcpy(&command.word[1], &command.word[0],
- sizeof(command_word_t));
+ command.word[1] = command.word[0];
command.word[0].id = POUR;
command.word[0].type = ACTION;
strncpy(command.word[0].raw, "pour", LINESIZE - 1);
command.word[0].id = POUR;
command.word[0].type = ACTION;
strncpy(command.word[0].raw, "pour", LINESIZE - 1);
@@
-1137,13
+1135,9
@@
Lclearobj:
/* From OV to VO form */
if (command.word[0].type==OBJECT && command.word[1].type==ACTION) {
/* From OV to VO form */
if (command.word[0].type==OBJECT && command.word[1].type==ACTION) {
- command_word_t stage;
- memcpy(&stage, &command.word[0],
- sizeof(command_word_t));
- memcpy(&command.word[0], &command.word[1],
- sizeof(command_word_t));
- memcpy(&command.word[1], &stage,
- sizeof(command_word_t));
+ command_word_t stage = command.word[0];
+ command.word[0] = command.word[1];
+ command.word[1] = stage;
}
}
}
}
diff --git
a/saveresume.c
b/saveresume.c
index a3dbe968ebdaf4838ea2552d6c77b6e951143721..d8541748fbf25fe573770562028838c65248ac7a 100644
(file)
--- a/
saveresume.c
+++ b/
saveresume.c
@@
-36,7
+36,7
@@
int savefile(FILE *fp, long version)
save.mode = -1;
save.version = (version == 0) ? VRSION : version;
save.mode = -1;
save.version = (version == 0) ? VRSION : version;
-
memcpy(&save.game, &game, sizeof(struct game_t))
;
+
save.game = game
;
IGNORE(fwrite(&save, sizeof(struct save_t), 1, fp));
return (0);
}
IGNORE(fwrite(&save, sizeof(struct save_t), 1, fp));
return (0);
}
@@
-119,7
+119,7
@@
int restore(FILE* fp)
if (save.version != VRSION) {
rspeak(VERSION_SKEW, save.version / 10, MOD(save.version, 10), VRSION / 10, MOD(VRSION, 10));
} else {
if (save.version != VRSION) {
rspeak(VERSION_SKEW, save.version / 10, MOD(save.version, 10), VRSION / 10, MOD(VRSION, 10));
} else {
-
memcpy(&game, &save.game, sizeof(struct game_t))
;
+
game = save.game
;
}
return GO_TOP;
}
}
return GO_TOP;
}