Skip to content

Commit

Permalink
Merge pull request #18 from mapbox/better-default-warnings
Browse files Browse the repository at this point in the history
Add more default warnings
  • Loading branch information
springmeyer authored Oct 16, 2017
2 parents 4e27a19 + 76ec7b5 commit 2b39bfb
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 10 deletions.
5 changes: 4 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,12 @@ else()
message("-- Configuring release build")
endif()

# Enable extra warnings to adhere to https://github.com/mapbox/cpp/issues/37
set(DESIRED_WARNINGS "-Wall -Wextra -Wconversion -Wunreachable-code -Wuninitialized -pedantic-errors -Wold-style-cast -Wno-error=unused-variable -Wshadow -Wfloat-equal")

# Note: -D_GLIBCXX_USE_CXX11_ABI=0 is needed to support mason packages that are precompiled libs
# Currently we only depend on a header only library, but this will help avoid issues when more libs are added via mason
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OPTIMIZATION_FLAGS} -Wall -Wextra -pedantic -Wsign-compare -Wconversion -Wshadow")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OPTIMIZATION_FLAGS} -D_GLIBCXX_USE_CXX11_ABI=0 ${DESIRED_WARNINGS}")

if (WERROR)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror")
Expand Down
9 changes: 5 additions & 4 deletions include/gzip.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
* gzip implements a standard namespace with a few available functions.
*/

#include "gzip/compress.hpp"
#include "gzip/decompress.hpp"
#include "gzip/utils.hpp"
#include "gzip/version.hpp"
#include <gzip/compress.hpp>
#include <gzip/config.hpp>
#include <gzip/decompress.hpp>
#include <gzip/utils.hpp>
#include <gzip/version.hpp>
8 changes: 5 additions & 3 deletions include/gzip/compress.hpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
#include <iostream>
#include <gzip/config.hpp>

// zlib
#include <zlib.h>
// std
#include <limits>
#include <stdexcept>
#include <string>

namespace gzip {

Expand Down Expand Up @@ -31,7 +33,7 @@ std::string compress(const char* data,
{
throw std::runtime_error("deflate init failed");
}
deflate_s.next_in = (Bytef*)data;
deflate_s.next_in = reinterpret_cast<z_const Bytef*>(data);

#ifdef DEBUG
// Verify if size input will fit into unsigned int, type used for zlib's avail_in
Expand All @@ -57,7 +59,7 @@ std::string compress(const char* data,
// There is no way we see that "increase" would not fit in an unsigned int,
// hence we use static cast here to avoid -Wshorten-64-to-32 error
deflate_s.avail_out = static_cast<unsigned int>(increase);
deflate_s.next_out = (Bytef*)(output.data() + length);
deflate_s.next_out = reinterpret_cast<Bytef*>((&output[0] + length));
// From http://www.zlib.net/zlib_how.html
// "deflate() has a return value that can indicate errors, yet we do not check it here.
// Why not? Well, it turns out that deflate() can do no wrong here."
Expand Down
5 changes: 5 additions & 0 deletions include/gzip/config.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#pragma once

#ifndef ZLIB_CONST
#define ZLIB_CONST
#endif
7 changes: 5 additions & 2 deletions include/gzip/decompress.hpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
#include <gzip/config.hpp>

// zlib
#include <zlib.h>
// std
#include <limits>
#include <stdexcept>
#include <string>

namespace gzip {

Expand All @@ -25,7 +28,7 @@ std::string decompress(const char* data, std::size_t size)
{
throw std::runtime_error("inflate init failed");
}
inflate_s.next_in = (Bytef*)data;
inflate_s.next_in = reinterpret_cast<z_const Bytef*>(data);

#ifdef DEBUG
// Verify if size (long type) input will fit into unsigned int, type used for zlib's avail_in
Expand All @@ -47,7 +50,7 @@ std::string decompress(const char* data, std::size_t size)
{
output.resize(length + 2 * size);
inflate_s.avail_out = static_cast<unsigned int>(2 * size);
inflate_s.next_out = (Bytef*)(output.data() + length);
inflate_s.next_out = reinterpret_cast<Bytef*>(&output[0] + length);
int ret = inflate(&inflate_s, Z_FINISH);
if (ret != Z_STREAM_END && ret != Z_OK && ret != Z_BUF_ERROR)
{
Expand Down
3 changes: 3 additions & 0 deletions include/gzip/utils.hpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
#include <cstdlib>

namespace gzip {

// These live in gzip.hpp because it doesnt need to use deps.
// Otherwise, they would need to live in impl files if these methods used
// zlib structures or functions like inflate/deflate)
Expand Down

0 comments on commit 2b39bfb

Please sign in to comment.