Skip to content

Commit e919688

Browse files
authored
Merge pull request #1025 from Exiv2/027_fixWarnings
fix some compiler warnings
2 parents b7bd098 + a62e35e commit e919688

File tree

6 files changed

+116
-94
lines changed

6 files changed

+116
-94
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ matrix:
1010
dist: xenial
1111
sudo: required
1212
compiler: gcc
13-
env: COVERAGE=1 CMAKE_OPTIONS="-DCMAKE_BUILD_TYPE=Release -DEXIV2_ENABLE_VIDEO=ON -DEXIV2_ENABLE_WEBREADY=ON -DEXIV2_BUILD_UNIT_TESTS=ON -DBUILD_WITH_COVERAGE=ON -DEXIV2_ENABLE_CURL=ON"
13+
env: COVERAGE=1 CMAKE_OPTIONS="-DCMAKE_BUILD_TYPE=Debug -DEXIV2_ENABLE_VIDEO=ON -DEXIV2_ENABLE_WEBREADY=ON -DEXIV2_BUILD_UNIT_TESTS=ON -DBUILD_WITH_COVERAGE=ON -DEXIV2_ENABLE_CURL=ON"
1414

1515
- os: linux
1616
dist: xenial

cmake/compilerFlags.cmake

Lines changed: 29 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ if ( MINGW OR UNIX OR MSYS ) # MINGW, Linux, APPLE, CYGWIN
77
set(COMPILER_IS_CLANG ON)
88
endif()
99

10-
set (CMAKE_CXX_FLAGS_DEBUG "-g3 -gstrict-dwarf -O0")
10+
set (CMAKE_CXX_FLAGS_DEBUG "-g3 -gstrict-dwarf -O0")
1111

1212
if (CMAKE_GENERATOR MATCHES "Xcode")
1313
set(CMAKE_XCODE_ATTRIBUTE_GCC_VERSION "com.apple.compilers.llvm.clang.1_0")
@@ -20,17 +20,39 @@ if ( MINGW OR UNIX OR MSYS ) # MINGW, Linux, APPLE, CYGWIN
2020
endif()
2121
endif()
2222

23+
2324
if (COMPILER_IS_GCC OR COMPILER_IS_CLANG)
2425

26+
# This fails under Fedora - MinGW - Gcc 8.3
27+
if (NOT MINGW)
28+
if (COMPILER_IS_GCC AND CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 8.0)
29+
add_compile_options(-fstack-clash-protection -fcf-protection)
30+
endif()
31+
32+
if (COMPILER_IS_GCC OR (COMPILER_IS_CLANG AND CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 3.7 ))
33+
# is not available for clang 3.4.2. it appears to be present in clang 3.7.
34+
add_compile_options(-fstack-protector-strong)
35+
endif()
36+
endif()
37+
38+
add_compile_options(-Wp,-D_GLIBCXX_ASSERTIONS)
39+
40+
if (CMAKE_BUILD_TYPE STREQUAL Release AND NOT APPLE)
41+
add_compile_options(-Wp,-D_FORTIFY_SOURCE=2) # Requires to compile with -O2
42+
endif()
43+
2544
if(BUILD_WITH_COVERAGE)
26-
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g ")
27-
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O0")
28-
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fprofile-arcs")
29-
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -ftest-coverage")
45+
add_compile_options(--coverage)
46+
# TODO: From CMake 3.13 we could use add_link_options instead these 2 lines
3047
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} --coverage")
48+
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} --coverage")
3149
endif()
3250

33-
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wcast-align -Wpointer-arith -Wformat-security -Wmissing-format-attribute -Woverloaded-virtual -W")
51+
add_compile_options(-Wall -Wcast-align -Wpointer-arith -Wformat-security -Wmissing-format-attribute -Woverloaded-virtual -W)
52+
53+
# This seems to be causing issues in the Fedora_MinGW GitLab job
54+
#add_compile_options(-fasynchronous-unwind-tables)
55+
3456

3557
if ( EXIV2_TEAM_USE_SANITIZERS )
3658
# ASAN is available in gcc from 4.8 and UBSAN from 4.9
@@ -61,82 +83,8 @@ if ( MINGW OR UNIX OR MSYS ) # MINGW, Linux, APPLE, CYGWIN
6183
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${SANITIZER_FLAGS}")
6284
set(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} ${SANITIZER_FLAGS}")
6385
endif()
64-
6586
endif()
66-
67-
if ( EXIV2_TEAM_EXTRA_WARNINGS )
68-
# Note that this is intended to be used only by Exiv2 developers/contributors.
69-
70-
if ( COMPILER_IS_GCC )
71-
if ( CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 4.0 )
72-
string(CONCAT EXTRA_COMPILE_FLAGS ${EXTRA_COMPILE_FLAGS}
73-
" -Wextra"
74-
" -Wlogical-op"
75-
" -Wdouble-promotion"
76-
" -Wshadow"
77-
" -Wuseless-cast"
78-
" -Wpointer-arith" # This warning is also enabled by -Wpedantic
79-
" -Wformat=2"
80-
#" -Wold-style-cast"
81-
)
82-
endif ()
83-
84-
if ( CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 5.0 )
85-
string(CONCAT EXTRA_COMPILE_FLAGS ${EXTRA_COMPILE_FLAGS}
86-
" -Warray-bounds=2"
87-
)
88-
endif ()
89-
90-
if ( CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 6.0 )
91-
string(CONCAT EXTRA_COMPILE_FLAGS ${EXTRA_COMPILE_FLAGS}
92-
" -Wduplicated-cond"
93-
)
94-
endif ()
95-
96-
if ( CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 7.0 )
97-
string(CONCAT EXTRA_COMPILE_FLAGS ${EXTRA_COMPILE_FLAGS}
98-
" -Wduplicated-branches"
99-
" -Wrestrict"
100-
)
101-
endif ()
102-
endif ()
103-
104-
if ( COMPILER_IS_CLANG )
105-
# https://clang.llvm.org/docs/DiagnosticsReference.html
106-
# These variables are at least available since clang 3.9.1
107-
string(CONCAT EXTRA_COMPILE_FLAGS "-Wextra"
108-
" -Wshadow"
109-
" -Wassign-enum"
110-
" -Wmicrosoft"
111-
" -Wcomments"
112-
" -Wconditional-uninitialized"
113-
" -Wdirect-ivar-access"
114-
" -Weffc++"
115-
" -Wpointer-arith"
116-
" -Wformat=2"
117-
#" -Warray-bounds" # Enabled by default
118-
# These two raises lot of warnings. Use them wisely
119-
#" -Wconversion"
120-
#" -Wold-style-cast"
121-
)
122-
# -Wdouble-promotion flag is not available in clang 3.4.2
123-
if ( CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 3.4.2 )
124-
string(CONCAT EXTRA_COMPILE_FLAGS ${EXTRA_COMPILE_FLAGS}
125-
" -Wdouble-promotion"
126-
)
127-
endif ()
128-
# -Wcomma flag is not available in clang 3.8.1
129-
if ( CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 3.8.1 )
130-
string(CONCAT EXTRA_COMPILE_FLAGS ${EXTRA_COMPILE_FLAGS}
131-
" -Wcomma"
132-
)
133-
endif ()
134-
endif ()
135-
136-
137-
endif ()
13887
endif()
139-
14088
endif ()
14189

14290
# http://stackoverflow.com/questions/10113017/setting-the-msvc-runtime-in-cmake
@@ -185,8 +133,6 @@ if(MSVC)
185133
endif ()
186134

187135
# Object Level Parallelism
188-
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /MP")
189-
136+
add_compile_options(/MP)
190137
add_definitions(-DNOMINMAX -DWIN32_LEAN_AND_MEAN)
191-
192138
endif()

cmake/compilerFlagsExiv2.cmake

Lines changed: 73 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,84 @@
11
# These flags only applies to exiv2lib, and the applications, but not to the xmp code
22

3-
if (MINGW OR UNIX) # MINGW, Linux, APPLE, CYGWIN
3+
if (COMPILER_IS_GCC OR COMPILER_IS_CLANG) # MINGW, Linux, APPLE, CYGWIN
44
if ( EXIV2_TEAM_WARNINGS_AS_ERRORS )
5-
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror")
6-
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-error=deprecated-declarations")
5+
add_compile_options(-Werror -Wno-error=deprecated-declarations)
6+
endif ()
7+
8+
if ( EXIV2_TEAM_EXTRA_WARNINGS )
9+
# Note that this is intended to be used only by Exiv2 developers/contributors.
10+
11+
if ( COMPILER_IS_GCC )
12+
if ( CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 4.0 )
13+
string(CONCAT EXTRA_COMPILE_FLAGS ${EXTRA_COMPILE_FLAGS}
14+
" -Wextra"
15+
" -Wlogical-op"
16+
" -Wdouble-promotion"
17+
" -Wshadow"
18+
" -Wuseless-cast"
19+
" -Wpointer-arith" # This warning is also enabled by -Wpedantic
20+
" -Wformat=2"
21+
#" -Wold-style-cast"
22+
)
23+
endif ()
24+
25+
if ( CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 5.0 )
26+
string(CONCAT EXTRA_COMPILE_FLAGS ${EXTRA_COMPILE_FLAGS}
27+
" -Warray-bounds=2"
28+
)
29+
endif ()
30+
31+
if ( CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 6.0 )
32+
string(CONCAT EXTRA_COMPILE_FLAGS ${EXTRA_COMPILE_FLAGS}
33+
" -Wduplicated-cond"
34+
)
35+
endif ()
36+
37+
if ( CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 7.0 )
38+
string(CONCAT EXTRA_COMPILE_FLAGS ${EXTRA_COMPILE_FLAGS}
39+
" -Wduplicated-branches"
40+
" -Wrestrict"
41+
)
42+
endif ()
43+
endif ()
44+
45+
if ( COMPILER_IS_CLANG )
46+
# https://clang.llvm.org/docs/DiagnosticsReference.html
47+
# These variables are at least available since clang 3.9.1
48+
string(CONCAT EXTRA_COMPILE_FLAGS "-Wextra"
49+
" -Wshadow"
50+
" -Wassign-enum"
51+
" -Wmicrosoft"
52+
" -Wcomments"
53+
" -Wconditional-uninitialized"
54+
" -Wdirect-ivar-access"
55+
" -Weffc++"
56+
" -Wpointer-arith"
57+
" -Wformat=2"
58+
#" -Warray-bounds" # Enabled by default
59+
# These two raises lot of warnings. Use them wisely
60+
#" -Wconversion"
61+
#" -Wold-style-cast"
62+
)
63+
# -Wdouble-promotion flag is not available in clang 3.4.2
64+
if ( CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 3.4.2 )
65+
string(CONCAT EXTRA_COMPILE_FLAGS ${EXTRA_COMPILE_FLAGS}
66+
" -Wdouble-promotion"
67+
)
68+
endif ()
69+
# -Wcomma flag is not available in clang 3.8.1
70+
if ( CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 3.8.1 )
71+
string(CONCAT EXTRA_COMPILE_FLAGS ${EXTRA_COMPILE_FLAGS}
72+
" -Wcomma"
73+
)
74+
endif ()
75+
endif ()
776
endif ()
877
endif()
978

1079
if (MSVC)
1180
if ( EXIV2_TEAM_WARNINGS_AS_ERRORS )
12-
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /WX")
81+
add_compile_options(/WX)
1382
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /WX")
1483
set(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} /WX")
1584
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} /WX")

cmake/printSummary.cmake

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,22 @@ macro( OptionOutput _outputstring )
88
message( STATUS "${_outputstring}${_var}" )
99
endmacro( OptionOutput _outputstring )
1010

11+
function(printList items)
12+
foreach (item ${items})
13+
message("\t ${item}")
14+
endforeach()
15+
endfunction()
16+
17+
get_property(COMPILER_OPTIONS DIRECTORY ${CMAKE_SOURCE_DIR} PROPERTY COMPILE_OPTIONS)
18+
1119
message( STATUS "Install prefix: ${CMAKE_INSTALL_PREFIX}")
1220
message( STATUS "------------------------------------------------------------------" )
1321
message( STATUS "CMake Generator: ${CMAKE_GENERATOR}" )
1422
message( STATUS "CMAKE_BUILD_TYPE: ${CMAKE_BUILD_TYPE}" )
1523
message( STATUS "Compiler info: ${CMAKE_CXX_COMPILER_ID} (${CMAKE_CXX_COMPILER}) ; version: ${CMAKE_CXX_COMPILER_VERSION}")
1624
message( STATUS " --- Compiler flags --- ")
1725
message( STATUS "General: ${CMAKE_CXX_FLAGS}" )
26+
printList("${COMPILER_OPTIONS}")
1827
message( STATUS "Extra: ${EXTRA_COMPILE_FLAGS}" )
1928
message( STATUS "Debug: ${CMAKE_CXX_FLAGS_DEBUG}" )
2029
message( STATUS "Release: ${CMAKE_CXX_FLAGS_RELEASE}" )
@@ -32,9 +41,6 @@ OptionOutput( "Warnings as errors: " EXIV2_WARNINGS_AS_ERRORS
3241
OptionOutput( "Use extra compiler warning flags: " EXIV2_EXTRA_WARNINGS )
3342
message( STATUS "" )
3443

35-
36-
message( STATUS "Compiler info: ${CMAKE_CXX_COMPILER_ID} (${CMAKE_CXX_COMPILER}) ; version: ${CMAKE_CXX_COMPILER_VERSION}")
37-
3844
message( STATUS "------------------------------------------------------------------" )
3945
OptionOutput( "Building shared library: " BUILD_SHARED_LIBS )
4046
OptionOutput( "Building PNG support: " EXIV2_ENABLE_PNG AND ZLIB_FOUND )

src/actions.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2050,8 +2050,8 @@ namespace {
20502050
pthread_mutex_lock( &cs );
20512051
std::string tmp = "/tmp/";
20522052
#endif
2053-
char sCount[12];
2054-
sprintf(sCount,"_%d",++count);
2053+
char sCount[13];
2054+
sprintf(sCount,"_%d",++count); /// \todo replace by std::snprintf on master
20552055

20562056
std::string result = tmp + Exiv2::toString(pid) + sCount ;
20572057
if ( Exiv2::fileExists(result) ) std::remove(result.c_str());

src/jpgimage.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -602,7 +602,8 @@ namespace Exiv2 {
602602
// 0xc0 .. 0xcf are SOFn (except 4)
603603
nm[0xc4] = "DHT";
604604
for (int i = 0; i <= 15; i++) {
605-
char MN[10];
605+
char MN[16];
606+
/// \todo to be replaced by std::snprintf on master (only available in c++11)
606607
sprintf(MN, "APP%d", i);
607608
nm[0xe0 + i] = MN;
608609
if (i != 4) {

0 commit comments

Comments
 (0)