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

This commit is contained in:
Mario Zechner 2022-03-11 18:07:30 +01:00
parent 9cd38191fc
commit f4a92fbfae
4 changed files with 24 additions and 18 deletions

View File

@ -1,6 +1,13 @@
cmake_minimum_required(VERSION 3.17)
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)
message("MSCV detected")
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS}")
@ -8,13 +15,12 @@ if(MSVC)
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_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"))
add_subdirectory(spine-c)
@ -34,4 +40,4 @@ if((${SPINE_COCOS2D_X}) OR (${CMAKE_CURRENT_BINARY_DIR} MATCHES "spine-cocos2dx"
endif()
# add_subdirectory(spine-c/spine-c-unit-tests)
add_subdirectory(spine-cpp/spine-cpp-unit-tests)
add_subdirectory(spine-cpp/spine-cpp-unit-tests)

View File

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

View File

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

View File

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