From 8b0b250f2cb9bdeef9730c432c002acd8e6f614f Mon Sep 17 00:00:00 2001 From: Davide Beatrici Date: Wed, 10 Mar 2021 01:56:55 +0100 Subject: Fix errors and warnings reported by MSVC, explicitly set C99 --- CMakeLists.txt | 8 ++++++++ FileSystem.c | 2 +- Hamcore.c | 2 +- Memory.c | 6 ++++-- 4 files changed, 14 insertions(+), 4 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index d508b1a..7c80405 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2,6 +2,8 @@ cmake_minimum_required(VERSION 3.11) project(libhamcore LANGUAGES C) +set(CMAKE_C_STANDARD 99) + include(TestBigEndian) add_library(libhamcore STATIC) @@ -11,6 +13,12 @@ if(BIG_ENDIAN) target_compile_definitions(libhamcore PRIVATE "BYTE_ORDER_BIG_ENDIAN") endif() +if(MSVC) + # Suppress "warning C4996: 'fopen': This function or variable may be unsafe. Consider using fopen_s instead.". + # fopen_s() is part of C11, but we want to stick with C99 for increased portability. + target_compile_definitions(libhamcore PRIVATE "_CRT_SECURE_NO_WARNINGS") +endif() + target_include_directories(libhamcore PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}) target_sources(libhamcore diff --git a/FileSystem.c b/FileSystem.c index cb64fe5..b0eda22 100755 --- a/FileSystem.c +++ b/FileSystem.c @@ -51,7 +51,7 @@ bool FileSeek(FILE *file, const size_t offset) return false; } - return fseek(file, offset, SEEK_SET) == 0; + return fseek(file, (long)offset, SEEK_SET) == 0; } size_t FileSize(const char *path) diff --git a/Hamcore.c b/Hamcore.c index 229129e..3475312 100644 --- a/Hamcore.c +++ b/Hamcore.c @@ -245,7 +245,7 @@ bool HamcoreBuild(const char *dst_path, const char *base_path, const char **src_ const size_t prev_size = buffer_size; buffer_size = wanted_size; buffer = realloc(buffer, buffer_size); - memset(buffer + prev_size, 0, buffer_size - prev_size); + memset((uint8_t *)buffer + prev_size, 0, buffer_size - prev_size); } file->Size = buffer_size; diff --git a/Memory.c b/Memory.c index 661d729..237efb9 100644 --- a/Memory.c +++ b/Memory.c @@ -21,6 +21,8 @@ void WriteAndSeek(void **dst, const void *src, const size_t size) return; } - memcpy(*dst, src, size); - *dst += size; + uint8_t **buf = (uint8_t **)dst; + + memcpy(*buf, src, size); + *buf += size; } -- cgit v1.2.3