diff options
author | Max Horn | 2009-05-05 12:23:05 +0000 |
---|---|---|
committer | Max Horn | 2009-05-05 12:23:05 +0000 |
commit | 7e51eb647842e03326eb4b1d41401538f9903eb6 (patch) | |
tree | 1a288bac72f0e0dcd7da2acaa5d67ac99384493e /engines/sci/engine | |
parent | 29809407887bbc178a49f215e08f18918e41c4e7 (diff) | |
download | scummvm-rg350-7e51eb647842e03326eb4b1d41401538f9903eb6.tar.gz scummvm-rg350-7e51eb647842e03326eb4b1d41401538f9903eb6.tar.bz2 scummvm-rg350-7e51eb647842e03326eb4b1d41401538f9903eb6.zip |
SCI: Actually, it turns out the SystemString is more messed up than I thought: In some places it allocates a memory block of max_size bytes; sometimes max_size+1 bytes; and sometimes max_size*sizeof(reg_t) bytes. And sometimes strings frags are accessed as plain C strings (e.g. when saved), sometimes as a string encode as a series of reg_t values. Ouch :/
svn-id: r40324
Diffstat (limited to 'engines/sci/engine')
-rw-r--r-- | engines/sci/engine/game.cpp | 10 | ||||
-rw-r--r-- | engines/sci/engine/savegame.cpp | 6 |
2 files changed, 8 insertions, 8 deletions
diff --git a/engines/sci/engine/game.cpp b/engines/sci/engine/game.cpp index c9e8755c5d..e35386dbd4 100644 --- a/engines/sci/engine/game.cpp +++ b/engines/sci/engine/game.cpp @@ -433,9 +433,9 @@ int script_init_engine(EngineState *s, sci_version_t version) { SystemString *str = &s->sys_strings->strings[SYS_STRING_SAVEDIR]; str->name = strdup("savedir"); str->max_size = MAX_SAVE_DIR_SIZE; - str->value = (reg_t*)sci_malloc(sizeof(reg_t)*MAX_SAVE_DIR_SIZE); - str->value->segment = s->string_frag_segment; // Set to empty string - str->value->offset = 0; + str->value = (reg_t *)calloc(MAX_SAVE_DIR_SIZE, sizeof(reg_t)); // FIXME -- sizeof(char) or sizeof(reg_t) ?? + str->value[0].segment = s->string_frag_segment; // Set to empty string + str->value[0].offset = 0; s->save_dir_copy = make_reg(s->sys_strings_segment, SYS_STRING_SAVEDIR); @@ -481,7 +481,7 @@ int script_init_engine(EngineState *s, sci_version_t version) { void script_set_gamestate_save_dir(EngineState *s, const char *path) { SystemString *str = &s->sys_strings->strings[SYS_STRING_SAVEDIR]; - strncpy((char *)str->value, path, str->max_size); + strncpy((char *)str->value, path, str->max_size); // FIXME -- strncpy or internal_stringfrag_strncpy ? str->value[str->max_size - 1].segment = s->string_frag_segment; // Make sure to terminate str->value[str->max_size - 1].offset &= 0xff00; // Make sure to terminate } @@ -576,7 +576,7 @@ int game_init(EngineState *s) { SystemString *str = &s->sys_strings->strings[SYS_STRING_PARSER_BASE]; str->name = strdup("parser-base"); str->max_size = MAX_PARSER_BASE; - str->value = (reg_t*)sci_malloc(MAX_PARSER_BASE + 1); + str->value = (reg_t *)calloc(MAX_PARSER_BASE + 1, sizeof(char)); // FIXME -- sizeof(char) or sizeof(reg_t) ?? str->value[0].segment = s->string_frag_segment; // Set to empty string str->value[0].offset = 0; // Set to empty string diff --git a/engines/sci/engine/savegame.cpp b/engines/sci/engine/savegame.cpp index 83cd125f11..a8f803c259 100644 --- a/engines/sci/engine/savegame.cpp +++ b/engines/sci/engine/savegame.cpp @@ -846,10 +846,10 @@ EngineState *gamestate_restore(EngineState *s, Common::SeekableReadStream *fh) { // First, pad memory for (int i = 0; i < SYS_STRINGS_MAX; i++) { str = &retval->sys_strings->strings[i]; - char *data = (char *) str->value; + char *data = (char *)str->value; if (data) { - str->value = (reg_t *)sci_malloc(str->max_size + 1); - strcpy((char *)str->value, data); + str->value = (reg_t *)calloc(str->max_size+1, sizeof(char)); // FIXME -- sizeof(char) or sizeof(reg_t) ?? + strncpy((char *)str->value, data, str->max_size+1); // FIXME -- strncpy or internal_stringfrag_strncpy ? free(data); } } |