[Bf-blender-cvs] [b2e5c01] master: BGE: correct ftell use in LoadGlobalDict

Jorge Bernal noreply at git.blender.org
Fri Jun 5 03:17:46 CEST 2015


Commit: b2e5c017a1a93ec9b6f001bae385c7cc9b756cca
Author: Jorge Bernal
Date:   Fri Jun 5 11:14:09 2015 +1000
Branches: master
https://developer.blender.org/rBb2e5c017a1a93ec9b6f001bae385c7cc9b756cca

BGE: correct ftell use in LoadGlobalDict

===================================================================

M	source/gameengine/Ketsji/KX_GameActuator.cpp
M	source/gameengine/Ketsji/KX_PythonInit.cpp

===================================================================

diff --git a/source/gameengine/Ketsji/KX_GameActuator.cpp b/source/gameengine/Ketsji/KX_GameActuator.cpp
index c6087ac..a23af68 100644
--- a/source/gameengine/Ketsji/KX_GameActuator.cpp
+++ b/source/gameengine/Ketsji/KX_GameActuator.cpp
@@ -178,6 +178,11 @@ bool KX_GameActuator::Update()
 					// obtain file size:
 					fseek (fp , 0 , SEEK_END);
 					marshal_length = ftell(fp);
+					if (marshal_length == -1) {
+						printf("warning: could not read position of '%s'\n", mashal_path);
+						fclose(fp);
+						break;
+					}
 					rewind(fp);
 					
 					marshal_buffer = (char*) malloc (sizeof(char)*marshal_length);
diff --git a/source/gameengine/Ketsji/KX_PythonInit.cpp b/source/gameengine/Ketsji/KX_PythonInit.cpp
index f7048f1..6fdc53f 100644
--- a/source/gameengine/Ketsji/KX_PythonInit.cpp
+++ b/source/gameengine/Ketsji/KX_PythonInit.cpp
@@ -356,7 +356,7 @@ static PyObject *gPyLoadGlobalDict(PyObject *)
 {
 	char marshal_path[512];
 	char *marshal_buffer = NULL;
-	size_t marshal_length;
+	int marshal_length;
 	FILE *fp = NULL;
 	int result;
 
@@ -367,7 +367,12 @@ static PyObject *gPyLoadGlobalDict(PyObject *)
 	if (fp) {
 		// obtain file size:
 		fseek (fp, 0, SEEK_END);
-		marshal_length = (size_t)ftell(fp);
+		marshal_length = ftell(fp);
+		if (marshal_length == -1) {
+			printf("Warning: could not read position of '%s'\n", marshal_path);
+			fclose(fp);
+			Py_RETURN_NONE;
+		}
 		rewind(fp);
 
 		marshal_buffer = (char*)malloc (sizeof(char)*marshal_length);




More information about the Bf-blender-cvs mailing list