Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 44ca541

Browse files
committed
Resolve clang-tidy bugprone warnings
Most of these issues are pretty innocuous, but I did find a couple places that constructors/destructors were relying on dynamic dispatch.
1 parent 65846fb commit 44ca541

16 files changed

+44
-38
lines changed

examples/AllTests/MockDocumentationTest.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,8 +125,8 @@ TEST(MockDocumentation, ObjectParameters)
125125
TEST(MockDocumentation, returnValue)
126126
{
127127
mock().expectOneCall("function").andReturnValue(10);
128-
int value = mock().actualCall("function").returnValue().getIntValue();
129-
value = mock().returnValue().getIntValue();
128+
mock().actualCall("function").returnValue().getIntValue();
129+
int value = mock().returnValue().getIntValue();
130130
LONGS_EQUAL(10, value);
131131
}
132132

include/CppUTest/UtestMacros.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,7 @@
312312
BITS_LOCATION(expected, actual, mask, text, __FILE__, __LINE__)
313313

314314
#define BITS_LOCATION(expected, actual, mask, text, file, line)\
315-
do { UtestShell::getCurrent()->assertBitsEqual(expected, actual, mask, sizeof(actual), text, file, line); } while(0)
315+
do { UtestShell::getCurrent()->assertBitsEqual(expected, actual, mask, sizeof(actual), text, file, line); } while(0) // NOLINT
316316

317317
#define ENUMS_EQUAL_INT(expected, actual)\
318318
ENUMS_EQUAL_TYPE(int, expected, actual)

include/CppUTestExt/MockCheckedActualCall.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ class MockCheckedActualCall : public MockActualCall
150150
MockOutputParametersListNode* outputParameterExpectations_;
151151

152152
virtual void addOutputParameter(const SimpleString& name, const SimpleString& type, void* ptr);
153-
virtual void cleanUpOutputParameterList();
153+
void cleanUpOutputParameterList();
154154
};
155155

156156
class MockActualCallTrace : public MockActualCall

src/CppUTest/CommandLineArguments.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,7 @@ bool CommandLineArguments::parse(TestPlugin* plugin)
7171
else if (argument == "-ll") listTestLocations_ = true;
7272
else if (argument == "-ri") runIgnored_ = true;
7373
else if (argument == "-f") crashOnFail_ = true;
74-
else if (argument == "-e") rethrowExceptions_ = false;
75-
else if (argument == "-ci") rethrowExceptions_ = false;
74+
else if ((argument == "-e") || (argument == "-ci")) rethrowExceptions_ = false;
7675
else if (argument.startsWith("-r")) setRepeatCount(ac_, av_, i);
7776
else if (argument.startsWith("-g")) addGroupFilter(ac_, av_, i);
7877
else if (argument.startsWith("-t")) correctParameters = addGroupDotNameFilter(ac_, av_, i, "-t", false, false);

src/CppUTest/MemoryLeakWarningPlugin.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ void cpputest_free_location_with_leak_detection(void* buffer, const char* file,
131131
#undef new
132132

133133
#if CPPUTEST_HAVE_EXCEPTIONS
134-
#define UT_THROW_BAD_ALLOC_WHEN_NULL(memory) if (memory == NULLPTR) throw CPPUTEST_BAD_ALLOC()
134+
#define UT_THROW_BAD_ALLOC_WHEN_NULL(memory) if ((memory) == NULLPTR) throw CPPUTEST_BAD_ALLOC()
135135
#else
136136
#define UT_THROW_BAD_ALLOC_WHEN_NULL(memory)
137137
#endif

src/CppUTest/SimpleString.cpp

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ GlobalSimpleStringMemoryAccountant::~GlobalSimpleStringMemoryAccountant()
6262

6363
void GlobalSimpleStringMemoryAccountant::restoreAllocator()
6464
{
65-
if (SimpleString::getStringAllocator() == allocator_)
65+
if (allocator_ && (SimpleString::getStringAllocator() == allocator_))
6666
SimpleString::setStringAllocator(allocator_->originalAllocator());
6767
}
6868

@@ -1031,19 +1031,17 @@ SimpleString StringFromMaskedBits(unsigned long value, unsigned long mask, size_
10311031

10321032
SimpleString StringFromOrdinalNumber(unsigned int number)
10331033
{
1034-
unsigned int onesDigit = number % 10;
1035-
1036-
const char* suffix;
1037-
if (number >= 11 && number <= 13) {
1038-
suffix = "th";
1039-
} else if (3 == onesDigit) {
1040-
suffix = "rd";
1041-
} else if (2 == onesDigit) {
1042-
suffix = "nd";
1043-
} else if (1 == onesDigit) {
1044-
suffix = "st";
1045-
} else {
1046-
suffix = "th";
1034+
const char* suffix = "th";
1035+
1036+
if ((number < 11) || (number > 13)) {
1037+
unsigned int const onesDigit = number % 10;
1038+
if (3 == onesDigit) {
1039+
suffix = "rd";
1040+
} else if (2 == onesDigit) {
1041+
suffix = "nd";
1042+
} else if (1 == onesDigit) {
1043+
suffix = "st";
1044+
}
10471045
}
10481046

10491047
return StringFromFormat("%u%s", number, suffix);

src/CppUTest/TestMemoryAllocator.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -418,7 +418,7 @@ MemoryAccountantAllocationNode* MemoryAccountant::createNewAccountantAllocationN
418418

419419
void MemoryAccountant::destroyAccountantAllocationNode(MemoryAccountantAllocationNode* node) const
420420
{
421-
allocator_->free_memory((char*) node, sizeof(node), __FILE__, __LINE__);
421+
allocator_->free_memory((char*) node, sizeof(node), __FILE__, __LINE__); // NOLINT
422422
}
423423

424424
MemoryAccountant::MemoryAccountant()
@@ -479,9 +479,9 @@ MemoryAccountantAllocationNode* MemoryAccountant::findNodeOfSize(size_t size) co
479479
{
480480
if (useCacheSizes_) {
481481
for (MemoryAccountantAllocationNode* node = head_; node; node = node->next_) {
482-
if (size > node->size_ && node->next_ == NULLPTR)
483-
return node;
484-
else if (size <= node->size_ && !(node->next_->size_ != 0 && node->next_->size_ <= size))
482+
if (((size > node->size_) && (node->next_ == NULLPTR))
483+
|| ((size <= node->size_) &&
484+
!((node->next_->size_ != 0) && (node->next_->size_ <= size))))
485485
return node;
486486
}
487487
}

src/CppUTestExt/CodeMemoryReportFormatter.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
#define MAX_VARIABLE_NAME_LINE_PART 10
3535
#define MAX_VARIABLE_NAME_FILE_PART 53
3636
#define MAX_VARIABLE_NAME_SEPERATOR_PART 1
37-
#define MAX_VARIABLE_NAME_LENGTH MAX_VARIABLE_NAME_FILE_PART + MAX_VARIABLE_NAME_SEPERATOR_PART + MAX_VARIABLE_NAME_LINE_PART
37+
#define MAX_VARIABLE_NAME_LENGTH (MAX_VARIABLE_NAME_FILE_PART + MAX_VARIABLE_NAME_SEPERATOR_PART + MAX_VARIABLE_NAME_LINE_PART)
3838

3939
struct CodeReportingAllocationNode
4040
{

src/CppUTestExt/MockSupport.cpp

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,18 @@ MockSupport& mock(const SimpleString& mockName, MockFailureReporter* failureRepo
4444
}
4545

4646
MockSupport::MockSupport(const SimpleString& mockName)
47-
: actualCallOrder_(0), expectedCallOrder_(0), strictOrdering_(false), standardReporter_(&defaultReporter_), ignoreOtherCalls_(false), enabled_(true), lastActualFunctionCall_(NULLPTR), mockName_(mockName), tracing_(false)
47+
:
48+
actualCallOrder_(0),
49+
expectedCallOrder_(0),
50+
strictOrdering_(false),
51+
activeReporter_(NULLPTR),
52+
standardReporter_(&defaultReporter_),
53+
ignoreOtherCalls_(false),
54+
enabled_(true),
55+
lastActualFunctionCall_(NULLPTR),
56+
mockName_(mockName),
57+
tracing_(false)
4858
{
49-
setActiveReporter(NULLPTR);
5059
}
5160

5261
MockSupport::~MockSupport()

tests/CppUTest/SimpleStringCacheTest.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ TEST(SimpleStringInternalCache, clearCacheWillRemoveAllCachedMemoryButNotAllUsed
188188
char* mem = cache.alloc(10);
189189
cache.dealloc(mem, 10);
190190

191-
mem = cache.alloc(60);
191+
cache.alloc(60);
192192

193193
cache.clearCache();
194194

tests/CppUTest/TestFailureNaNTest.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ TEST_GROUP(TestFailureNanAndInf)
5454
delete test;
5555
}
5656
};
57-
#define FAILURE_EQUAL(a, b) STRCMP_EQUAL_LOCATION(a, b.getMessage().asCharString(), "", __FILE__, __LINE__)
57+
#define FAILURE_EQUAL(a, b) STRCMP_EQUAL_LOCATION(a, (b).getMessage().asCharString(), "", __FILE__, __LINE__)
5858

5959
TEST(TestFailureNanAndInf, DoublesEqualExpectedIsNaN)
6060
{

tests/CppUTest/TestFailureTest.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ TEST_GROUP(TestFailure)
4747
delete test;
4848
}
4949
};
50-
#define FAILURE_EQUAL(a, b) STRCMP_EQUAL_LOCATION(a, b.getMessage().asCharString(), "", __FILE__, __LINE__)
50+
#define FAILURE_EQUAL(a, b) STRCMP_EQUAL_LOCATION(a, (b).getMessage().asCharString(), "", __FILE__, __LINE__)
5151

5252
TEST(TestFailure, CreateFailure)
5353
{

tests/CppUTest/TestMemoryAllocatorTest.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ TEST(TestMemoryAllocatorTest, NullUnknownNames)
127127

128128
#if (! CPPUTEST_SANITIZE_ADDRESS)
129129

130-
#define MAX_SIZE_FOR_ALLOC ((size_t) -1 > (unsigned short)-1) ? (size_t) -97 : (size_t) -1
130+
#define MAX_SIZE_FOR_ALLOC ((size_t) -1 > (unsigned short)-1) ? (size_t)(-97) : (size_t)(-1)
131131

132132
static void failTryingToAllocateTooMuchMemory(void)
133133
{

tests/CppUTest/TestUTestMacro.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -615,16 +615,16 @@ TEST(UnitTestMacros, FailureWithLONGS_EQUALS)
615615

616616
static void failingTestMethodWithLONGS_EQUALWithSymbolicParameters_()
617617
{
618-
#define _MONDAY 1
619-
int day_of_the_week = _MONDAY+1;
620-
LONGS_EQUAL(_MONDAY, day_of_the_week);
618+
#define MONDAY 1
619+
int day_of_the_week = MONDAY+1;
620+
LONGS_EQUAL(MONDAY, day_of_the_week);
621621
TestTestingFixture::lineExecutedAfterCheck(); // LCOV_EXCL_LINE
622622
} // LCOV_EXCL_LINE
623623

624624
TEST(UnitTestMacros, FailureWithLONGS_EQUALShowsSymbolicParameters)
625625
{
626626
fixture.runTestWithMethod(failingTestMethodWithLONGS_EQUALWithSymbolicParameters_);
627-
CHECK_TEST_FAILS_PROPER_WITH_TEXT("LONGS_EQUAL(_MONDAY, day_of_the_week) failed");
627+
CHECK_TEST_FAILS_PROPER_WITH_TEXT("LONGS_EQUAL(MONDAY, day_of_the_week) failed");
628628
CHECK_TEST_FAILS_PROPER_WITH_TEXT("expected <1 (0x1)>");
629629
CHECK_TEST_FAILS_PROPER_WITH_TEXT("but was <2 (0x2)>");
630630
CHECK_FALSE(fixture.getOutput().contains("Message: "));

tests/CppUTest/UtestPlatformTest.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ TEST(UTestPlatformsTest_PlatformSpecificRunTestInASeperateProcess, FailureInSepa
126126

127127
static int accessViolationTestFunction_()
128128
{
129-
return *(volatile int*) NULLPTR;
129+
return *(volatile int*) NULLPTR; // NOLINT
130130
}
131131

132132
TEST(UTestPlatformsTest_PlatformSpecificRunTestInASeperateProcess, AccessViolationInSeparateProcessWorks)

tests/CppUTestExt/OrderedTestTest.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ TEST_GROUP(TestOrderedTest)
8282

8383
TEST(TestOrderedTest, TestInstallerSetsFields)
8484
{
85-
OrderedTestInstaller(orderedTest, "testgroup", "testname", "this.cpp", 10, 5);
85+
OrderedTestInstaller installer(orderedTest, "testgroup", "testname", "this.cpp", 10, 5);
8686
STRCMP_EQUAL("testgroup", orderedTest.getGroup().asCharString());
8787
STRCMP_EQUAL("testname", orderedTest.getName().asCharString());
8888
STRCMP_EQUAL("this.cpp", orderedTest.getFile().asCharString());

0 commit comments

Comments
 (0)