[Scummvm-cvs-logs] scummvm master -> 919e577ba665002c1513b53a755cb1d663b99f7e

lordhoto lordhoto at gmail.com
Sun Nov 3 18:48:03 CET 2013


This automated email contains information about 1 new commit which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .

Summary:
919e577ba6 SDL: Fix invalid memory access in getSystemLanguage.


Commit: 919e577ba665002c1513b53a755cb1d663b99f7e
    https://github.com/scummvm/scummvm/commit/919e577ba665002c1513b53a755cb1d663b99f7e
Author: Johannes Schickel (lordhoto at scummvm.org)
Date: 2013-11-03T09:47:03-08:00

Commit Message:
SDL: Fix invalid memory access in getSystemLanguage.

A call to setlocale can invalidate the string a previous setlocale call
returned. Instead of saving a pointer we copy the returned string now. This,
for example, fixes invalid memory access on my system.

See de8da01b0e8a309b9ed3f5b0f152ebbcf8f4af37 for the commit introducing the
invalid memory access.

Changed paths:
    backends/platform/sdl/sdl.cpp



diff --git a/backends/platform/sdl/sdl.cpp b/backends/platform/sdl/sdl.cpp
index 508c5f4..bc80d8a 100644
--- a/backends/platform/sdl/sdl.cpp
+++ b/backends/platform/sdl/sdl.cpp
@@ -392,7 +392,7 @@ Common::String OSystem_SDL::getSystemLanguage() const {
 	}
 #else // WIN32
 	// Activating current locale settings
-	const char *locale = setlocale(LC_ALL, "");
+	const Common::String locale = setlocale(LC_ALL, "");
  
 	// Restore default C locale to prevent issues with
 	// portability of sscanf(), atof(), etc.
@@ -400,7 +400,7 @@ Common::String OSystem_SDL::getSystemLanguage() const {
 	setlocale(LC_ALL, "C");
 
 	// Detect the language from the locale
-	if (!locale) {
+	if (locale.empty()) {
 		return ModularBackend::getSystemLanguage();
 	} else {
 		int length = 0;
@@ -409,14 +409,14 @@ Common::String OSystem_SDL::getSystemLanguage() const {
 		// ".UTF-8" or the like. We do this, since
 		// our translation languages are usually
 		// specified without any charset information.
-		for (int i = 0; locale[i]; ++i, ++length) {
+		for (int size = locale.size(); length < size; ++length) {
 			// TODO: Check whether "@" should really be checked
 			// here.
-			if (locale[i] == '.' || locale[i] == ' ' || locale[i] == '@')
+			if (locale[length] == '.' || locale[length] == ' ' || locale[length] == '@')
 				break;
 		}
 
-		return Common::String(locale, length);
+		return Common::String(locale.c_str(), length);
 	}
 #endif // WIN32
 #else // USE_DETECTLANG






More information about the Scummvm-git-logs mailing list