From 29bdbd9947feed5881f1e3ac9f96014b16f026b8 Mon Sep 17 00:00:00 2001 From: Jari Vetoniemi Date: Sun, 23 Aug 2015 01:06:59 +0300 Subject: [PATCH] CMake: Update warnings and compile flags. --- CMakeLists.txt | 12 +++++++++--- bin/server.c | 4 ++-- lib/chck | 2 +- src/pi9.c | 18 +++++++++--------- src/pi9.h | 2 +- 5 files changed, 22 insertions(+), 16 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 720ee0e..6a33ff6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -11,8 +11,14 @@ set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/lib) set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/lib) if (CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_GNUCXX) - set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -Wno-variadic-macros -Wno-long-long") - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Wno-variadic-macros -Wno-long-long") + set(ldflags -Wl,-O1,--sort-common,--as-needed,-z,relro,-z,now) + set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${ldflags}") + set(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} ${ldflags}") + set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} ${ldflags}") + add_definitions( + -Wall -Wextra -Wno-variadic-macros -Wno-long-long -Wformat=2 -Winit-self -Wfloat-equal + -Wcast-align -Wpointer-arith -Wmissing-prototypes -Wsuggest-attribute=pure -Wsuggest-attribute=const) + add_definitions(-fstack-protector-strong -fstack-check -pie -flto) endif () if (UNIX AND CMAKE_COMPILER_IS_GNUCC) @@ -22,7 +28,7 @@ if (UNIX AND CMAKE_COMPILER_IS_GNUCC) endif () endif () -set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c99 -D_DEFAULT_SOURCE") +add_definitions(-std=c99 -D_DEFAULT_SOURCE) include_directories( ${CMAKE_CURRENT_SOURCE_DIR}/src diff --git a/bin/server.c b/bin/server.c index 544cd83..6ab084b 100644 --- a/bin/server.c +++ b/bin/server.c @@ -269,7 +269,7 @@ cb_read_hello(struct pi9 *pi9, struct node *node, uint16_t tag, uint64_t offset, const size_t size = sizeof("Hello World!"); offset = chck_minsz(size, offset); count = chck_minsz(size - offset, count); - if (!(pi9_write("Hello World!" + offset, 1, count, pi9->stream)) == count) + if (pi9_write("Hello World!" + offset, 1, count, pi9->stream) != count) return false; return pi9_reply_send(&reply, pi9->fd, pi9->stream); @@ -282,7 +282,7 @@ cb_write_hello(struct pi9 *pi9, struct node *node, uint64_t offset, uint32_t cou fprintf(stderr, "\n--- wrote to %s\n", node->stat.name.data); fprintf(stderr, "(%u) ", count); - for (size_t i = 0; i < count; ++i) putc(*(char*)(data + i), stderr); + for (size_t i = 0; i < count; ++i) putc(*((char*)data + i), stderr); fprintf(stderr, "---\n\n"); return true; } diff --git a/lib/chck b/lib/chck index 92f6ef1..252fa59 160000 --- a/lib/chck +++ b/lib/chck @@ -1 +1 @@ -Subproject commit 92f6ef1e52d6141d9d1d6e8dc4f82e5fc28053a7 +Subproject commit 252fa59d552036355d621bb6c7c29cc04790d291 diff --git a/src/pi9.c b/src/pi9.c index ac4a29e..58b7ab2 100644 --- a/src/pi9.c +++ b/src/pi9.c @@ -147,7 +147,7 @@ read_stat(struct pi9_stat *stat, struct pi9_stream *stream) if (!chck_buffer_read_int(&len, sizeof(len), &stream->in)) return false; - pi9_string_set_cstr_with_length(fields[i], stream->in.curpos, len, false); + pi9_string_set_cstr_with_length(fields[i], (char*)stream->in.curpos, len, false); } return true; @@ -171,7 +171,7 @@ op_Tversion(struct pi9 *pi9, uint16_t tag, struct pi9_stream *stream) #endif struct pi9_string version = {0}; - pi9_string_set_cstr_with_length(&version, stream->in.curpos, vsize, false); + pi9_string_set_cstr_with_length(&version, (char*)stream->in.curpos, vsize, false); // A successful version request initializes the connection. // All outstanding I/O on the connection is aborted; all active fids are freed (`clunked') automatically. @@ -231,7 +231,7 @@ op_Tauth(struct pi9 *pi9, uint16_t tag, struct pi9_stream *stream) goto err_read; struct pi9_string uname = {0}; - pi9_string_set_cstr_with_length(&uname, stream->in.curpos, usize, false); + pi9_string_set_cstr_with_length(&uname, (char*)stream->in.curpos, usize, false); chck_buffer_seek(&stream->in, usize, SEEK_CUR); uint16_t asize; @@ -239,7 +239,7 @@ op_Tauth(struct pi9 *pi9, uint16_t tag, struct pi9_stream *stream) goto err_read; struct pi9_string aname = {0}; - pi9_string_set_cstr_with_length(&aname, stream->in.curpos, asize, false); + pi9_string_set_cstr_with_length(&aname, (char*)stream->in.curpos, asize, false); struct pi9_qid *qid = NULL; if (pi9->procs.auth && !pi9->procs.auth(pi9, tag, afid, &uname, &aname, &qid)) @@ -285,7 +285,7 @@ op_Tattach(struct pi9 *pi9, uint16_t tag, struct pi9_stream *stream) goto err_read; struct pi9_string uname = {0}; - pi9_string_set_cstr_with_length(&uname, stream->in.curpos, usize, false); + pi9_string_set_cstr_with_length(&uname, (char*)stream->in.curpos, usize, false); chck_buffer_seek(&stream->in, usize, SEEK_CUR); uint16_t asize; @@ -293,7 +293,7 @@ op_Tattach(struct pi9 *pi9, uint16_t tag, struct pi9_stream *stream) goto err_read; struct pi9_string aname = {0}; - pi9_string_set_cstr_with_length(&aname, stream->in.curpos, asize, false); + pi9_string_set_cstr_with_length(&aname, (char*)stream->in.curpos, asize, false); struct pi9_qid *qid = NULL; if (pi9->procs.attach && !pi9->procs.attach(pi9, tag, fid, afid, &uname, &aname, &qid)) @@ -373,7 +373,7 @@ op_Twalk(struct pi9 *pi9, uint16_t tag, struct pi9_stream *stream) if (!chck_buffer_read_int(&len, sizeof(len), &stream->in)) goto err_read; - pi9_string_set_cstr_with_length(&walks[i], stream->in.curpos, len, false); + pi9_string_set_cstr_with_length(&walks[i], (char*)stream->in.curpos, len, false); } uint16_t nwqid = 0; @@ -464,7 +464,7 @@ op_Tcreate(struct pi9 *pi9, uint16_t tag, struct pi9_stream *stream) goto err_read; struct pi9_string name = {0}; - pi9_string_set_cstr_with_length(&name, stream->in.curpos, nsize, false); + pi9_string_set_cstr_with_length(&name, (char*)stream->in.curpos, nsize, false); uint8_t mode; uint32_t perm; @@ -640,7 +640,7 @@ op_Tstat(struct pi9 *pi9, uint16_t tag, struct pi9_stream *stream) #endif chck_buffer_seek(&stream->out, HDRSZ + sizeof(uint16_t), SEEK_SET); - void *start = stream->out.curpos; + uint8_t *start = stream->out.curpos; struct pi9_stat *stat = NULL; if (pi9->procs.stat && !pi9->procs.stat(pi9, tag, fid, &stat)) diff --git a/src/pi9.h b/src/pi9.h index d28d7cd..bc92865 100644 --- a/src/pi9.h +++ b/src/pi9.h @@ -9,7 +9,7 @@ static const uint32_t PI9_NOFID = (uint32_t)~0; struct pi9_stream; struct pi9_reply { - const void *start; + const uint8_t *start; uint16_t tag; };