mirror of
https://github.com/valitydev/thrift.git
synced 2024-11-06 18:35:19 +00:00
THRIFT-3873: fix various compiler warnings and overflow errors
THRIFT-3847: change VERSION to PACKAGE_VERSION to avoid conflicts with third party or OS headers This closes #1128
This commit is contained in:
parent
e0ccbd6e62
commit
7edc8faefd
@ -17,17 +17,16 @@
|
||||
# under the License.
|
||||
#
|
||||
|
||||
|
||||
include(CheckSymbolExists)
|
||||
include(CheckFunctionExists)
|
||||
include(CheckIncludeFile)
|
||||
include(CheckIncludeFiles)
|
||||
include(CheckFunctionExists)
|
||||
include(CheckSymbolExists)
|
||||
|
||||
# If AI_ADDRCONFIG is not defined we define it as 0
|
||||
check_symbol_exists(AI_ADDRCONFIG "sys/types.h;sys/socket.h;netdb.h" HAVE_AI_ADDRCONFIG)
|
||||
if(NOT HAVE_AI_ADDRCONFIG)
|
||||
set(AI_ADDRCONFIG 1)
|
||||
endif(NOT HAVE_AI_ADDRCONFIG)
|
||||
if (Inttypes_FOUND)
|
||||
# This allows the inttypes.h and stdint.h checks to succeed on platforms that
|
||||
# do not natively provide there.
|
||||
set (CMAKE_REQUIRED_INCLUDES ${INTTYPES_INCLUDE_DIRS})
|
||||
endif ()
|
||||
|
||||
check_include_file(arpa/inet.h HAVE_ARPA_INET_H)
|
||||
check_include_file(fcntl.h HAVE_FCNTL_H)
|
||||
@ -72,5 +71,5 @@ set(VERSION ${thrift_VERSION})
|
||||
|
||||
# generate a config.h file
|
||||
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/build/cmake/config.h.in" "${CMAKE_CURRENT_BINARY_DIR}/thrift/config.h")
|
||||
# HACK: Some files include thrift/config.h and some config.h so we include both. This should be cleaned up.
|
||||
include_directories("${CMAKE_CURRENT_BINARY_DIR}/thrift" "${CMAKE_CURRENT_BINARY_DIR}")
|
||||
|
||||
include_directories("${CMAKE_CURRENT_BINARY_DIR}")
|
||||
|
@ -71,12 +71,24 @@ if(MSVC)
|
||||
message (FATAL_ERROR "Windows build does not support shared library output yet, please set -DWITH_SHARED_LIB=off")
|
||||
endif()
|
||||
|
||||
add_definitions("/MP") # parallel build
|
||||
add_definitions("/W3") # warning level 3
|
||||
|
||||
# VS2010 does not provide inttypes which we need for "PRId64" used in many places
|
||||
find_package(Inttypes)
|
||||
if (Inttypes_FOUND)
|
||||
include_directories(${INTTYPES_INCLUDE_DIRS})
|
||||
# OpenSSL conflicts with the definition of PRId64 unless it is defined first
|
||||
add_definitions("/FIinttypes.h")
|
||||
endif ()
|
||||
elseif(UNIX)
|
||||
find_program( MEMORYCHECK_COMMAND valgrind )
|
||||
set( MEMORYCHECK_COMMAND_OPTIONS "--gen-suppressions=all --leak-check=full" )
|
||||
set( MEMORYCHECK_SUPPRESSIONS_FILE "${PROJECT_SOURCE_DIR}/test/valgrind.suppress" )
|
||||
endif()
|
||||
|
||||
add_definitions("-D__STDC_FORMAT_MACROS")
|
||||
|
||||
# WITH_*THREADS selects which threading library to use
|
||||
if(WITH_BOOSTTHREADS)
|
||||
add_definitions("-DUSE_BOOST_THREAD=1")
|
||||
|
41
build/cmake/FindInttypes.cmake
Normal file
41
build/cmake/FindInttypes.cmake
Normal file
@ -0,0 +1,41 @@
|
||||
#
|
||||
# Licensed to the Apache Software Foundation (ASF) under one
|
||||
# or more contributor license agreements. See the NOTICE file
|
||||
# distributed with this work for additional information
|
||||
# regarding copyright ownership. The ASF licenses this file
|
||||
# to you under the Apache License, Version 2.0 (the
|
||||
# "License"); you may not use this file except in compliance
|
||||
# with the License. You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing,
|
||||
# software distributed under the License is distributed on an
|
||||
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
# KIND, either express or implied. See the License for the
|
||||
# specific language governing permissions and limitations
|
||||
# under the License.
|
||||
#
|
||||
|
||||
# find msinttypes on compilers that don't provide it, for example
|
||||
# VS2010
|
||||
|
||||
# Usage:
|
||||
# Provide INTTYPES_ROOT if you need it
|
||||
# Result: INTTYPES_INCLUDE_DIRS, where to find inttypes.h
|
||||
# Result: Inttypes_FOUND, If false, inttypes.h was not found
|
||||
|
||||
find_path(INTTYPES_INCLUDE_DIRS inttypes.h HINTS ${INTTYPES_ROOT})
|
||||
if (INTTYPES_INCLUDE_DIRS)
|
||||
set(Inttypes_FOUND TRUE)
|
||||
else ()
|
||||
set(Inttypes_FOUND FALSE)
|
||||
if (Inttypes_FIND_REQUIRED)
|
||||
message(FATAL_ERROR "Could NOT find inttypes.h")
|
||||
endif ()
|
||||
message(STATUS "inttypes.h NOT found")
|
||||
endif ()
|
||||
|
||||
mark_as_advanced(
|
||||
INTTYPES_INCLUDE_DIRS
|
||||
)
|
@ -13,9 +13,13 @@ foreach(prefix ${LibEvent_EXTRA_PREFIXES})
|
||||
list(APPEND LibEvent_LIBRARIES_PATHS "${prefix}/lib")
|
||||
endforeach()
|
||||
|
||||
find_path(LIBEVENT_INCLUDE_DIRS event.h PATHS ${LibEvent_INCLUDE_PATHS})
|
||||
# "lib" prefix is needed on Windows
|
||||
find_library(LIBEVENT_LIBRARIES NAMES event libevent PATHS ${LibEvent_LIBRARIES_PATHS})
|
||||
# Looking for "event.h" will find the Platform SDK include dir on windows
|
||||
# so we also look for a peer header like evhttp.h to get the right path
|
||||
find_path(LIBEVENT_INCLUDE_DIRS evhttp.h event.h PATHS ${LibEvent_INCLUDE_PATHS})
|
||||
|
||||
# "lib" prefix is needed on Windows in some cases
|
||||
# newer versions of libevent use three libraries
|
||||
find_library(LIBEVENT_LIBRARIES NAMES event event_core event_extra libevent PATHS ${LibEvent_LIBRARIES_PATHS})
|
||||
|
||||
if (LIBEVENT_LIBRARIES AND LIBEVENT_INCLUDE_DIRS)
|
||||
set(Libevent_FOUND TRUE)
|
||||
|
@ -44,9 +44,6 @@
|
||||
/* Define to the full name and version of this package. */
|
||||
#define PACKAGE_STRING "${PACKAGE_STRING}"
|
||||
|
||||
/* Version number of package */
|
||||
#define VERSION "${VERSION}"
|
||||
|
||||
/************************** DEFINES *************************/
|
||||
|
||||
/* Define if the AI_ADDRCONFIG symbol is unavailable */
|
||||
@ -154,4 +151,4 @@
|
||||
/* Define to 1 if strerror_r returns char *. */
|
||||
#cmakedefine STRERROR_R_CHAR_P 1
|
||||
|
||||
#endif
|
||||
#endif
|
||||
|
@ -18,6 +18,14 @@
|
||||
#
|
||||
|
||||
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/src/thrift/version.h.in ${CMAKE_CURRENT_BINARY_DIR}/thrift/version.h)
|
||||
if(MSVC)
|
||||
# The winflexbison generator outputs some macros that conflict with the Visual Studio 2010 copy of stdint.h
|
||||
# This might be fixed in later versions of Visual Studio, but an easy solution is to include stdint.h first
|
||||
if(HAVE_STDINT_H)
|
||||
add_definitions(-D__STDC_LIMIT_MACROS)
|
||||
add_definitions(/FI"stdint.h")
|
||||
endif(HAVE_STDINT_H)
|
||||
endif()
|
||||
|
||||
find_package(FLEX REQUIRED)
|
||||
find_package(BISON REQUIRED)
|
||||
|
@ -20,6 +20,7 @@
|
||||
#include <string>
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
#include <limits>
|
||||
#include <vector>
|
||||
|
||||
#include <stdlib.h>
|
||||
@ -968,10 +969,13 @@ void t_erl_generator::export_string(string name, int num) {
|
||||
}
|
||||
|
||||
void t_erl_generator::export_types_function(t_function* tfunction, string prefix) {
|
||||
|
||||
t_struct::members_type::size_type num = tfunction->get_arglist()->get_members().size();
|
||||
if (num > static_cast<t_struct::members_type::size_type>(std::numeric_limits<int>().max())) {
|
||||
throw "integer overflow in t_erl_generator::export_types_function, name " + tfunction->get_name();
|
||||
}
|
||||
export_types_string(prefix + tfunction->get_name(),
|
||||
1 // This
|
||||
+ ((tfunction->get_arglist())->get_members()).size());
|
||||
+ static_cast<int>(num));
|
||||
}
|
||||
|
||||
void t_erl_generator::export_types_string(string name, int num) {
|
||||
@ -984,10 +988,13 @@ void t_erl_generator::export_types_string(string name, int num) {
|
||||
}
|
||||
|
||||
void t_erl_generator::export_function(t_function* tfunction, string prefix) {
|
||||
|
||||
t_struct::members_type::size_type num = tfunction->get_arglist()->get_members().size();
|
||||
if (num > static_cast<t_struct::members_type::size_type>(std::numeric_limits<int>().max())) {
|
||||
throw "integer overflow in t_erl_generator::export_function, name " + tfunction->get_name();
|
||||
}
|
||||
export_string(prefix + tfunction->get_name(),
|
||||
1 // This
|
||||
+ ((tfunction->get_arglist())->get_members()).size());
|
||||
+ static_cast<int>(num));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -25,9 +25,10 @@
|
||||
* guide for ensuring uniformity and readability.
|
||||
*/
|
||||
|
||||
#include <string>
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
#include <limits>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include <stdlib.h>
|
||||
@ -433,7 +434,11 @@ std::string t_go_generator::camelcase(const std::string& value) const {
|
||||
if (islower(value2[i + 1])) {
|
||||
value2.replace(i, 2, 1, toupper(value2[i + 1]));
|
||||
}
|
||||
fix_common_initialism(value2, i);
|
||||
|
||||
if (i > static_cast<std::string::size_type>(std::numeric_limits<int>().max())) {
|
||||
throw "integer overflow in t_go_generator::camelcase, value = " + value;
|
||||
}
|
||||
fix_common_initialism(value2, static_cast<int>(i));
|
||||
}
|
||||
}
|
||||
|
||||
@ -2308,7 +2313,7 @@ void t_go_generator::generate_service_remote(t_service* tservice) {
|
||||
f_remote << indent() << "}" << endl;
|
||||
|
||||
for (std::vector<t_field*>::size_type i = 0; i < num_args; ++i) {
|
||||
int flagArg = i + 1;
|
||||
std::vector<t_field*>::size_type flagArg = i + 1;
|
||||
t_type* the_type(args[i]->get_type());
|
||||
t_type* the_type2(get_true_type(the_type));
|
||||
|
||||
|
@ -39,9 +39,15 @@
|
||||
#endif
|
||||
|
||||
#ifdef _MSC_VER
|
||||
//warning C4102: 'find_rule' : unreferenced label
|
||||
#pragma warning(disable:4102)
|
||||
//avoid isatty redefinition
|
||||
#pragma warning( push )
|
||||
|
||||
// warning C4102: 'find_rule' : unreferenced label
|
||||
#pragma warning( disable : 4102 )
|
||||
|
||||
// warning C4267: 'argument' : conversion from 'size_t' to 'int', possible loss of data
|
||||
#pragma warning( disable : 4267 )
|
||||
|
||||
// avoid isatty redefinition
|
||||
#define YY_NEVER_INTERACTIVE 1
|
||||
|
||||
#define YY_NO_UNISTD_H 1
|
||||
@ -459,5 +465,9 @@ literal_begin (['\"])
|
||||
|
||||
%%
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#pragma warning( pop )
|
||||
#endif
|
||||
|
||||
/* vim: filetype=lex
|
||||
*/
|
||||
|
@ -25,8 +25,12 @@
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef __STDC_LIMIT_MACROS
|
||||
#define __STDC_LIMIT_MACROS
|
||||
#endif
|
||||
#ifndef __STDC_FORMAT_MACROS
|
||||
#define __STDC_FORMAT_MACROS
|
||||
#endif
|
||||
#include <stdio.h>
|
||||
#ifndef _MSC_VER
|
||||
#include <inttypes.h>
|
||||
|
@ -34,9 +34,13 @@
|
||||
|
||||
#define strtoll(begin_ptr, end_ptr, length) _strtoi64(begin_ptr, end_ptr, length)
|
||||
|
||||
#define PRIu64 "I64d"
|
||||
#define PRIi64 "I64d"
|
||||
#ifndef PRIu64
|
||||
#define PRIu64 "I64u"
|
||||
#endif
|
||||
|
||||
#ifndef PRIi64
|
||||
#define PRIi64 "I64i"
|
||||
#endif
|
||||
// squelch deprecation warnings
|
||||
#pragma warning(disable : 4996)
|
||||
// squelch bool conversion performance warning
|
||||
|
@ -46,7 +46,7 @@ public:
|
||||
explicit THeaderProtocol(const boost::shared_ptr<TTransport>& trans,
|
||||
uint16_t protoId = T_COMPACT_PROTOCOL)
|
||||
: TVirtualProtocol<THeaderProtocol>(boost::shared_ptr<TTransport>(new THeaderTransport(trans))),
|
||||
trans_(boost::dynamic_pointer_cast<THeaderTransport>(this->getTransport())),
|
||||
trans_(boost::dynamic_pointer_cast<THeaderTransport>(getTransport())),
|
||||
protoId_(protoId) {
|
||||
trans_->setProtocolId(protoId);
|
||||
resetProtocol();
|
||||
@ -57,7 +57,7 @@ public:
|
||||
uint16_t protoId = T_COMPACT_PROTOCOL)
|
||||
: TVirtualProtocol<THeaderProtocol>(
|
||||
boost::shared_ptr<TTransport>(new THeaderTransport(inTrans, outTrans))),
|
||||
trans_(boost::dynamic_pointer_cast<THeaderTransport>(this->getTransport())),
|
||||
trans_(boost::dynamic_pointer_cast<THeaderTransport>(getTransport())),
|
||||
protoId_(protoId) {
|
||||
trans_->setProtocolId(protoId);
|
||||
resetProtocol();
|
||||
|
@ -524,7 +524,7 @@ namespace {
|
||||
std::string doubleToString(double d) {
|
||||
std::ostringstream str;
|
||||
str.imbue(std::locale::classic());
|
||||
const int max_digits10 = 2 + std::numeric_limits<double>::digits10;
|
||||
const std::streamsize max_digits10 = 2 + std::numeric_limits<double>::digits10;
|
||||
str.precision(max_digits10);
|
||||
str << d;
|
||||
return str.str();
|
||||
|
@ -17,8 +17,6 @@
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
#define __STDC_FORMAT_MACROS
|
||||
|
||||
#include <thrift/thrift-config.h>
|
||||
|
||||
#include <thrift/server/TNonblockingServer.h>
|
||||
@ -64,13 +62,12 @@
|
||||
#define AF_LOCAL AF_UNIX
|
||||
#endif
|
||||
|
||||
#if !defined(PRIu32)
|
||||
#define PRIu32 "I32u"
|
||||
#define PRIu64 "I64u"
|
||||
#ifdef HAVE_INTTYPES_H
|
||||
#include <inttypes.h>
|
||||
#endif
|
||||
|
||||
#if defined(_WIN32) && (_WIN32_WINNT < 0x0600)
|
||||
#define AI_ADDRCONFIG 0x0400
|
||||
#ifdef HAVE_STDINT_H
|
||||
#include <stdint.h>
|
||||
#endif
|
||||
|
||||
namespace apache {
|
||||
|
@ -23,11 +23,11 @@
|
||||
#include <thrift/protocol/TBinaryProtocol.h>
|
||||
#include <thrift/protocol/TCompactProtocol.h>
|
||||
|
||||
#include <limits>
|
||||
#include <utility>
|
||||
#include <cassert>
|
||||
#include <string>
|
||||
#include <zlib.h>
|
||||
#include <string.h>
|
||||
#include <zlib.h>
|
||||
|
||||
using std::map;
|
||||
using boost::shared_ptr;
|
||||
@ -172,7 +172,7 @@ bool THeaderTransport::readFrame() {
|
||||
* Reads a string from ptr, taking care not to reach headerBoundary
|
||||
* Advances ptr on success
|
||||
*
|
||||
* @param str output string
|
||||
* @param str output string
|
||||
* @throws CORRUPTED_DATA if size of string exceeds boundary
|
||||
*/
|
||||
void THeaderTransport::readString(uint8_t*& ptr,
|
||||
@ -198,7 +198,10 @@ void THeaderTransport::readHeaderFormat(uint16_t headerSize, uint32_t sz) {
|
||||
uint8_t* ptr = reinterpret_cast<uint8_t*>(rBuf_.get() + 10);
|
||||
|
||||
// Catch integer overflow, check for reasonable header size
|
||||
assert(headerSize < 16384);
|
||||
if (headerSize >= 16384) {
|
||||
throw TTransportException(TTransportException::CORRUPTED_DATA,
|
||||
"Header size is unreasonable");
|
||||
}
|
||||
headerSize *= 4;
|
||||
const uint8_t* const headerBoundary = ptr + headerSize;
|
||||
if (headerSize > sz) {
|
||||
@ -252,7 +255,7 @@ void THeaderTransport::readHeaderFormat(uint16_t headerSize, uint32_t sz) {
|
||||
}
|
||||
|
||||
// Untransform the data section. rBuf will contain result.
|
||||
untransform(data, sz - (data - rBuf_.get())); // ignore header in size calc
|
||||
untransform(data, safe_numeric_cast<uint32_t>(static_cast<ptrdiff_t>(sz) - (data - rBuf_.get())));
|
||||
}
|
||||
|
||||
void THeaderTransport::untransform(uint8_t* ptr, uint32_t sz) {
|
||||
@ -375,7 +378,7 @@ void THeaderTransport::resetProtocol() {
|
||||
}
|
||||
|
||||
uint32_t THeaderTransport::getWriteBytes() {
|
||||
return wBase_ - wBuf_.get();
|
||||
return safe_numeric_cast<uint32_t>(wBase_ - wBuf_.get());
|
||||
}
|
||||
|
||||
/**
|
||||
@ -384,7 +387,7 @@ uint32_t THeaderTransport::getWriteBytes() {
|
||||
* Automatically advances ptr to after the written portion
|
||||
*/
|
||||
void THeaderTransport::writeString(uint8_t*& ptr, const string& str) {
|
||||
uint32_t strLen = str.length();
|
||||
int32_t strLen = safe_numeric_cast<int32_t>(str.length());
|
||||
ptr += writeVarint32(strLen, ptr);
|
||||
memcpy(ptr, str.c_str(), strLen); // no need to write \0
|
||||
ptr += strLen;
|
||||
@ -394,7 +397,7 @@ void THeaderTransport::setHeader(const string& key, const string& value) {
|
||||
writeHeaders_[key] = value;
|
||||
}
|
||||
|
||||
size_t THeaderTransport::getMaxWriteHeadersSize() const {
|
||||
uint32_t THeaderTransport::getMaxWriteHeadersSize() const {
|
||||
size_t maxWriteHeadersSize = 0;
|
||||
THeaderTransport::StringToStringMap::const_iterator it;
|
||||
for (it = writeHeaders_.begin(); it != writeHeaders_.end(); ++it) {
|
||||
@ -402,7 +405,7 @@ size_t THeaderTransport::getMaxWriteHeadersSize() const {
|
||||
// 2 varints32 + the strings themselves
|
||||
maxWriteHeadersSize += 5 + 5 + (it->first).length() + (it->second).length();
|
||||
}
|
||||
return maxWriteHeadersSize;
|
||||
return safe_numeric_cast<uint32_t>(maxWriteHeadersSize);
|
||||
}
|
||||
|
||||
void THeaderTransport::clearHeaders() {
|
||||
@ -431,7 +434,7 @@ void THeaderTransport::flush() {
|
||||
if (clientType == THRIFT_HEADER_CLIENT_TYPE) {
|
||||
// header size will need to be updated at the end because of varints.
|
||||
// Make it big enough here for max varint size, plus 4 for padding.
|
||||
int headerSize = (2 + getNumTransforms()) * THRIFT_MAX_VARINT32_BYTES + 4;
|
||||
uint32_t headerSize = (2 + getNumTransforms()) * THRIFT_MAX_VARINT32_BYTES + 4;
|
||||
// add approximate size of info headers
|
||||
headerSize += getMaxWriteHeadersSize();
|
||||
|
||||
@ -479,11 +482,11 @@ void THeaderTransport::flush() {
|
||||
// write info headers
|
||||
|
||||
// for now only write kv-headers
|
||||
uint16_t headerCount = writeHeaders_.size();
|
||||
int32_t headerCount = safe_numeric_cast<int32_t>(writeHeaders_.size());
|
||||
if (headerCount > 0) {
|
||||
pkt += writeVarint32(infoIdType::KEYVALUE, pkt);
|
||||
// Write key-value headers count
|
||||
pkt += writeVarint32(headerCount, pkt);
|
||||
pkt += writeVarint32(static_cast<int32_t>(headerCount), pkt);
|
||||
// Write info headers
|
||||
map<string, string>::const_iterator it;
|
||||
for (it = writeHeaders_.begin(); it != writeHeaders_.end(); ++it) {
|
||||
@ -494,7 +497,7 @@ void THeaderTransport::flush() {
|
||||
}
|
||||
|
||||
// Fixups after varint size calculations
|
||||
headerSize = (pkt - headerStart);
|
||||
headerSize = safe_numeric_cast<uint32_t>(pkt - headerStart);
|
||||
uint8_t padding = 4 - (headerSize % 4);
|
||||
headerSize += padding;
|
||||
|
||||
@ -504,8 +507,13 @@ void THeaderTransport::flush() {
|
||||
}
|
||||
|
||||
// Pkt size
|
||||
ptrdiff_t szHbp = (headerStart - pktStart - 4);
|
||||
if (static_cast<uint64_t>(szHbp) > static_cast<uint64_t>(std::numeric_limits<uint32_t>().max()) - (headerSize + haveBytes)) {
|
||||
throw TTransportException(TTransportException::CORRUPTED_DATA,
|
||||
"Header section size is unreasonable");
|
||||
}
|
||||
szHbo = headerSize + haveBytes // thrift header + payload
|
||||
+ (headerStart - pktStart - 4); // common header section
|
||||
+ static_cast<uint32_t>(szHbp); // common header section
|
||||
headerSizeN = htons(headerSize / 4);
|
||||
memcpy(headerSizePtr, &headerSizeN, sizeof(headerSizeN));
|
||||
|
||||
|
@ -21,11 +21,18 @@
|
||||
#define THRIFT_TRANSPORT_THEADERTRANSPORT_H_ 1
|
||||
|
||||
#include <bitset>
|
||||
#include <limits>
|
||||
#include <vector>
|
||||
#include <stdexcept>
|
||||
#include <string>
|
||||
#include <map>
|
||||
|
||||
#ifdef HAVE_STDINT_H
|
||||
#include <stdint.h>
|
||||
#elif HAVE_INTTYPES_H
|
||||
#include <inttypes.h>
|
||||
#endif
|
||||
|
||||
#include <boost/scoped_array.hpp>
|
||||
#include <boost/shared_ptr.hpp>
|
||||
|
||||
@ -135,8 +142,7 @@ public:
|
||||
void transform(uint8_t* ptr, uint32_t sz);
|
||||
|
||||
uint16_t getNumTransforms() const {
|
||||
int trans = writeTrans_.size();
|
||||
return trans;
|
||||
return safe_numeric_cast<uint16_t>(writeTrans_.size());
|
||||
}
|
||||
|
||||
void setTransform(uint16_t transId) { writeTrans_.push_back(transId); }
|
||||
@ -204,7 +210,7 @@ protected:
|
||||
/**
|
||||
* Returns the maximum number of bytes that write k/v headers can take
|
||||
*/
|
||||
size_t getMaxWriteHeadersSize() const;
|
||||
uint32_t getMaxWriteHeadersSize() const;
|
||||
|
||||
struct infoIdType {
|
||||
enum idType {
|
||||
|
@ -22,6 +22,7 @@
|
||||
#include <sstream>
|
||||
#include <boost/algorithm/string.hpp>
|
||||
|
||||
#include <thrift/config.h>
|
||||
#include <thrift/transport/THttpClient.h>
|
||||
#include <thrift/transport/TSocket.h>
|
||||
|
||||
@ -102,7 +103,7 @@ void THttpClient::flush() {
|
||||
std::ostringstream h;
|
||||
h << "POST " << path_ << " HTTP/1.1" << CRLF << "Host: " << host_ << CRLF
|
||||
<< "Content-Type: application/x-thrift" << CRLF << "Content-Length: " << len << CRLF
|
||||
<< "Accept: application/x-thrift" << CRLF << "User-Agent: Thrift/" << VERSION
|
||||
<< "Accept: application/x-thrift" << CRLF << "User-Agent: Thrift/" << PACKAGE_VERSION
|
||||
<< " (C++/THttpClient)" << CRLF << CRLF;
|
||||
string header = h.str();
|
||||
|
||||
|
@ -21,6 +21,7 @@
|
||||
#include <sstream>
|
||||
#include <iostream>
|
||||
|
||||
#include <thrift/config.h>
|
||||
#include <thrift/transport/THttpServer.h>
|
||||
#include <thrift/transport/TSocket.h>
|
||||
#if defined(_MSC_VER) || defined(__MINGW32__)
|
||||
@ -124,7 +125,7 @@ void THttpServer::flush() {
|
||||
// Construct the HTTP header
|
||||
std::ostringstream h;
|
||||
h << "HTTP/1.1 200 OK" << CRLF << "Date: " << getTimeRFC1123() << CRLF << "Server: Thrift/"
|
||||
<< VERSION << CRLF << "Access-Control-Allow-Origin: *" << CRLF
|
||||
<< PACKAGE_VERSION << CRLF << "Access-Control-Allow-Origin: *" << CRLF
|
||||
<< "Content-Type: application/x-thrift" << CRLF << "Content-Length: " << len << CRLF
|
||||
<< "Connection: Keep-Alive" << CRLF << CRLF;
|
||||
string header = h.str();
|
||||
|
@ -60,10 +60,6 @@
|
||||
#endif // _WIN32
|
||||
#endif
|
||||
|
||||
#if defined(_WIN32) && (_WIN32_WINNT < 0x0600)
|
||||
#define AI_ADDRCONFIG 0x0400
|
||||
#endif
|
||||
|
||||
template <class T>
|
||||
inline const SOCKOPT_CAST_T* const_cast_sockopt(const T* v) {
|
||||
return reinterpret_cast<const SOCKOPT_CAST_T*>(v);
|
||||
|
@ -53,10 +53,6 @@
|
||||
#endif // _WIN32
|
||||
#endif
|
||||
|
||||
#if defined(_WIN32) && (_WIN32_WINNT < 0x0600)
|
||||
#define AI_ADDRCONFIG 0x0400
|
||||
#endif
|
||||
|
||||
template <class T>
|
||||
inline const SOCKOPT_CAST_T* const_cast_sockopt(const T* v) {
|
||||
return reinterpret_cast<const SOCKOPT_CAST_T*>(v);
|
||||
|
@ -20,6 +20,7 @@
|
||||
#ifndef _THRIFT_TRANSPORT_TTRANSPORTEXCEPTION_H_
|
||||
#define _THRIFT_TRANSPORT_TTRANSPORTEXCEPTION_H_ 1
|
||||
|
||||
#include <boost/numeric/conversion/cast.hpp>
|
||||
#include <string>
|
||||
#include <thrift/Thrift.h>
|
||||
|
||||
@ -83,6 +84,21 @@ protected:
|
||||
/** Error code */
|
||||
TTransportExceptionType type_;
|
||||
};
|
||||
|
||||
/**
|
||||
* Legacy code in transport implementations have overflow issues
|
||||
* that need to be enforced.
|
||||
*/
|
||||
template <typename To, typename From> To safe_numeric_cast(From i) {
|
||||
try {
|
||||
return boost::numeric_cast<To>(i);
|
||||
}
|
||||
catch (const std::bad_cast& bc) {
|
||||
throw TTransportException(TTransportException::CORRUPTED_DATA,
|
||||
bc.what());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
} // apache::thrift::transport
|
||||
|
@ -36,6 +36,9 @@
|
||||
#define USE_BOOST_THREAD 1
|
||||
#endif
|
||||
|
||||
// Something that defines PRId64 is required to build
|
||||
#define HAVE_INTTYPES_H 1
|
||||
|
||||
// VS2010 or later has stdint.h
|
||||
#if _MSC_VER >= 1600
|
||||
#define HAVE_STDINT_H 1
|
||||
@ -65,7 +68,6 @@
|
||||
|
||||
#pragma warning(disable : 4996) // Deprecated posix name.
|
||||
|
||||
#define VERSION "1.0.0-dev"
|
||||
#define HAVE_GETTIMEOFDAY 1
|
||||
#define HAVE_SYS_STAT_H 1
|
||||
|
||||
|
@ -190,14 +190,14 @@ void testProtocol(const char* protoname) {
|
||||
|
||||
testNaked<TProto, int64_t>(0);
|
||||
for (int64_t i = 0; i < 62; i++) {
|
||||
testNaked<TProto, int64_t>(1L << i);
|
||||
testNaked<TProto, int64_t>(-(1L << i));
|
||||
testNaked<TProto, int64_t>(1LL << i);
|
||||
testNaked<TProto, int64_t>(-(1LL << i));
|
||||
}
|
||||
|
||||
testField<TProto, T_I64, int64_t>(0);
|
||||
for (int i = 0; i < 62; i++) {
|
||||
testField<TProto, T_I64, int64_t>(1L << i);
|
||||
testField<TProto, T_I64, int64_t>(-(1L << i));
|
||||
testField<TProto, T_I64, int64_t>(1LL << i);
|
||||
testField<TProto, T_I64, int64_t>(-(1LL << i));
|
||||
}
|
||||
|
||||
testNaked<TProto, double>(123.456);
|
||||
|
@ -19,7 +19,13 @@
|
||||
|
||||
include_directories(SYSTEM "${Boost_INCLUDE_DIRS}")
|
||||
|
||||
#Make sure gen-cpp files can be included
|
||||
add_definitions("-D__STDC_LIMIT_MACROS")
|
||||
|
||||
if (WITH_DYN_LINK_TEST)
|
||||
add_definitions( -DBOOST_TEST_DYN_LINK )
|
||||
endif()
|
||||
|
||||
# Make sure gen-cpp files can be included
|
||||
include_directories("${CMAKE_CURRENT_BINARY_DIR}")
|
||||
|
||||
# Create the thrift C++ test library
|
||||
@ -54,7 +60,6 @@ set(testgencpp_cob_SOURCES
|
||||
)
|
||||
add_library(testgencpp_cob STATIC ${testgencpp_cob_SOURCES})
|
||||
|
||||
|
||||
add_executable(Benchmark Benchmark.cpp)
|
||||
target_link_libraries(Benchmark testgencpp)
|
||||
LINK_AGAINST_THRIFT_LIBRARY(Benchmark thrift)
|
||||
|
@ -262,8 +262,9 @@ BOOST_AUTO_TEST_CASE(test_json_proto_8) {
|
||||
":[\"i8\",3,1,2,3]},\"13\":{\"lst\":[\"i16\",3,1,2,3]},\"14\":{\"lst\":[\"i64"
|
||||
"\",3,1,2,3]}}";
|
||||
|
||||
const std::size_t bufSiz = strlen(json_string) * sizeof(char);
|
||||
boost::shared_ptr<TMemoryBuffer> buffer(new TMemoryBuffer(
|
||||
(uint8_t*)(json_string), strlen(json_string)*sizeof(char)));
|
||||
(uint8_t*)(json_string), static_cast<uint32_t>(bufSiz)));
|
||||
boost::shared_ptr<TJSONProtocol> proto(new TJSONProtocol(buffer));
|
||||
|
||||
OneOfEach ooe2;
|
||||
|
@ -17,13 +17,19 @@
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
#define __STDC_FORMAT_MACROS
|
||||
|
||||
#ifndef _GNU_SOURCE
|
||||
#define _GNU_SOURCE // needed for getopt_long
|
||||
#endif
|
||||
|
||||
#if (_MSC_VER <= 1700)
|
||||
// polynomial and std::fill_t warning happens in MSVC 2010, 2013, maybe others
|
||||
// https://svn.boost.org/trac/boost/ticket/11426
|
||||
#pragma warning(disable:4996)
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_STDINT_H
|
||||
#include <stdint.h>
|
||||
#endif
|
||||
#ifdef HAVE_INTTYPES_H
|
||||
#include <inttypes.h>
|
||||
#endif
|
||||
|
@ -35,6 +35,8 @@ void ServerThread::start() {
|
||||
assert(!running_);
|
||||
running_ = true;
|
||||
|
||||
helper_.reset(new Helper(this));
|
||||
|
||||
// Start the other thread
|
||||
concurrency::PlatformThreadFactory threadFactory;
|
||||
threadFactory.setDetached(false);
|
||||
|
@ -71,8 +71,7 @@ public:
|
||||
class ServerThread {
|
||||
public:
|
||||
ServerThread(const boost::shared_ptr<ServerState>& state, bool autoStart)
|
||||
: helper_(new Helper(this)),
|
||||
port_(0),
|
||||
: port_(0),
|
||||
running_(false),
|
||||
serving_(false),
|
||||
error_(false),
|
||||
|
@ -33,7 +33,6 @@ include_directories("${CMAKE_CURRENT_BINARY_DIR}")
|
||||
include_directories("${CMAKE_CURRENT_BINARY_DIR}/gen-cpp")
|
||||
include_directories("${PROJECT_SOURCE_DIR}/lib/cpp/src")
|
||||
|
||||
|
||||
set(crosstestgencpp_SOURCES
|
||||
gen-cpp/ThriftTest.cpp
|
||||
gen-cpp/ThriftTest_types.cpp
|
||||
|
@ -107,7 +107,7 @@ gen-cpp/StressTest_types.cpp gen-cpp/StressTest_constants.cpp gen-cpp/Service.cp
|
||||
$(THRIFT) --gen cpp $<
|
||||
|
||||
AM_CPPFLAGS = $(BOOST_CPPFLAGS) $(LIBEVENT_CPPFLAGS) -I$(top_srcdir)/lib/cpp/src -Igen-cpp
|
||||
AM_CXXFLAGS = -Wall -Wextra -pedantic
|
||||
AM_CXXFLAGS = -Wall -Wextra -pedantic -D__STDC_LIMIT_MACROS
|
||||
AM_LDFLAGS = $(BOOST_LDFLAGS) $(LIBEVENT_LDFLAGS) $(ZLIB_LIBS)
|
||||
|
||||
clean-local:
|
||||
|
@ -1,4 +1,4 @@
|
||||
/*
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
@ -17,8 +17,6 @@
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
#define __STDC_FORMAT_MACROS
|
||||
#include <inttypes.h>
|
||||
#include <limits>
|
||||
#include <locale>
|
||||
#include <ios>
|
||||
@ -35,6 +33,13 @@
|
||||
#include <thrift/async/TEvhttpClientChannel.h>
|
||||
#include <thrift/server/TNonblockingServer.h> // <event.h>
|
||||
|
||||
#ifdef HAVE_STDINT_H
|
||||
#include <stdint.h>
|
||||
#endif
|
||||
#ifdef HAVE_INTTYPES_H
|
||||
#include <inttypes.h>
|
||||
#endif
|
||||
|
||||
#include <boost/shared_ptr.hpp>
|
||||
#include <boost/program_options.hpp>
|
||||
#include <boost/filesystem.hpp>
|
||||
@ -355,6 +360,10 @@ int main(int argc, char** argv) {
|
||||
}
|
||||
|
||||
try {
|
||||
#ifdef _MSC_VER
|
||||
#pragma warning( push )
|
||||
#pragma warning( disable : 4566 )
|
||||
#endif
|
||||
string str(
|
||||
"}{Afrikaans, Alemannisch, Aragonés, العربية, مصرى, "
|
||||
"Asturianu, Aymar aru, Azərbaycan, Башҡорт, Boarisch, Žemaitėška, "
|
||||
@ -381,6 +390,9 @@ int main(int argc, char** argv) {
|
||||
"Türkçe, Татарча/Tatarça, Українська, اردو, Tiếng Việt, Volapük, "
|
||||
"Walon, Winaray, 吴语, isiXhosa, ייִדיש, Yorùbá, Zeêuws, 中文, "
|
||||
"Bân-lâm-gú, 粵語");
|
||||
#ifdef _MSC_VER
|
||||
#pragma warning( pop )
|
||||
#endif
|
||||
cout << "testString(" << str << ") = " << flush;
|
||||
testClient.testString(s, str);
|
||||
cout << s << endl;
|
||||
@ -457,10 +469,10 @@ int main(int argc, char** argv) {
|
||||
BASETYPE_IDENTITY_TEST(testI64, (int64_t)-1);
|
||||
BASETYPE_IDENTITY_TEST(testI64, (int64_t)7000000000000000123LL);
|
||||
BASETYPE_IDENTITY_TEST(testI64, (int64_t)-7000000000000000123LL);
|
||||
BASETYPE_IDENTITY_TEST(testI64, (int64_t)pow(2LL, 32));
|
||||
BASETYPE_IDENTITY_TEST(testI64, (int64_t)-pow(2LL, 32));
|
||||
BASETYPE_IDENTITY_TEST(testI64, (int64_t)pow(2LL, 32) + 1);
|
||||
BASETYPE_IDENTITY_TEST(testI64, (int64_t)-pow(2LL, 32) - 1);
|
||||
BASETYPE_IDENTITY_TEST(testI64, (int64_t)pow(static_cast<double>(2LL), 32));
|
||||
BASETYPE_IDENTITY_TEST(testI64, (int64_t)-pow(static_cast<double>(2LL), 32));
|
||||
BASETYPE_IDENTITY_TEST(testI64, (int64_t)pow(static_cast<double>(2LL), 32) + 1);
|
||||
BASETYPE_IDENTITY_TEST(testI64, (int64_t)-pow(static_cast<double>(2LL), 32) - 1);
|
||||
BASETYPE_IDENTITY_TEST(testI64, numeric_limits<int64_t>::max());
|
||||
BASETYPE_IDENTITY_TEST(testI64, numeric_limits<int64_t>::min());
|
||||
|
||||
@ -472,19 +484,19 @@ int main(int argc, char** argv) {
|
||||
BASETYPE_IDENTITY_TEST(testDouble, -1.0);
|
||||
BASETYPE_IDENTITY_TEST(testDouble, -5.2098523);
|
||||
BASETYPE_IDENTITY_TEST(testDouble, -0.000341012439638598279);
|
||||
BASETYPE_IDENTITY_TEST(testDouble, pow(2, 32));
|
||||
BASETYPE_IDENTITY_TEST(testDouble, pow(2, 32) + 1);
|
||||
BASETYPE_IDENTITY_TEST(testDouble, pow(2, 53) - 1);
|
||||
BASETYPE_IDENTITY_TEST(testDouble, -pow(2, 32));
|
||||
BASETYPE_IDENTITY_TEST(testDouble, -pow(2, 32) - 1);
|
||||
BASETYPE_IDENTITY_TEST(testDouble, -pow(2, 53) + 1);
|
||||
BASETYPE_IDENTITY_TEST(testDouble, pow(static_cast<double>(2), 32));
|
||||
BASETYPE_IDENTITY_TEST(testDouble, pow(static_cast<double>(2), 32) + 1);
|
||||
BASETYPE_IDENTITY_TEST(testDouble, pow(static_cast<double>(2), 53) - 1);
|
||||
BASETYPE_IDENTITY_TEST(testDouble, -pow(static_cast<double>(2), 32));
|
||||
BASETYPE_IDENTITY_TEST(testDouble, -pow(static_cast<double>(2), 32) - 1);
|
||||
BASETYPE_IDENTITY_TEST(testDouble, -pow(static_cast<double>(2), 53) + 1);
|
||||
|
||||
try {
|
||||
double expected = pow(10, 307);
|
||||
double expected = pow(static_cast<double>(10), 307);
|
||||
cout << "testDouble(" << expected << ") = " << flush;
|
||||
double actual = testClient.testDouble(expected);
|
||||
cout << "(" << actual << ")" << endl;
|
||||
if (expected - actual > pow(10, 292)) {
|
||||
if (expected - actual > pow(static_cast<double>(10), 292)) {
|
||||
cout << "*** FAILED ***" << endl
|
||||
<< "Expected: " << expected << " but got: " << actual << endl;
|
||||
}
|
||||
@ -496,11 +508,11 @@ int main(int argc, char** argv) {
|
||||
}
|
||||
|
||||
try {
|
||||
double expected = pow(10, -292);
|
||||
double expected = pow(static_cast<double>(10), -292);
|
||||
cout << "testDouble(" << expected << ") = " << flush;
|
||||
double actual = testClient.testDouble(expected);
|
||||
cout << "(" << actual << ")" << endl;
|
||||
if (expected - actual > pow(10, -307)) {
|
||||
if (expected - actual > pow(static_cast<double>(10), -307)) {
|
||||
cout << "*** FAILED ***" << endl
|
||||
<< "Expected: " << expected << " but got: " << actual << endl;
|
||||
}
|
||||
|
@ -17,9 +17,6 @@
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
#define __STDC_FORMAT_MACROS
|
||||
#include <inttypes.h>
|
||||
|
||||
#include <thrift/concurrency/ThreadManager.h>
|
||||
#include <thrift/concurrency/PlatformThreadFactory.h>
|
||||
#include <thrift/protocol/TBinaryProtocol.h>
|
||||
@ -41,6 +38,13 @@
|
||||
#include <thrift/transport/TTransportUtils.h>
|
||||
#include "ThriftTest.h"
|
||||
|
||||
#ifdef HAVE_STDINT_H
|
||||
#include <stdint.h>
|
||||
#endif
|
||||
#ifdef HAVE_INTTYPES_H
|
||||
#include <inttypes.h>
|
||||
#endif
|
||||
|
||||
#include <iostream>
|
||||
#include <stdexcept>
|
||||
#include <sstream>
|
||||
|
@ -44,9 +44,13 @@ add_custom_command(OUTPUT gen-cpp/Calculator.cpp gen-cpp/SharedService.cpp gen-c
|
||||
add_executable(TutorialServer CppServer.cpp)
|
||||
target_link_libraries(TutorialServer tutorialgencpp)
|
||||
LINK_AGAINST_THRIFT_LIBRARY(TutorialServer thrift)
|
||||
target_link_libraries(TutorialServer ${ZLIB_LIBRARIES})
|
||||
if (ZLIB_FOUND)
|
||||
target_link_libraries(TutorialServer ${ZLIB_LIBRARIES})
|
||||
endif ()
|
||||
|
||||
add_executable(TutorialClient CppClient.cpp)
|
||||
target_link_libraries(TutorialClient tutorialgencpp)
|
||||
LINK_AGAINST_THRIFT_LIBRARY(TutorialClient thrift)
|
||||
target_link_libraries(TutorialClient ${ZLIB_LIBRARIES})
|
||||
if (ZLIB_FOUND)
|
||||
target_link_libraries(TutorialClient ${ZLIB_LIBRARIES})
|
||||
endif ()
|
||||
|
Loading…
Reference in New Issue
Block a user