Browse Source

Fixed a potential null pointer dereference and a case of undefined behaviour

Alex Szpakowski 11 years ago
parent
commit
f05551a01f
3 changed files with 5 additions and 2 deletions
  1. 1 1
      src/common/StringMap.h
  2. 1 1
      src/common/runtime.cpp
  3. 3 0
      src/modules/graphics/opengl/wrap_Mesh.cpp

+ 1 - 1
src/common/StringMap.h

@@ -126,7 +126,7 @@ public:
 
 		if (index >= SIZE)
 		{
-			printf("\nConstant %s out of bounds with %i!\n", key, index);
+			printf("Constant %s out of bounds with %u!\n", key, index);
 			return false;
 		}
 

+ 1 - 1
src/common/runtime.cpp

@@ -538,7 +538,7 @@ int luax_insist(lua_State *L, int idx, const char *k)
 {
 	// Convert to absolute index if necessary.
 	if (idx < 0 && idx > LUA_REGISTRYINDEX)
-		idx = lua_gettop(L) + ++idx;
+		idx += lua_gettop(L) + 1;
 
 	lua_getfield(L, idx, k);
 

+ 3 - 0
src/modules/graphics/opengl/wrap_Mesh.cpp

@@ -147,6 +147,9 @@ int w_Mesh_getVertices(lua_State *L)
 	size_t count = t->getVertexCount();
 	lua_createtable(L, count, 0);
 
+	if (count == 0 || vertices == nullptr)
+		return 1;
+
 	for (size_t i = 0; i < count; i++)
 	{
 		// Create vertex table.