From a5b465fad147e010dbed88e8bfc6ec6725ce3e41 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Janiszewski?= Date: Mon, 14 Dec 2015 22:23:12 +0100 Subject: [PATCH] Fix some compiler warnings --- src/addresses.c | 6 +++++- src/cmdline.c | 6 +++--- src/cmdline_sprite.c | 6 +++--- src/network/http.cpp | 3 ++- src/network/network.cpp | 2 +- src/rct2.h | 5 +++++ src/windows/server_start.c | 2 +- 7 files changed, 20 insertions(+), 10 deletions(-) diff --git a/src/addresses.c b/src/addresses.c index 0e9f4d3a89..335d905b72 100644 --- a/src/addresses.c +++ b/src/addresses.c @@ -1,7 +1,11 @@ #include "addresses.h" #if defined(__GNUC__) -#define DISABLE_OPT __attribute__((noinline,optimize("O0"))) + #ifdef __clang__ + #define DISABLE_OPT __attribute__((noinline,optnone)) + #else + #define DISABLE_OPT __attribute__((noinline,optimize("O0"))) + #endif // __clang__ #else #define DISABLE_OPT #endif // defined(__GNUC__) diff --git a/src/cmdline.c b/src/cmdline.c index 769ec50f0f..8b1480b842 100644 --- a/src/cmdline.c +++ b/src/cmdline.c @@ -98,7 +98,7 @@ int cmdline_run(const char **argv, int argc) */ char** mutableArgv = malloc(argvsize); memcpy(mutableArgv,argv,argvsize); - argc = argparse_parse(&argparse, argc, mutableArgv); + argc = argparse_parse(&argparse, argc, (const char**)mutableArgv); if (version) { print_version(); @@ -130,7 +130,7 @@ int cmdline_run(const char **argv, int argc) if (argc != 0) { // see comment next to cmdline_call_action for expected return codes - gExitCode = cmdline_call_action(mutableArgv, argc); + gExitCode = cmdline_call_action((const char**)mutableArgv, argc); free(mutableArgv); if (gExitCode < 0) { // action failed, don't change exit code @@ -236,7 +236,7 @@ struct { const char *firstArg; cmdline_action action; } cmdline_table[] = { /** * This function delegates starting the game to different handlers, if found. - * + * * Three cases of return values are supported: * - result < 0 means failure, will exit with error code * This case is useful when user provided wrong arguments or the requested diff --git a/src/cmdline_sprite.c b/src/cmdline_sprite.c index 285beaf217..dff9acbf18 100644 --- a/src/cmdline_sprite.c +++ b/src/cmdline_sprite.c @@ -434,8 +434,8 @@ int cmdline_for_sprite(const char **argv, int argc) return -1; } - printf("sprites: %lu\n", spriteFileHeader.num_entries); - printf("data size: %lu\n", spriteFileHeader.total_size); + printf("sprites: %u\n", spriteFileHeader.num_entries); + printf("data size: %u\n", spriteFileHeader.total_size); sprite_file_close(); return 1; @@ -459,7 +459,7 @@ int cmdline_for_sprite(const char **argv, int argc) printf("height: %d\n", g1->height); printf("x offset: %d\n", g1->x_offset); printf("y offset: %d\n", g1->y_offset); - printf("data offset: 0x%lX\n", (uint32)g1->offset); + printf("data offset: 0x%X\n", (uint32)g1->offset); sprite_file_close(); return 1; diff --git a/src/network/http.cpp b/src/network/http.cpp index 29392b73d6..f0700df26c 100644 --- a/src/network/http.cpp +++ b/src/network/http.cpp @@ -11,6 +11,7 @@ void http_dispose() { } #else #include +#include "../core/Math.hpp" // cURL includes windows.h, but we don't need all of it. #define WIN32_LEAN_AND_MEAN @@ -65,7 +66,7 @@ static size_t http_request_write_func(void *ptr, size_t size, size_t nmemb, void int newCapacity = writeBuffer->capacity; int newLength = writeBuffer->length + newBytesLength; while (newLength > newCapacity) { - newCapacity = max(4096, newCapacity * 2); + newCapacity = Math::Max(4096, newCapacity * 2); } if (newCapacity != writeBuffer->capacity) { writeBuffer->ptr = (char*)realloc(writeBuffer->ptr, newCapacity); diff --git a/src/network/network.cpp b/src/network/network.cpp index 265da30a25..3f6f58ddf6 100644 --- a/src/network/network.cpp +++ b/src/network/network.cpp @@ -1343,7 +1343,7 @@ int Network::Client_Handle_MAP(NetworkConnection& connection, NetworkPacket& pac chunk_buffer.resize(offset + chunksize); } char status[256]; - sprintf(status, "Downloading map ... (%lu / %lu)", (offset + chunksize) / 1000, size / 1000); + sprintf(status, "Downloading map ... (%u / %u)", (offset + chunksize) / 1000, size / 1000); window_network_status_open(status); memcpy(&chunk_buffer[offset], (void*)packet.Read(chunksize), chunksize); if (offset + chunksize == size) { diff --git a/src/rct2.h b/src/rct2.h index 2c9d1255f9..ded705f7b5 100644 --- a/src/rct2.h +++ b/src/rct2.h @@ -64,12 +64,17 @@ typedef utf16* utf16string; #define ror32(x, shift) (((uint32)(x) >> (shift)) | ((uint32)(x) << (32 - (shift)))) #define rol64(x, shift) (((uint64)(x) << (shift)) | ((uint32)(x) >> (64 - (shift)))) #define ror64(x, shift) (((uint64)(x) >> (shift)) | ((uint32)(x) << (64 - (shift)))) + +#ifndef __cplusplus +// in C++ you should be using Math::Min and Math::Max #ifndef min #define min(a,b) (((a) < (b)) ? (a) : (b)) #endif #ifndef max #define max(a,b) (((a) > (b)) ? (a) : (b)) #endif +#endif // __cplusplus + #define sgn(x) ((x > 0) ? 1 : ((x < 0) ? -1 : 0)) #define clamp(l, x, h) (min(h, max(l, x))) diff --git a/src/windows/server_start.c b/src/windows/server_start.c index 752c7efd4b..a63aaacd60 100644 --- a/src/windows/server_start.c +++ b/src/windows/server_start.c @@ -140,7 +140,7 @@ void window_server_start_open() window->colours[1] = 26; window->colours[2] = 26; - sprintf(_port, "%lu", gConfigNetwork.default_port); + sprintf(_port, "%u", gConfigNetwork.default_port); safe_strncpy(_name, gConfigNetwork.server_name, sizeof(_name)); }