[Scummvm-cvs-logs] SF.net SVN: scummvm:[50596] scummvm/trunk/engines/sci/engine/seg_manager. cpp

thebluegr at users.sourceforge.net thebluegr at users.sourceforge.net
Fri Jul 2 12:38:43 CEST 2010


Revision: 50596
          http://scummvm.svn.sourceforge.net/scummvm/?rev=50596&view=rev
Author:   thebluegr
Date:     2010-07-02 10:38:42 +0000 (Fri, 02 Jul 2010)

Log Message:
-----------
Add checks for null reference to strncpy() and strlen() - happens for example when trying to talk to inanimate objects in KQ6

Modified Paths:
--------------
    scummvm/trunk/engines/sci/engine/seg_manager.cpp

Modified: scummvm/trunk/engines/sci/engine/seg_manager.cpp
===================================================================
--- scummvm/trunk/engines/sci/engine/seg_manager.cpp	2010-07-02 10:18:11 UTC (rev 50595)
+++ scummvm/trunk/engines/sci/engine/seg_manager.cpp	2010-07-02 10:38:42 UTC (rev 50596)
@@ -643,6 +643,14 @@
 }
 
 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 @@
 }
 
 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));


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.




More information about the Scummvm-git-logs mailing list