Skip to content
This repository has been archived by the owner on Oct 9, 2023. It is now read-only.

Commit

Permalink
Feature/fix warnings (#125)
Browse files Browse the repository at this point in the history
* Fix MSVC 14 warnings
* Fix MSVC 12 warnings
* Fix GCC build
  • Loading branch information
Quentin Deslandes committed Dec 22, 2017
1 parent bd61b7a commit 912a1ed
Show file tree
Hide file tree
Showing 26 changed files with 203 additions and 96 deletions.
4 changes: 3 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,18 @@ endif ()
set(CMAKE_MODULE_PATH "${CMAKE_MODULE_PATH}" "${CMAKE_SOURCE_DIR}/resources/cmake/module")

if (WIN32)
set_property(GLOBAL PROPERTY USE_FOLDERS On)
set(pthread_HINTS "${pthread_HINTS}" "${CMAKE_SOURCE_DIR}/external")
endif ()

find_package(pthread REQUIRED)

#[[
Project version
#]]
set(YALL_VERSION_MAJOR 1)
set(YALL_VERSION_MINOR 3)
set(YALL_VERSION_PATCH 4)
set(YALL_VERSION_PATCH 5)
set(YALL_VERSION "${YALL_VERSION_MAJOR}.${YALL_VERSION_MINOR}.${YALL_VERSION_PATCH}")

configure_file("${PROJECT_SOURCE_DIR}/include/version.h.in" "${PROJECT_BINARY_DIR}/generated_headers/version.h")
Expand Down
2 changes: 1 addition & 1 deletion include/yall/Yall.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ class YallConfig {
}

/* Tab width */
void setTabWidth(int width)
void setTabWidth(uint8_t width)
{
yall_config_set_tab_width(width);
}
Expand Down
2 changes: 1 addition & 1 deletion include/yall/call.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@

#include "yall/utils.h"

#define DEFAULT_LINE_SIZE 1024
#define DEFAULT_LINE_SIZE 1024U

struct yall_call_data_line {
char *content;
Expand Down
4 changes: 2 additions & 2 deletions include/yall/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@
*/

struct yall_config {
char *std_header_template;
char *call_header_template;
const char *std_header_template;
const char *call_header_template;
uint8_t tab_width;
};

Expand Down
16 changes: 8 additions & 8 deletions include/yall/header.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,13 @@ enum header_type {
};

enum yall_matches {
empty,
subsystem,
log_level,
function,
filename,
line,
date
match_empty,
match_subsystem,
match_log_level,
match_function,
match_filename,
match_line,
match_date
};

struct header_content {
Expand All @@ -64,7 +64,7 @@ struct header_content {
* store the modifiers order for proper log message header generation.
* <format> can't be NULL.
*/
void header_compile_format(enum header_type hdr_type, char *format);
void header_compile_format(enum header_type hdr_type, const char *format);

/*
* fill_header_content : from a header_content structure, fill the fields with
Expand Down
5 changes: 5 additions & 0 deletions include/yall/msvc_defines.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@
* guards.
*/

// Used to suppress GCC warning from -Wundef
#ifdef __linux__
# define _MSC_VER 0
#endif

// MSVC 12.0 _MSC_VER == 1800 (Visual Studio 2013)
#if (_MSC_VER == 1800)
# define inline __inline
Expand Down
5 changes: 3 additions & 2 deletions include/yall/yall.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,10 @@ _YALL_PUBLIC const char *yall_get_version_string(void);
_YALL_PUBLIC yall_error yall_init(void);

/*
* yall_is_init : return the number of initializations required.
* yall_is_init : returns the number initialization done without closing the
* library.
*/
_YALL_PUBLIC uint8_t yall_is_init(void);
_YALL_PUBLIC uint16_t yall_is_init(void);

/*
* yall_log : major logging function, used to forge the message and write it
Expand Down
3 changes: 3 additions & 0 deletions resources/cmake/module/Findcriterion.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ if(criterion_FOUND)
set_target_properties(criterion::criterion PROPERTIES
IMPORTED_LOCATION "${criterion_LIBRARIES}"
INTERFACE_INCLUDE_DIRECTORIES "${criterion_INCLUDE_DIRS}")

message(STATUS ">\t${criterion_LIBRARIES}")
message(STATUS ">\t${criterion_INCLUDE_DIRS}")
else ()
message(STATUS "> criterion not found")
endif ()
Expand Down
3 changes: 3 additions & 0 deletions resources/cmake/module/Findpthread.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ if(pthread_FOUND)
set_target_properties(pthread::pthread PROPERTIES
IMPORTED_LOCATION "${pthread_LIBRARIES}"
INTERFACE_INCLUDE_DIRECTORIES "${pthread_INCLUDE_DIRS}")

message(STATUS ">\t${pthread_LIBRARIES}")
message(STATUS ">\t${pthread_INCLUDE_DIRS}")
else ()
message(STATUS "> pthread not found")
endif ()
Expand Down
44 changes: 34 additions & 10 deletions resources/cmake/yall.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,48 @@
#[[
Yall objects compilation
#]]

file(GLOB_RECURSE YALL_SRCS src/*.c include/*.h)

add_library(yall SHARED ${YALL_SRCS})

if (UNIX)
# For more infos about the used flags :
# * https://stackoverflow.com/questions/3375697/useful-gcc-flags-for-c
# * https://kristerw.blogspot.fr/2017/09/useful-gcc-warning-options-not-enabled.html
# Compile options
set(_PVT_OPT -Wall -Wextra -std=gnu11 -fvisibility=hidden -fPIC)
set(_PVT_OPT -Wall -Wextra -Wconversion -ftrapv -Wfloat-equal -Wundef
-Wshadow -Wpointer-arith -Wcast-align -Wstrict-prototypes
-Wwrite-strings -Waggregate-return -Wuninitialized
-Wduplicated-cond -Wlogical-op -Wnull-dereference -Wdouble-promotion
-fvisibility=hidden -fPIC)
set(_PVT_OPT_DEBUG -O0)
set(_PVT_OPT_RELEASE -O3)
set(_PVT_OPT_RELEASE -O3 -Werror)
elseif (WIN32)
# Compile options
set(_PVT_OPT /wd4820 /wd4255 /wd4127 /wd4210 /wd6031 /wd4706 /wd28252 /wd28253 /wd4172 /wd4100 /wd4204 /wd4221 /Wall)
set(_PVT_OPT_DEBUG /O0)

#[[
* 4204 : non-const initializer
* 4115 : named type defininition in parenthesis
* 4127 : constant conditional expression
* 4255 : no function prototype given
* 4668 : macro not defined, replaced by 0
* 4706 : assignment within conditional expression
* 4710 : function not inlined
* 4774 : argument is not a string literal
* 4820 : padding
* 4996 : "strdup" deprecated
#]]

set(_PVT_OPT /wd4204 /wd4115 /wd4127 /wd4255 /wd4668 /wd4706 /wd4710 /wd4774 /wd4820 /wd4996 /Wall)
set(_PVT_OPT_DEBUG /Od)
set(_PVT_OPT_RELEASE /W4 /O2 /MP)

# Compile definitions
set(_PVT_DEF _CRT_SECURE_NO_WARNINGS)
endif ()

file(GLOB_RECURSE YALL_SRCS src/*.c include/*.h)

add_library(yall SHARED ${YALL_SRCS})
set_property(TARGET yall PROPERTY FOLDER "library")
endif ()

target_compile_options(yall
PRIVATE
Expand All @@ -34,9 +58,9 @@ target_compile_definitions(yall
PRIVATE ${_PVT_DEF})

target_include_directories(yall
PUBLIC
PUBLIC
${_PUB_INCDIR}
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include>
PRIVATE
${CMAKE_BINARY_DIR}/generated_headers)
Expand Down
16 changes: 12 additions & 4 deletions resources/cmake/yall_c.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
# Redistribution and use of this file is allowed according to the terms of the MIT license.
# For details see the LICENSE file distributed with yall.

add_executable(yall_c tests/c/main.c)

if (UNIX)
# Compile options
set(_PVT_OPT -Wall -Wextra -std=gnu11)
Expand All @@ -12,16 +14,22 @@ if (UNIX)
set(_PVT_LINKLIB yall)
elseif (WIN32)
# Compile options
set(_PVT_OPT /Wall)
set(_PVT_OPT_DEBUG /O0)

#[[
* 4115 : named type defininition in parenthesis
* 4820 : padding
#]]

set(_PVT_OPT /wd4115 /wd4820 /Wall)
set(_PVT_OPT_DEBUG /Od)
set(_PVT_OPT_RELEASE /W4 /O2 /MP)

# Link libraries
set(_PVT_LINKLIB yall)

set_property(TARGET yall_c PROPERTY FOLDER "tests")
endif ()

add_executable(yall_c tests/c/main.c)

target_compile_options(yall_c
PRIVATE
${_PVT_OPT}
Expand Down
23 changes: 19 additions & 4 deletions resources/cmake/yall_cpp.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
# Redistribution and use of this file is allowed according to the terms of the MIT license.
# For details see the LICENSE file distributed with yall.

add_executable(yall_cpp tests/cpp/main.cpp)

if (UNIX)
# Compile options
set(_PVT_OPT -Wall -Wextra)
Expand All @@ -12,16 +14,29 @@ if (UNIX)
set(_PVT_LINKLIB yall)
elseif (WIN32)
# Compile options
set(_PVT_OPT /Wall)
set(_PVT_OPT_DEBUG /O0)

#[[
* 4127 : constant conditional expression
* 4350 : behaviour changed for allocator
* 4365 : conversion from int to uint64_t
* 4514 : unreferenced inline function removed
* 4625 : copy constructor implicitly deleted
* 4626 : assignment operator implicitly deleted
* 4640 : construction of local static object is not thread safe
* 4710 : function not inlined
* 4820 : padding
#]]

set(_PVT_OPT /wd4127 /wd4350 /wd4365 /wd4514 /wd4625 /wd4626 /wd4640 /wd4710 /wd4820 /Wall)
set(_PVT_OPT_DEBUG /Od)
set(_PVT_OPT_RELEASE /W4 /O2 /MP)

# Link libraries
set(_PVT_LINKLIB yall)

set_property(TARGET yall_cpp PROPERTY FOLDER "tests")
endif ()

add_executable(yall_cpp tests/cpp/main.cpp)

target_compile_options(yall_cpp
PRIVATE
${_PVT_OPT}
Expand Down
48 changes: 40 additions & 8 deletions resources/cmake/yall_unit.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,35 @@ find_package(criterion REQUIRED)
]]#
file(GLOB_RECURSE YALL_SRCS src/*.c include/*.h)

add_library(yall_unit_src_obj OBJECT ${YALL_SRCS})

if (UNIX)
# Compile options
set(_PVT_OPT -Wall -Wextra -std=gnu11 -coverage)
set(_PVT_OPT_DEBUG -O0)
set(_PVT_OPT_RELEASE -O3)
elseif (WIN32)
# Compile options
set(_PVT_OPT /wd4820 /wd4255 /wd4127 /wd4210 /wd6031 /wd4706 /wd28252 /wd28253 /wd4172 /wd4100 /wd4204 /wd4221 /Wall)
set(_PVT_OPT_DEBUG /O0)

#[[
* 4005 : macro redefinition
* 4172 : returning local variable address (warned on a MSVC file)
* 4204 : non-const initializer
* 4668 : macro not defined, replaced by 0
* 4706 : assignment within conditional expression
* 4710 : function not inlined
* 4774 : argument is not a string literal
* 4996 : "strdup" deprecated
* 4820 : padding
#]]

set(_PVT_OPT /wd4005 /wd4172 /wd4204 /wd4668 /wd4706 /wd4710 /wd4774 /wd4996 /wd4820 /Wall)
set(_PVT_OPT_DEBUG /Od)
set(_PVT_OPT_RELEASE /W4 /O2 /MP)

set_property(TARGET yall_unit_src_obj PROPERTY FOLDER "tests")
endif ()

add_library(yall_unit_src_obj OBJECT ${YALL_SRCS})

target_compile_options(yall_unit_src_obj
PRIVATE
${_PVT_OPT}
Expand All @@ -51,20 +66,35 @@ target_include_directories(yall_unit_src_obj
]]#
file(GLOB_RECURSE YALL_UNIT_SRCS tests/unit/*.c tests/unit/*.h)

add_executable(yall_unit $<TARGET_OBJECTS:yall_unit_src_obj> ${YALL_UNIT_SRCS})

if (UNIX)
# Compile options
set(_PVT_OPT -Wall -Wextra -std=gnu11)
set(_PVT_OPT_DEBUG -O0)
set(_PVT_OPT_RELEASE -O3)
elseif (WIN32)
# Compile options
set(_PVT_OPT /wd4820 /wd4255 /wd4127 /wd4210 /wd6031 /wd4706 /wd28252 /wd28253 /wd4172 /wd4100 /wd4204 /wd4221 /Wall)
set(_PVT_OPT_DEBUG /O0)

#[[
* 4204 : non-const initializer
* 4221 : initialize pointer with automatic variable
* 4255 : no function prototype given
* 4267 : conversion from size_t to int
* 4464 : relative path contains ".." (on Criterion)
* 4668 : macro not defined, replaced by 0
* 4710 : function not inlined
* 4820 : padding
* 4996 : "strdup" deprecated
#]]

set(_PVT_OPT /wd4204 /wd4221 /wd4255 /wd4267 /wd4464 /wd4668 /wd4710 /wd4820 /wd4996 /Wall)
set(_PVT_OPT_DEBUG /Od)
set(_PVT_OPT_RELEASE /W4 /O2 /MP)

set_property(TARGET yall_unit PROPERTY FOLDER "tests")
endif ()

add_executable(yall_unit $<TARGET_OBJECTS:yall_unit_src_obj> ${YALL_UNIT_SRCS})

target_compile_options(yall_unit
PRIVATE
${_PVT_OPT}
Expand All @@ -87,6 +117,8 @@ target_link_libraries(yall_unit

if (MSVC_VERSION EQUAL 1900)
add_custom_target(unit COMMAND yall_unit --ascii WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/external/bin)

set_property(TARGET unit PROPERTY FOLDER "launch")
endif ()

targetInfos(yall_unit_src_obj)
Expand Down
4 changes: 2 additions & 2 deletions src/call.c
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,8 @@ void yall_call_add_line(yall_call_data *d, uint8_t indent, const char *format,

// Create the message line
va_start(args, format);
vsnprintf(&line_content[i], DEFAULT_LINE_SIZE - tab_width * indent,
format, args);
vsnprintf(&line_content[i], DEFAULT_LINE_SIZE -
(uint32_t)(tab_width * indent), format, args);
va_end(args);

// Manage \n
Expand Down
4 changes: 2 additions & 2 deletions src/config.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,10 @@ void config_setup(void)

void config_clean(void)
{
free(current_config.std_header_template);
free((void *)current_config.std_header_template);
current_config.std_header_template = NULL;

free(current_config.call_header_template);
free((void *)current_config.call_header_template);
current_config.call_header_template = NULL;

current_config.tab_width = 0;
Expand Down
Loading

0 comments on commit 912a1ed

Please sign in to comment.