diff options
author | Filippos Karapetis | 2010-07-02 10:38:42 +0000 |
---|---|---|
committer | Filippos Karapetis | 2010-07-02 10:38:42 +0000 |
commit | dcb92c83521794af87fc64f941e7d3bf71818c36 (patch) | |
tree | 51773134466f2c19724d78106caec7997363aefe /engines/sci/engine/seg_manager.cpp | |
parent | 79768098b13e20bade076b8a36c9d8cd16514b2a (diff) | |
download | scummvm-rg350-dcb92c83521794af87fc64f941e7d3bf71818c36.tar.gz scummvm-rg350-dcb92c83521794af87fc64f941e7d3bf71818c36.tar.bz2 scummvm-rg350-dcb92c83521794af87fc64f941e7d3bf71818c36.zip |
Add checks for null reference to strncpy() and strlen() - happens for example when trying to talk to inanimate objects in KQ6
svn-id: r50596
Diffstat (limited to 'engines/sci/engine/seg_manager.cpp')
-rw-r--r-- | engines/sci/engine/seg_manager.cpp | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/engines/sci/engine/seg_manager.cpp b/engines/sci/engine/seg_manager.cpp index 339920936f..ef2279e492 100644 --- a/engines/sci/engine/seg_manager.cpp +++ b/engines/sci/engine/seg_manager.cpp @@ -643,6 +643,14 @@ void SegManager::strncpy(reg_t dest, const char* src, size_t n) { } void SegManager::strncpy(reg_t dest, reg_t src, size_t n) { + if (src.isNull()) { + // Clear target string instead. + if (n > 0) + strcpy(dest, ""); + + return; // empty text + } + SegmentRef dest_r = dereference(dest); const SegmentRef src_r = dereference(src); if (!src_r.isValid()) { @@ -770,6 +778,9 @@ void SegManager::memcpy(byte *dest, reg_t src, size_t n) { } size_t SegManager::strlen(reg_t str) { + if (str.isNull()) + return 0; // empty text + SegmentRef str_r = dereference(str); if (!str_r.isValid()) { warning("Attempt to call strlen on invalid pointer %04x:%04x", PRINT_REG(str)); |