From 932add79e5f06d6fa5c781edfe1aa6462f445d43 Mon Sep 17 00:00:00 2001 From: anyc Date: Wed, 21 May 2014 00:07:57 +0200 Subject: [PATCH] bug fixes and more error reporting --- CMakeLists_mingw.txt | 3 +++ src/rct2.h | 6 ++++++ src/sawyercoding.c | 14 ++++++++++---- src/window_title_exit.c | 3 +-- 4 files changed, 20 insertions(+), 6 deletions(-) diff --git a/CMakeLists_mingw.txt b/CMakeLists_mingw.txt index 6acff59606..111ad06a48 100644 --- a/CMakeLists_mingw.txt +++ b/CMakeLists_mingw.txt @@ -7,6 +7,9 @@ SET(CMAKE_RC_COMPILER ${COMPILER_PREFIX}-windres) SET(CMAKE_PKGCONFIG_EXECUTABLE ${COMPILER_PREFIX}-pkg-config) SET(PKG_CONFIG_EXECUTABLE ${COMPILER_PREFIX}-pkg-config) +# potential flags to make code more similar to MSVC: +# -fshort-wchar -fshort-enums -mms-bitfields -fpack-struct=1 +# set(CMAKE_C_FLAGS "-masm=intel -std=gnu99" CACHE STRING "" FORCE) set(CMAKE_SHARED_LINKER_FLAGS "-static-libgcc" CACHE STRING "" FORCE) diff --git a/src/rct2.h b/src/rct2.h index 4d914d64c8..175dd78361 100644 --- a/src/rct2.h +++ b/src/rct2.h @@ -23,6 +23,7 @@ #include #include +#include typedef signed char sint8; typedef signed short sint16; @@ -52,6 +53,11 @@ typedef unsigned long long uint64; #define RCT2_ERROR(format,...) fprintf(stderr, "ERROR %s:%s():%d: " format "\n", __FILE__, __func__, __LINE__, __VA_ARGS__); #endif +#ifndef _MSC_VER +// use similar struct packing as MSVC for our structs +#pragma pack(1) +#endif + void rct2_finish(); enum { diff --git a/src/sawyercoding.c b/src/sawyercoding.c index 3b56e5806c..3f41fbdd76 100644 --- a/src/sawyercoding.c +++ b/src/sawyercoding.c @@ -81,9 +81,15 @@ int sawyercoding_read_chunk(HANDLE hFile, uint8 *buffer) // Read chunk header ReadFile(hFile, &chunkHeader, sizeof(sawyercoding_chunk_header), &numBytesRead, NULL); + if (sizeof(sawyercoding_chunk_header) != numBytesRead) { + RCT2_ERROR("read error %d != %d\n", sizeof(sawyercoding_chunk_header), numBytesRead); + } // Read chunk data ReadFile(hFile, buffer, chunkHeader.length, &numBytesRead, NULL); + if (chunkHeader.length != numBytesRead) { + RCT2_ERROR("read error %d != %d\n", chunkHeader.length, numBytesRead); + } // Decode chunk data switch (chunkHeader.encoding) { @@ -111,7 +117,7 @@ int sawyercoding_read_chunk(HANDLE hFile, uint8 *buffer) static int decode_chunk_rle(char *buffer, int length) { int i, j, count; - char *src, *dst, rleCodeByte; + unsigned char *src, *dst, rleCodeByte; // Backup buffer src = malloc(length); @@ -135,7 +141,7 @@ static int decode_chunk_rle(char *buffer, int length) free(src); // Return final size - return dst - buffer; + return (char*)dst - buffer; } /** @@ -145,7 +151,7 @@ static int decode_chunk_rle(char *buffer, int length) static int decode_chunk_repeat(char *buffer, int length) { int i, j, count; - char *src, *dst, *copyOffset; + unsigned char *src, *dst, *copyOffset; // Backup buffer src = malloc(length); @@ -167,7 +173,7 @@ static int decode_chunk_repeat(char *buffer, int length) free(src); // Return final size - return dst - buffer; + return (char*)dst - buffer; } /** diff --git a/src/window_title_exit.c b/src/window_title_exit.c index da9526ba1a..6b3db2be55 100644 --- a/src/window_title_exit.c +++ b/src/window_title_exit.c @@ -110,8 +110,7 @@ static void window_title_exit_mouseup() __asm__ ( "mov %[w], esi " : [w] "+m" (w) ); #endif - - if (RCT2_GLOBAL(RCT2_ADDRESS_RUN_INTRO_TICK_PART, int) != 0) + if (RCT2_GLOBAL(RCT2_ADDRESS_RUN_INTRO_TICK_PART, uint8) != 0) return; if (widgetIndex == 0)