Skip to content
Permalink
Browse files
GEODE-5753: Fixes google-readability-casting clang-tidy warning. (#368)
* Uses static_cast<> over C-style cast.
* Fixes ACE thread id to string.
  • Loading branch information
pivotal-jbarrett committed Oct 8, 2018
1 parent 1bf43b5 commit a905e8ba60b1a342274ee540f5fdc500fa211cea
Showing 46 changed files with 220 additions and 171 deletions.
@@ -1,6 +1,6 @@
---
Checks: '-*,clang-diagnostic-*,clang-analyzer-*,-clang-analyzer-alpha*,google-*,-google-readability-todo,-google-runtime-references'
WarningsAsErrors: 'google-build-using-namespace,google-readability-redundant-smartptr-get,google-explicit-constructor,google-global-names-in-headers,google-runtime-int'
Checks: '-*,clang-diagnostic-*,clang-analyzer-*,-clang-analyzer-alpha*,google-*,-google-readability-todo,-google-runtime-references,-google-default-arguments'
WarningsAsErrors: 'google-build-using-namespace,google-readability-redundant-smartptr-get,google-explicit-constructor,google-global-names-in-headers,google-runtime-int,google-readability-casting'
HeaderFilterRegex: '.*'
AnalyzeTemporaryDtors: false
FormatStyle: file
@@ -417,7 +417,8 @@ class APACHE_GEODE_EXPORT DataOutput {
inline void reset() {
if (m_haveBigBuffer) {
// create smaller buffer
m_bytes.reset((uint8_t*)std::malloc(m_lowWaterMark * sizeof(uint8_t)));
m_bytes.reset(
static_cast<uint8_t*>(std::malloc(m_lowWaterMark * sizeof(uint8_t))));
if (m_bytes == nullptr) {
throw OutOfMemoryException("Out of Memory while resizing buffer");
}
@@ -444,7 +445,8 @@ class APACHE_GEODE_EXPORT DataOutput {
m_size = newSize;

auto bytes = m_bytes.release();
auto tmp = (uint8_t*)std::realloc(bytes, m_size * sizeof(uint8_t));
auto tmp =
static_cast<uint8_t*>(std::realloc(bytes, m_size * sizeof(uint8_t)));
if (tmp == nullptr) {
throw OutOfMemoryException("Out of Memory while resizing buffer");
}
@@ -261,19 +261,19 @@ inline void readObject(apache::geode::client::DataInput& input, TObj*& array,
template <typename TObj,
typename std::enable_if<!std::is_base_of<Serializable, TObj>::value,
Serializable>::type* = nullptr>
inline uint32_t objectArraySize(const std::vector<TObj>& array) {
return (uint32_t)(sizeof(TObj) * array.size());
inline size_t objectArraySize(const std::vector<TObj>& array) {
return sizeof(TObj) * array.size();
}

template <typename TObj,
typename std::enable_if<std::is_base_of<Serializable, TObj>::value,
Serializable>::type* = nullptr>
inline uint32_t objectArraySize(const std::vector<TObj>& array) {
uint32_t size = 0;
inline size_t objectArraySize(const std::vector<TObj>& array) {
size_t size = 0;
for (auto obj : array) {
size += obj.objectArraySize();
}
size += (uint32_t)(sizeof(TObj) * array.size());
size += sizeof(TObj) * array.size();
return size;
}

@@ -48,9 +48,7 @@ inline int32_t hashcode(const int16_t value) {
return static_cast<int32_t>(value);
}

inline int32_t hashcode(const int32_t value) {
return static_cast<int32_t>(value);
}
inline int32_t hashcode(const int32_t value) { return value; }

inline int32_t hashcode(const int64_t value) {
int32_t hash = static_cast<int32_t>(value);
@@ -129,7 +129,7 @@ inline double random(double maxValue) {

template <typename TPRIM>
inline TPRIM random(TPRIM maxValue) {
return (TPRIM)random((double)maxValue);
return static_cast<TPRIM>(random(static_cast<double>(maxValue)));
}

// This returns an array allocated on heap
@@ -338,7 +338,8 @@ class CacheableDateWrapper : public CacheableWrapper {

const ACE_Time_Value currentTime = ACE_OS::gettimeofday();
timeofday = currentTime.sec();
time_t epoctime = (time_t)(timeofday + (rnd * (rnd % 2 == 0 ? 1 : -1)));
time_t epoctime =
static_cast<time_t>(timeofday + (rnd * (rnd % 2 == 0 ? 1 : -1)));

m_cacheableObject = CacheableDate::create(epoctime);
}
@@ -1035,7 +1036,7 @@ class CacheableNullStringWrapper : public CacheableWrapper {
// CacheableWrapper members

void initRandomValue(int32_t) override {
m_cacheableObject = CacheableString::create((char*)nullptr);
m_cacheableObject = CacheableString::create(static_cast<char*>(nullptr));
}

uint32_t getCheckSum(const std::shared_ptr<Cacheable> object) const override {
@@ -1,8 +1,3 @@
#pragma once

#ifndef GEODE_INTEGRATION_TEST_THINCLIENTSECURITYHELPER_H_
#define GEODE_INTEGRATION_TEST_THINCLIENTSECURITYHELPER_H_

/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
@@ -19,9 +14,17 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#pragma once

#ifndef GEODE_INTEGRATION_TEST_THINCLIENTSECURITYHELPER_H_
#define GEODE_INTEGRATION_TEST_THINCLIENTSECURITYHELPER_H_

#include <ace/Process.h>

#include "fw_dunit.hpp"
#include "ThinClientHelper.hpp"
#include "ace/Process.h"
#include "hacks/AceThreadId.h"

namespace {

@@ -214,7 +217,6 @@ class putThread : public ACE_Task_Base {
int svc(void) {
int ops = 0;
auto pid = ACE_OS::getpid();
auto thr_id = ACE_OS::thr_self();
std::shared_ptr<CacheableKey> key;
std::shared_ptr<CacheableString> value;
std::vector<std::shared_ptr<CacheableKey>> keys0;
@@ -262,8 +264,8 @@ class putThread : public ACE_Task_Base {
m_reg->destroy(key);
}
} catch (Exception& ex) {
printf("%d: %" PRIuPTR " exception got and exception message = %s\n",
pid, (uintptr_t)thr_id, ex.what());
printf("%d: %" PRIu64 " exception got and exception message = %s\n",
pid, hacks::aceThreadId(ACE_OS::thr_self()), ex.what());
}
}
}
@@ -176,10 +176,7 @@ class NamingContextImpl : virtual public NamingContext {
* otherwise returns 0.
*/
virtual int rebind(const char* key, int value) {
char buf[VALUE_MAX] = {0};
ACE_OS::sprintf(buf, "%d", value);
int res = rebind(key, (const char*)buf);
return res;
return rebind(key, std::to_string(value).c_str());
}

/**
@@ -103,7 +103,7 @@ BEGIN_TEST(int_t)
{
DataOutputInternal dataOutput;

dataOutput.writeInt((int32_t)0x11223344);
dataOutput.writeInt(static_cast<int32_t>(0x11223344));
const uint8_t* buffer = dataOutput.getBuffer();
dumpnbytes(buffer, 4);
ASSERT(buffer[0] == (uint8_t)0x11, "expected 0x11.");
@@ -101,7 +101,7 @@ class OtherType : public DataSerializable {

static std::shared_ptr<Cacheable> uniqueCT(int32_t i) {
auto ot = std::make_shared<OtherType>();
ot->m_struct.a = (int)i;
ot->m_struct.a = static_cast<int>(i);
ot->m_struct.b = (i % 2 == 0) ? true : false;
ot->m_struct.c = static_cast<char>(65) + i;
ot->m_struct.d = ((2.0) * static_cast<double>(i));
@@ -261,7 +261,7 @@ DUNIT_TASK_DEFINITION(CLIENT2, GetsTask)
// have deserialized on server so checks serialization/deserialization
// compatibility with java server.
std::string queryStr = "SELECT DISTINCT iter.key, iter.value FROM /";
queryStr += ((std::string)regionNames[0] + ".entrySet AS iter");
queryStr += (std::string(regionNames[0]) + ".entrySet AS iter");
dataReg->query(queryStr.c_str());
dataReg->localInvalidateRegion();
verifyReg->localInvalidateRegion();
@@ -79,7 +79,7 @@ uint8_t* createRandByteArray(int size) {
}
char* createRandCharArray(int size) {
char* ch;
ch = (char *) std::malloc((size + 1) * sizeof(char));
ch = static_cast<char*>(std::malloc((size + 1) * sizeof(char)));
if (ch == nullptr) {
throw OutOfMemoryException(
"Out of Memory while resizing buffer");
@@ -91,7 +91,7 @@ DUNIT_TASK(CLIENT2, SetupClient2)
"__TEST_POOL1__", true, true);
auto regPtr = getHelper()->getRegion(regionNames[0]);
regPtr->registerAllKeys();
auto keyPtr = CacheableKey::create((const char*)"key01");
auto keyPtr = CacheableKey::create("key01");
auto valPtr =
CacheableBytes::create(std::vector<int8_t>{'v','a','l','u','e','0','1'});
regPtr->put(keyPtr, valPtr);
@@ -44,7 +44,7 @@ DUNIT_TASK(CLIENT1, SetupClient1)
getHelper()->createPooledRegion(regionNames[0], false, locatorsG,
"__TEST_POOL1__", true, true);
auto regPtr = getHelper()->getRegion(regionNames[0]);
auto key = CacheableKey::create((const char*)"key01");
auto key = CacheableKey::create("key01");
ASSERT(!regPtr->containsKeyOnServer(key), "key should not be there");
}
END_TASK(SetupClient1)
@@ -1673,7 +1673,7 @@ DUNIT_TASK_DEFINITION(CLIENT2, modifyPdxInstance)
auto setVec = CacheableVector::create();
setVec->push_back(CacheableInt32::create(3));
setVec->push_back(CacheableInt32::create(4));
wpiPtr->setField("m_vector", (std::shared_ptr<Cacheable>)setVec);
wpiPtr->setField("m_vector", setVec);
rptr->put(keyport, wpiPtr);
newPiPtr = std::dynamic_pointer_cast<PdxInstance>(rptr->get(keyport));
ASSERT(newPiPtr->hasField("m_vector") == true, "m_vector = true expected");
@@ -1702,7 +1702,7 @@ DUNIT_TASK_DEFINITION(CLIENT2, modifyPdxInstance)
setarr->push_back(CacheableInt32::create(3));
setarr->push_back(CacheableInt32::create(4));
setarr->push_back(CacheableInt32::create(5));
wpiPtr->setField("m_arraylist", (std::shared_ptr<Cacheable>)setarr);
wpiPtr->setField("m_arraylist", setarr);
rptr->put(keyport, wpiPtr);
newPiPtr = std::dynamic_pointer_cast<PdxInstance>(rptr->get(keyport));
ASSERT(newPiPtr->hasField("m_arraylist") == true,
@@ -1733,7 +1733,7 @@ DUNIT_TASK_DEFINITION(CLIENT2, modifyPdxInstance)
hashset->insert(CacheableInt32::create(3));
hashset->insert(CacheableInt32::create(4));
hashset->insert(CacheableInt32::create(5));
wpiPtr->setField("m_chs", (std::shared_ptr<Cacheable>)hashset);
wpiPtr->setField("m_chs", hashset);
rptr->put(keyport, wpiPtr);
newPiPtr = std::dynamic_pointer_cast<PdxInstance>(rptr->get(keyport));
ASSERT(newPiPtr->hasField("m_chs") == true, "m_chs = true expected");
@@ -1759,7 +1759,7 @@ DUNIT_TASK_DEFINITION(CLIENT2, modifyPdxInstance)
hashmap->emplace(CacheableInt32::create(3), CacheableInt32::create(3));
hashmap->emplace(CacheableInt32::create(4), CacheableInt32::create(4));
hashmap->emplace(CacheableInt32::create(5), CacheableInt32::create(5));
wpiPtr->setField("m_map", (std::shared_ptr<Cacheable>)hashmap);
wpiPtr->setField("m_map", hashmap);
rptr->put(keyport, wpiPtr);
newPiPtr = std::dynamic_pointer_cast<PdxInstance>(rptr->get(keyport));
ASSERT(newPiPtr->hasField("m_map") == true, "m_map = true expected");
@@ -1785,7 +1785,7 @@ DUNIT_TASK_DEFINITION(CLIENT2, modifyPdxInstance)
linkedhashset->insert(CacheableInt32::create(3));
linkedhashset->insert(CacheableInt32::create(4));
linkedhashset->insert(CacheableInt32::create(5));
wpiPtr->setField("m_clhs", (std::shared_ptr<Cacheable>)linkedhashset);
wpiPtr->setField("m_clhs", linkedhashset);
rptr->put(keyport, wpiPtr);
newPiPtr = std::dynamic_pointer_cast<PdxInstance>(rptr->get(keyport));
ASSERT(newPiPtr->hasField("m_clhs") == true, "m_clhs = true expected");
@@ -1851,8 +1851,7 @@ DUNIT_TASK_DEFINITION(CLIENT2, modifyPdxInstance)

wpiPtr = pIPtr->createWriter();
try {
wpiPtr->setField("m_byteByteArray",
(std::shared_ptr<Cacheable>)linkedhashset);
wpiPtr->setField("m_byteByteArray", linkedhashset);
FAIL(
"setField on m_byteByteArray with linkedhashset value should throw "
"expected IllegalStateException");
@@ -1888,7 +1887,7 @@ DUNIT_TASK_DEFINITION(CLIENT2, modifyPdxInstance)
wpiPtr = pIPtr->createWriter();
auto childpdxobjPtr = std::make_shared<ChildPdx>(2);
LOGINFO("created new childPdx");
wpiPtr->setField("m_childPdx", (std::shared_ptr<Cacheable>)childpdxobjPtr);
wpiPtr->setField("m_childPdx", childpdxobjPtr);
LOGINFO("childPdx seField done");
rptr->put(keyport1, wpiPtr);
newPiPtr = std::dynamic_pointer_cast<PdxInstance>(rptr->get(keyport1));
@@ -102,8 +102,8 @@ DUNIT_TASK_DEFINITION(CLIENT1, InitClientCreateRegionAndRunQueries)
qh.populatePortfolioData(reg, qh.getPortfolioSetSize(),
qh.getPortfolioNumSets());

std::string qry1Str = (std::string) "select * from /" + qRegionNames[0];
std::string qry2Str = (std::string) "select * from /" + qRegionNames[1];
std::string qry1Str = std::string("select * from /") + qRegionNames[0];
std::string qry2Str = std::string("select * from /") + qRegionNames[1];

std::shared_ptr<QueryService> qs = nullptr;
qs = pool1->getQueryService();
@@ -164,8 +164,8 @@ DUNIT_TASK_DEFINITION(CLIENT1, CreateRegionAndRunQueries)
qh.populatePositionData(reg, qh.getPositionSetSize(),
qh.getPositionNumSets());

std::string qry1Str = (std::string) "select * from /" + qRegionNames[0];
std::string qry2Str = (std::string) "select * from /" + qRegionNames[1];
std::string qry1Str = std::string("select * from /") + qRegionNames[0];
std::string qry2Str = std::string("select * from /") + qRegionNames[1];

std::shared_ptr<QueryService> qs = nullptr;
qs = pool2->getQueryService();
@@ -41,7 +41,7 @@ using apache::geode::client::Pool;
static bool isLocalServer = false;
static bool isLocator = false;
static int numberOfLocators = 1;
const char* endPoints = (const char*)nullptr;
const char* endPoints = nullptr;
const char* locatorsG =
CacheHelper::getLocatorHostPort(isLocator, isLocalServer, numberOfLocators);

@@ -37,7 +37,7 @@ using apache::geode::client::Exception;
static bool isLocalServer = false;
static bool isLocator = false;
static int numberOfLocators = 1;
const char* endPoints = (const char*)nullptr;
const char* endPoints = nullptr;
const char* locatorsG =
CacheHelper::getLocatorHostPort(isLocator, isLocalServer, numberOfLocators);

@@ -0,0 +1,44 @@
/*
* 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.
*/

#pragma once

#ifndef INTERNAL_HACKS_ACETHREADID_H_
#define INTERNAL_HACKS_ACETHREADID_H_

#include <cstdint>
#include <type_traits>

namespace hacks {

template <class _T>
uint64_t aceThreadId(
_T&& thread,
typename std::enable_if<std::is_pointer<_T>::value>::type* = nullptr) {
return reinterpret_cast<uintptr_t>(thread);
}

template <class _T>
uint64_t aceThreadId(
_T&& thread,
typename std::enable_if<std::is_integral<_T>::value>::type* = nullptr) {
return thread;
}

} // namespace hacks

#endif // INTERNAL_HACKS_ACETHREADID_H_
@@ -127,7 +127,7 @@ void ClientProxyMembershipID::initObjectVars(
memcpy(&temp, hostAddr, 4);
m_memID.writeInt(static_cast<int32_t>(temp));
// m_memID.writeInt((int32_t)hostPort);
m_memID.writeInt((int32_t)synch_counter);
m_memID.writeInt(static_cast<int32_t>(synch_counter));
m_memID.writeString(hostname);
m_memID.write(splitBrainFlag); // splitbrain flags

@@ -80,7 +80,7 @@ class TSSDataOutput {
} else {
uint8_t* buf;
*size = 8192;
buf = (uint8_t*)std::malloc(8192 * sizeof(uint8_t));
buf = static_cast<uint8_t*>(std::malloc(8192 * sizeof(uint8_t)));
if (buf == nullptr) {
throw OutOfMemoryException("Out of Memory while resizing buffer");
}
@@ -58,7 +58,7 @@ class FairQueue {
T* mp = getNoGetLock(isClosed);

if (mp == nullptr && !isClosed) {
mp = getUntilWithToken(sec, isClosed, (void*)nullptr);
mp = getUntilWithToken(sec, isClosed, static_cast<void*>(nullptr));
}
return mp;
}

0 comments on commit a905e8b

Please sign in to comment.