Selaa lähdekoodia

[c] Fixes #2041, adds sanitizer support via Cmake flag SPINE_SANITIZER=TRUE

Mario Zechner 3 vuotta sitten
vanhempi
commit
f4a92fbfae

+ 13 - 7
CMakeLists.txt

@@ -1,6 +1,13 @@
 cmake_minimum_required(VERSION 3.17)
 cmake_minimum_required(VERSION 3.17)
 project(spine)
 project(spine)
 
 
+set(CMAKE_INSTALL_PREFIX "./")
+set(CMAKE_VERBOSE_MAKEFILE ON)
+set(SPINE_SFML FALSE CACHE BOOL FALSE)
+set(SPINE_COCOS2D_OBJC FALSE CACHE BOOL FALSE)
+set(SPINE_COCOS2D_X FALSE CACHE BOOL FALSE)
+set(SPINE_SANITIZE FALSE CACHE BOOL FALSE)
+
 if(MSVC)
 if(MSVC)
 	message("MSCV detected")
 	message("MSCV detected")
 	set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS}")
 	set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS}")
@@ -8,13 +15,12 @@ if(MSVC)
 else()
 else()
 	set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wunused-value -Wno-c++11-long-long -Wno-variadic-macros -Werror -Wextra -pedantic -Wnonportable-include-path -Wshadow -std=c89")
 	set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wunused-value -Wno-c++11-long-long -Wno-variadic-macros -Werror -Wextra -pedantic -Wnonportable-include-path -Wshadow -std=c89")
 	set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wunused-value -Wno-c++11-long-long -Wno-variadic-macros -Werror -Wextra -Wnon-virtual-dtor -pedantic -Wnonportable-include-path -Wshadow -std=c++11 -fno-exceptions -fno-rtti")
 	set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wunused-value -Wno-c++11-long-long -Wno-variadic-macros -Werror -Wextra -Wnon-virtual-dtor -pedantic -Wnonportable-include-path -Wshadow -std=c++11 -fno-exceptions -fno-rtti")
-endif()
 
 
-set(CMAKE_INSTALL_PREFIX "./")
-set(CMAKE_VERBOSE_MAKEFILE ON)
-set(SPINE_SFML FALSE CACHE BOOL FALSE)
-set(SPINE_COCOS2D_OBJC FALSE CACHE BOOL FALSE)
-set(SPINE_COCOS2D_X FALSE CACHE BOOL FALSE)
+	if (${SPINE_SANITIZE})
+		set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=address -fsanitize=undefined")
+		set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=address -fsanitize=undefined")
+	endif()
+endif()
 
 
 if((${SPINE_SFML}) OR (${CMAKE_CURRENT_BINARY_DIR} MATCHES "spine-sfml"))
 if((${SPINE_SFML}) OR (${CMAKE_CURRENT_BINARY_DIR} MATCHES "spine-sfml"))
 	add_subdirectory(spine-c)
 	add_subdirectory(spine-c)
@@ -34,4 +40,4 @@ if((${SPINE_COCOS2D_X}) OR (${CMAKE_CURRENT_BINARY_DIR} MATCHES "spine-cocos2dx"
 endif()
 endif()
 
 
 # add_subdirectory(spine-c/spine-c-unit-tests)
 # add_subdirectory(spine-c/spine-c-unit-tests)
-add_subdirectory(spine-cpp/spine-cpp-unit-tests)
+add_subdirectory(spine-cpp/spine-cpp-unit-tests)

+ 1 - 1
spine-c/spine-c/src/spine/SkeletonBinary.c

@@ -1189,7 +1189,7 @@ spSkeletonData *spSkeletonBinary_readSkeletonData(spSkeletonBinary *self, const
 	highHash = readInt(input);
 	highHash = readInt(input);
 	sprintf(buffer, "%x%x", highHash, lowHash);
 	sprintf(buffer, "%x%x", highHash, lowHash);
 	buffer[31] = 0;
 	buffer[31] = 0;
-	skeletonData->hash = strdup(buffer);
+	MALLOC_STR(skeletonData->hash, buffer);
 
 
 	skeletonData->version = readString(input);
 	skeletonData->version = readString(input);
 	if (!strlen(skeletonData->version)) {
 	if (!strlen(skeletonData->version)) {

+ 10 - 6
spine-c/spine-c/src/spine/SkeletonJson.c

@@ -34,10 +34,6 @@
 #include <spine/extension.h>
 #include <spine/extension.h>
 #include <stdio.h>
 #include <stdio.h>
 
 
-#if defined(WIN32) || defined(_WIN32) || defined(__WIN32) && !defined(__CYGWIN__)
-#define strdup _strdup
-#endif
-
 typedef struct {
 typedef struct {
 	const char *parent;
 	const char *parent;
 	const char *skin;
 	const char *skin;
@@ -938,9 +934,17 @@ spSkeletonData *spSkeletonJson_readSkeletonData(spSkeletonJson *self, const char
 		skeletonData->height = Json_getFloat(skeleton, "height", 0);
 		skeletonData->height = Json_getFloat(skeleton, "height", 0);
 		skeletonData->fps = Json_getFloat(skeleton, "fps", 30);
 		skeletonData->fps = Json_getFloat(skeleton, "fps", 30);
 		skeletonData->imagesPath = Json_getString(skeleton, "images", 0);
 		skeletonData->imagesPath = Json_getString(skeleton, "images", 0);
-		if (skeletonData->imagesPath) skeletonData->imagesPath = strdup(skeletonData->imagesPath);
+		if (skeletonData->imagesPath) {
+			char *tmp = NULL;
+			MALLOC_STR(tmp, skeletonData->imagesPath);
+			skeletonData->imagesPath = tmp;
+		}
 		skeletonData->audioPath = Json_getString(skeleton, "audio", 0);
 		skeletonData->audioPath = Json_getString(skeleton, "audio", 0);
-		if (skeletonData->audioPath) skeletonData->audioPath = strdup(skeletonData->audioPath);
+		if (skeletonData->audioPath) {
+			char *tmp = NULL;
+			MALLOC_STR(tmp, skeletonData->audioPath);
+			skeletonData->audioPath = tmp;
+		}
 	}
 	}
 
 
 	/* Bones. */
 	/* Bones. */

+ 0 - 4
spine-cpp/spine-cpp/src/spine/SkeletonJson.cpp

@@ -73,10 +73,6 @@
 #include <spine/TranslateTimeline.h>
 #include <spine/TranslateTimeline.h>
 #include <spine/Vertices.h>
 #include <spine/Vertices.h>
 
 
-#if defined(WIN32) || defined(_WIN32) || defined(__WIN32) && !defined(__CYGWIN__)
-#define strdup _strdup
-#endif
-
 using namespace spine;
 using namespace spine;
 
 
 static float toColor(const char *value, size_t index) {
 static float toColor(const char *value, size_t index) {