mirror of
https://github.com/glest/glest-source.git
synced 2025-08-29 10:49:48 +02:00
- updated cmake to check for support of backtraces in gcc compiler
- fixed numerous bugs / warnings from cppcheck
This commit is contained in:
@@ -33,7 +33,8 @@
|
||||
using Shared::Platform::Mutex;
|
||||
|
||||
// START - For gcc backtrace
|
||||
#if defined(__GNUC__) && !defined(__MINGW32__) && !defined(__FreeBSD__) && !defined(BSD)
|
||||
//#if defined(__GNUC__) && !defined(__MINGW32__) && !defined(__FreeBSD__) && !defined(BSD)
|
||||
#if defined(HAS_GCC_BACKTRACE)
|
||||
#include <execinfo.h>
|
||||
#include <cxxabi.h>
|
||||
#include <signal.h>
|
||||
@@ -78,7 +79,8 @@ public:
|
||||
: ptr(ptr), file(file), line(line), bytes(bytes), array(array), freetouse(false), inuse(true), stack(stacktrace) {
|
||||
}
|
||||
|
||||
#if defined(__GNUC__) && !defined(__FreeBSD__) && !defined(BSD)
|
||||
//#if defined(__GNUC__) && !defined(__FreeBSD__) && !defined(BSD)
|
||||
#if defined(HAS_GCC_BACKTRACE)
|
||||
inline static int getFileAndLine(char *function, void *address, char *file, size_t flen) {
|
||||
int line=-1;
|
||||
if(want_full_leak_stacktrace_line_numbers == true && AllocInfo::get_application_binary() != "") {
|
||||
@@ -171,7 +173,8 @@ public:
|
||||
#endif
|
||||
|
||||
inline static string getStackTrace() {
|
||||
#if defined(__GNUC__) && !defined(__MINGW32__) && !defined(__FreeBSD__) && !defined(BSD)
|
||||
//#if defined(__GNUC__) && !defined(__MINGW32__) && !defined(__FreeBSD__) && !defined(BSD)
|
||||
#if defined(HAS_GCC_BACKTRACE)
|
||||
if(want_full_leak_stacktrace == true) {
|
||||
string errMsg = "\nStack Trace:\n";
|
||||
//errMsg += "To find line #'s use:\n";
|
||||
|
@@ -547,7 +547,7 @@ int getLastSocketError() {
|
||||
}
|
||||
|
||||
const char * getLastSocketErrorText(int *errNumber) {
|
||||
int errId = (errNumber != NULL ? *errNumber : getLastSocketError());
|
||||
//int errId = (errNumber != NULL ? *errNumber : getLastSocketError());
|
||||
//return WSAGetLastErrorMessage("",errId);
|
||||
return "?";
|
||||
}
|
||||
|
@@ -326,15 +326,15 @@ const char* findFont(const char *firstFontToTry,const char *firstFontFamilyToTry
|
||||
#define CHECK_FONT_PATH(filename,fontFamily) \
|
||||
{ \
|
||||
path = filename; \
|
||||
if( !font && path && strlen(path) > 0 && fileExists(path) == true ) { \
|
||||
if( font == NULL && path != NULL && strlen(path) > 0 && fileExists(path) == true ) { \
|
||||
font = strdup(path); \
|
||||
} \
|
||||
if(SystemFlags::VERBOSE_MODE_ENABLED) printf("#1 Searching for font file [%s] result [%s]\n",path,font); \
|
||||
if( !font && fontFamily != NULL && strlen(fontFamily) > 0) { \
|
||||
if( font != NULL && fontFamily != NULL && strlen(fontFamily) > 0) { \
|
||||
string fileFound = findFontFamily(font, fontFamily); \
|
||||
if(fileFound != "") { \
|
||||
path = fileFound.c_str(); \
|
||||
if( !font && path && strlen(path) > 0 && fileExists(path) == true ) { \
|
||||
if( font != NULL && path && strlen(path) > 0 && fileExists(path) == true ) { \
|
||||
font = strdup(path); \
|
||||
} \
|
||||
} \
|
||||
@@ -343,8 +343,8 @@ const char* findFont(const char *firstFontToTry,const char *firstFontFamilyToTry
|
||||
}
|
||||
|
||||
string tryFont = "";
|
||||
if(firstFontToTry || firstFontFamilyToTry) {
|
||||
if(firstFontToTry && strlen(firstFontToTry) > 0) {
|
||||
if(firstFontToTry != NULL || firstFontFamilyToTry != NULL) {
|
||||
if(firstFontToTry != NULL && strlen(firstFontToTry) > 0) {
|
||||
tryFont = firstFontToTry;
|
||||
#ifdef WIN32
|
||||
replaceAll(tryFont, "/", "\\");
|
||||
|
@@ -449,6 +449,7 @@ void PixmapIoPng::openWrite(const string &path, int w, int h, int components) {
|
||||
void PixmapIoPng::write(uint8 *pixels) {
|
||||
|
||||
// initialize stuff
|
||||
/*
|
||||
std::auto_ptr<png_byte*> imrow(new png_byte*[h]);
|
||||
for(int i = 0; i < h; ++i) {
|
||||
imrow.get()[i] = pixels+(h-1-i) * w * components;
|
||||
@@ -470,8 +471,31 @@ void PixmapIoPng::write(uint8 *pixels) {
|
||||
png_write_info(imgp, infop);
|
||||
png_write_image(imgp, imrow.get());
|
||||
png_write_end(imgp, NULL);
|
||||
*/
|
||||
png_bytep *imrow = new png_bytep[h];
|
||||
//png_bytep *imrow = (png_bytep*) malloc(sizeof(png_bytep) * height);
|
||||
for(int i = 0; i < h; ++i) {
|
||||
imrow[i] = pixels + (h-1-i) * w * components;
|
||||
}
|
||||
|
||||
png_structp imgp = png_create_write_struct(PNG_LIBPNG_VER_STRING,0,0,0);
|
||||
png_infop infop = png_create_info_struct(imgp);
|
||||
png_init_io(imgp, file);
|
||||
|
||||
int color_type = PNG_COLOR_TYPE_RGB;
|
||||
if(components == 4) {
|
||||
color_type = PNG_COLOR_TYPE_RGBA;
|
||||
}
|
||||
png_set_IHDR(imgp, infop, w, h,
|
||||
8, color_type, PNG_INTERLACE_NONE,
|
||||
PNG_COMPRESSION_TYPE_BASE, PNG_FILTER_TYPE_BASE);
|
||||
|
||||
// write file
|
||||
png_write_info(imgp, infop);
|
||||
png_write_image(imgp, imrow);
|
||||
png_write_end(imgp, NULL);
|
||||
|
||||
delete [] imrow;
|
||||
|
||||
/*
|
||||
// Allocate write & info structures
|
||||
|
@@ -503,7 +503,7 @@ void MapPreview::reset(int w, int h, float alt, MapSurfaceType surf) {
|
||||
char szBuf[1024]="";
|
||||
sprintf(szBuf,"Size of map must be at least %dx%d",MIN_MAP_CELL_DIMENSION,MIN_MAP_CELL_DIMENSION);
|
||||
throw megaglest_runtime_error(szBuf);
|
||||
return;
|
||||
//return;
|
||||
}
|
||||
|
||||
if (w > MAX_MAP_CELL_DIMENSION || h > MAX_MAP_CELL_DIMENSION) {
|
||||
@@ -555,7 +555,7 @@ void MapPreview::resize(int w, int h, float alt, MapSurfaceType surf) {
|
||||
char szBuf[1024]="";
|
||||
sprintf(szBuf,"Size of map must be at least %dx%d",MIN_MAP_CELL_DIMENSION,MIN_MAP_CELL_DIMENSION);
|
||||
throw megaglest_runtime_error(szBuf);
|
||||
return;
|
||||
//return;
|
||||
}
|
||||
|
||||
if (w > MAX_MAP_CELL_DIMENSION || h > MAX_MAP_CELL_DIMENSION) {
|
||||
|
@@ -1684,9 +1684,9 @@ bool isKeyDown(int virtualKey) {
|
||||
|
||||
// kinda hack and wrong...
|
||||
if(key >= 0) {
|
||||
if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] keystate[key] = %d\n",__FILE__,__FUNCTION__,__LINE__,keystate[key]);
|
||||
if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] keystate[key] = %d\n",__FILE__,__FUNCTION__,__LINE__,keystate[(unsigned char)key]);
|
||||
|
||||
return (keystate[key] != 0);
|
||||
return (keystate[(unsigned char)key] != 0);
|
||||
}
|
||||
switch(key) {
|
||||
case vkAdd:
|
||||
|
@@ -90,8 +90,11 @@ getHTTPResponse(int s, int * size)
|
||||
int colon=0;
|
||||
int valuestart=0;
|
||||
if(header_buf_used + n > header_buf_len) {
|
||||
header_buf = realloc(header_buf, header_buf_used + n);
|
||||
header_buf_len = header_buf_used + n;
|
||||
char *header_buf_new = realloc(header_buf, header_buf_used + n);
|
||||
if(header_buf_new != NULL) {
|
||||
header_buf = header_buf_new;
|
||||
header_buf_len = header_buf_used + n;
|
||||
}
|
||||
}
|
||||
memcpy(header_buf + header_buf_used, buf, n);
|
||||
header_buf_used += n;
|
||||
@@ -227,11 +230,15 @@ getHTTPResponse(int s, int * size)
|
||||
{
|
||||
if(content_length >= content_buf_used + (int)bytestocopy) {
|
||||
content_buf_len = content_length;
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
content_buf_len = content_buf_used + (int)bytestocopy;
|
||||
}
|
||||
content_buf = (char *)realloc((void *)content_buf,
|
||||
char *content_buf_new = (char *)realloc((void *)content_buf,
|
||||
content_buf_len);
|
||||
if(content_buf_new) {
|
||||
content_buf = content_buf_new;
|
||||
}
|
||||
}
|
||||
memcpy(content_buf + content_buf_used, buf + i, bytestocopy);
|
||||
content_buf_used += bytestocopy;
|
||||
@@ -254,8 +261,11 @@ getHTTPResponse(int s, int * size)
|
||||
} else {
|
||||
content_buf_len = content_buf_used + n;
|
||||
}
|
||||
content_buf = (char *)realloc((void *)content_buf,
|
||||
char *content_buf_new = (char *)realloc((void *)content_buf,
|
||||
content_buf_len);
|
||||
if(content_buf_new) {
|
||||
content_buf = content_buf_new;
|
||||
}
|
||||
}
|
||||
memcpy(content_buf + content_buf_used, buf, n);
|
||||
content_buf_used += n;
|
||||
|
@@ -1430,7 +1430,7 @@ int Socket::receive(void *data, int dataSize, bool tryReceiveUntilDataSizeMet) {
|
||||
else if(tryReceiveUntilDataSizeMet == true && bytesReceived < dataSize) {
|
||||
int newBufferSize = (dataSize - bytesReceived);
|
||||
if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] WARNING, attempting to receive MORE data, bytesReceived = %d, dataSize = %d, newBufferSize = %d\n",__FILE__,__FUNCTION__,__LINE__,bytesReceived,dataSize,newBufferSize);
|
||||
if(SystemFlags::VERBOSE_MODE_ENABLED) printf("\nIn [%s::%s Line: %d] WARNING, attempting to receive MORE data, bytesReceived = %d, dataSize = %d, newBufferSize = %d\n",__FILE__,__FUNCTION__,__LINE__,(int)bytesReceived,dataSize,newBufferSize,newBufferSize);
|
||||
if(SystemFlags::VERBOSE_MODE_ENABLED) printf("\nIn [%s::%s Line: %d] WARNING, attempting to receive MORE data, bytesReceived = %d, dataSize = %d, newBufferSize = %d\n",__FILE__,__FUNCTION__,__LINE__,(int)bytesReceived,dataSize,newBufferSize);
|
||||
|
||||
char *dataAsCharPointer = reinterpret_cast<char *>(data);
|
||||
int additionalBytes = receive(&dataAsCharPointer[bytesReceived], newBufferSize, tryReceiveUntilDataSizeMet);
|
||||
|
@@ -13,7 +13,8 @@
|
||||
#include "util.h"
|
||||
#include "conversion.h"
|
||||
// For gcc backtrace on crash!
|
||||
#if defined(__GNUC__) && !defined(__MINGW32__) && !defined(__FreeBSD__) && !defined(BSD)
|
||||
//#if defined(__GNUC__) && !defined(__MINGW32__) && !defined(__FreeBSD__) && !defined(BSD)
|
||||
#if defined(HAS_GCC_BACKTRACE)
|
||||
//#include <mcheck.h>
|
||||
|
||||
#include <execinfo.h>
|
||||
@@ -65,7 +66,8 @@ void exceptionMessage(const exception &excp) {
|
||||
//int result = MessageBox(NULL, excp.what(), "Error", 0);
|
||||
}
|
||||
|
||||
#if defined(__GNUC__) && !defined(__FreeBSD__) && !defined(BSD)
|
||||
//#if defined(__GNUC__) && !defined(__FreeBSD__) && !defined(BSD)
|
||||
#if defined(HAS_GCC_BACKTRACE)
|
||||
static int getFileAndLine(char *function, void *address, char *file, size_t flen) {
|
||||
int line=-1;
|
||||
if(PlatformExceptionHandler::application_binary != "") {
|
||||
@@ -160,7 +162,8 @@ static int getFileAndLine(char *function, void *address, char *file, size_t flen
|
||||
|
||||
string PlatformExceptionHandler::getStackTrace() {
|
||||
string errMsg = "";
|
||||
#if defined(__GNUC__) && !defined(__MINGW32__) && !defined(__FreeBSD__) && !defined(BSD)
|
||||
//#if defined(__GNUC__) && !defined(__MINGW32__) && !defined(__FreeBSD__) && !defined(BSD)
|
||||
#if defined(HAS_GCC_BACKTRACE)
|
||||
// if(disableBacktrace == false && sdl_quitCalled == false) {
|
||||
errMsg = "\nStack Trace:\n";
|
||||
//errMsg += "To find line #'s use:\n";
|
||||
|
@@ -64,7 +64,7 @@ std::string utf8_encode(const std::wstring wstr) {
|
||||
}
|
||||
|
||||
// Convert an UTF8 string to a wide Unicode String
|
||||
std::wstring utf8_decode(const std::string str) {
|
||||
std::wstring utf8_decode(const std::string &str) {
|
||||
string friendly_path = str;
|
||||
replaceAll(friendly_path, "/", "\\");
|
||||
replaceAll(friendly_path, "\\\\", "\\");
|
||||
|
Reference in New Issue
Block a user