Skip to content

Commit

Permalink
Merge pull request #1369 from basvodde/master
Browse files Browse the repository at this point in the history
Lots of int to size_t to remove and avoid future warnings.
  • Loading branch information
basvodde committed May 4, 2020
2 parents 7b1dd28 + 0530776 commit f7b4d15
Show file tree
Hide file tree
Showing 49 changed files with 464 additions and 448 deletions.
8 changes: 4 additions & 4 deletions include/CppUTest/CommandLineArguments.h
Expand Up @@ -48,10 +48,10 @@ class CommandLineArguments
bool isListingTestGroupNames() const;
bool isListingTestGroupAndCaseNames() const;
bool isRunIgnored() const;
int getRepeatCount() const;
size_t getRepeatCount() const;
bool isShuffling() const;
bool isReversing() const;
unsigned int getShuffleSeed() const;
size_t getShuffleSeed() const;
const TestFilter* getGroupFilters() const;
const TestFilter* getNameFilters() const;
bool isJUnitOutput() const;
Expand Down Expand Up @@ -83,8 +83,8 @@ class CommandLineArguments
bool reversing_;
bool shuffling_;
bool shufflingPreSeeded_;
int repeat_;
unsigned int shuffleSeed_;
size_t repeat_;
size_t shuffleSeed_;
TestFilter* groupFilters_;
TestFilter* nameFilters_;
OutputType outputType_;
Expand Down
1 change: 1 addition & 0 deletions include/CppUTest/JUnitTestOutput.h
Expand Up @@ -50,6 +50,7 @@ class JUnitTestOutput: public TestOutput
virtual void printBuffer(const char*) _override;
virtual void print(const char*) _override;
virtual void print(long) _override;
virtual void print(size_t) _override;
virtual void printFailure(const TestFailure& failure) _override;

virtual void flush() _override;
Expand Down
44 changes: 22 additions & 22 deletions include/CppUTest/MemoryLeakDetector.h
Expand Up @@ -86,30 +86,30 @@ class MemoryLeakOutputStringBuffer

void reportMemoryLeak(MemoryLeakDetectorNode* leak);

void reportDeallocateNonAllocatedMemoryFailure(const char* freeFile, int freeLine, TestMemoryAllocator* freeAllocator, MemoryLeakFailure* reporter);
void reportMemoryCorruptionFailure(MemoryLeakDetectorNode* node, const char* freeFile, int freeLineNumber, TestMemoryAllocator* freeAllocator, MemoryLeakFailure* reporter);
void reportAllocationDeallocationMismatchFailure(MemoryLeakDetectorNode* node, const char* freeFile, int freeLineNumber, TestMemoryAllocator* freeAllocator, MemoryLeakFailure* reporter);
void reportDeallocateNonAllocatedMemoryFailure(const char* freeFile, size_t freeLine, TestMemoryAllocator* freeAllocator, MemoryLeakFailure* reporter);
void reportMemoryCorruptionFailure(MemoryLeakDetectorNode* node, const char* freeFile, size_t freeLineNumber, TestMemoryAllocator* freeAllocator, MemoryLeakFailure* reporter);
void reportAllocationDeallocationMismatchFailure(MemoryLeakDetectorNode* node, const char* freeFile, size_t freeLineNumber, TestMemoryAllocator* freeAllocator, MemoryLeakFailure* reporter);
char* toString();

private:
void addAllocationLocation(const char* allocationFile, int allocationLineNumber, size_t allocationSize, TestMemoryAllocator* allocator);
void addDeallocationLocation(const char* freeFile, int freeLineNumber, TestMemoryAllocator* allocator);
void addAllocationLocation(const char* allocationFile, size_t allocationLineNumber, size_t allocationSize, TestMemoryAllocator* allocator);
void addDeallocationLocation(const char* freeFile, size_t freeLineNumber, TestMemoryAllocator* allocator);

void addMemoryLeakHeader();
void addMemoryLeakFooter(int totalAmountOfLeaks);
void addMemoryLeakFooter(size_t totalAmountOfLeaks);
void addWarningForUsingMalloc();
void addNoMemoryLeaksMessage();
void addErrorMessageForTooMuchLeaks();

private:

int total_leaks_;
size_t total_leaks_;
bool giveWarningOnUsingMalloc_;

void reportFailure(const char* message, const char* allocFile,
int allocLine, size_t allocSize,
size_t allocLine, size_t allocSize,
TestMemoryAllocator* allocAllocator, const char* freeFile,
int freeLine, TestMemoryAllocator* freeAllocator, MemoryLeakFailure* reporter);
size_t freeLine, TestMemoryAllocator* freeAllocator, MemoryLeakFailure* reporter);

SimpleStringBuffer outputBuffer_;
};
Expand All @@ -121,13 +121,13 @@ struct MemoryLeakDetectorNode
{
}

void init(char* memory, unsigned number, size_t size, TestMemoryAllocator* allocator, MemLeakPeriod period, unsigned char allocation_stage, const char* file, int line);
void init(char* memory, unsigned number, size_t size, TestMemoryAllocator* allocator, MemLeakPeriod period, unsigned char allocation_stage, const char* file, size_t line);

size_t size_;
unsigned number_;
char* memory_;
const char* file_;
int line_;
size_t line_;
TestMemoryAllocator* allocator_;
MemLeakPeriod period_;
unsigned char allocation_stage_;
Expand Down Expand Up @@ -156,7 +156,7 @@ struct MemoryLeakDetectorList
MemoryLeakDetectorNode* getLeakFrom(MemoryLeakDetectorNode* node, MemLeakPeriod period);
MemoryLeakDetectorNode* getLeakForAllocationStageFrom(MemoryLeakDetectorNode* node, unsigned char allocation_stage);

int getTotalLeaks(MemLeakPeriod period);
size_t getTotalLeaks(MemLeakPeriod period);
void clearAllAccounting(MemLeakPeriod period);

bool isInPeriod(MemoryLeakDetectorNode* node, MemLeakPeriod period);
Expand All @@ -174,7 +174,7 @@ struct MemoryLeakDetectorTable
MemoryLeakDetectorNode* retrieveNode(char* memory);
MemoryLeakDetectorNode* removeNode(char* memory);

int getTotalLeaks(MemLeakPeriod period);
size_t getTotalLeaks(MemLeakPeriod period);

MemoryLeakDetectorNode* getFirstLeak(MemLeakPeriod period);
MemoryLeakDetectorNode* getFirstLeakForAllocationStage(unsigned char allocation_stage);
Expand Down Expand Up @@ -212,16 +212,16 @@ class MemoryLeakDetector

const char* report(MemLeakPeriod period);
void markCheckingPeriodLeaksAsNonCheckingPeriod();
int totalMemoryLeaks(MemLeakPeriod period);
size_t totalMemoryLeaks(MemLeakPeriod period);
void clearAllAccounting(MemLeakPeriod period);

char* allocMemory(TestMemoryAllocator* allocator, size_t size, bool allocatNodesSeperately = false);
char* allocMemory(TestMemoryAllocator* allocator, size_t size,
const char* file, int line, bool allocatNodesSeperately = false);
const char* file, size_t line, bool allocatNodesSeperately = false);
void deallocMemory(TestMemoryAllocator* allocator, void* memory, bool allocatNodesSeperately = false);
void deallocMemory(TestMemoryAllocator* allocator, void* memory, const char* file, int line, bool allocatNodesSeperately = false);
void deallocMemory(TestMemoryAllocator* allocator, void* memory, const char* file, size_t line, bool allocatNodesSeperately = false);
void deallocAllMemoryInCurrentAllocationStage();
char* reallocMemory(TestMemoryAllocator* allocator, char* memory, size_t size, const char* file, int line, bool allocatNodesSeperately = false);
char* reallocMemory(TestMemoryAllocator* allocator, char* memory, size_t size, const char* file, size_t line, bool allocatNodesSeperately = false);

void invalidateMemory(char* memory);
void removeMemoryLeakInformationWithoutCheckingOrDeallocatingTheMemoryButDeallocatingTheAccountInformation(TestMemoryAllocator* allocator, void* memory, bool allocatNodesSeperately);
Expand All @@ -247,24 +247,24 @@ class MemoryLeakDetector
unsigned char current_allocation_stage_;
SimpleMutex* mutex_;

char* allocateMemoryWithAccountingInformation(TestMemoryAllocator* allocator, size_t size, const char* file, int line, bool allocatNodesSeperately);
char* reallocateMemoryWithAccountingInformation(TestMemoryAllocator* allocator, char* memory, size_t size, const char* file, int line, bool allocatNodesSeperately);
char* allocateMemoryWithAccountingInformation(TestMemoryAllocator* allocator, size_t size, const char* file, size_t line, bool allocatNodesSeperately);
char* reallocateMemoryWithAccountingInformation(TestMemoryAllocator* allocator, char* memory, size_t size, const char* file, size_t line, bool allocatNodesSeperately);
MemoryLeakDetectorNode* createMemoryLeakAccountingInformation(TestMemoryAllocator* allocator, size_t size, char* memory, bool allocatNodesSeperately);


bool validMemoryCorruptionInformation(char* memory);
bool matchingAllocation(TestMemoryAllocator *alloc_allocator, TestMemoryAllocator *free_allocator);

void storeLeakInformation(MemoryLeakDetectorNode * node, char *new_memory, size_t size, TestMemoryAllocator *allocator, const char *file, int line);
void storeLeakInformation(MemoryLeakDetectorNode * node, char *new_memory, size_t size, TestMemoryAllocator *allocator, const char *file, size_t line);
void ConstructMemoryLeakReport(MemLeakPeriod period);

size_t sizeOfMemoryWithCorruptionInfo(size_t size);
MemoryLeakDetectorNode* getNodeFromMemoryPointer(char* memory, size_t size);

char* reallocateMemoryAndLeakInformation(TestMemoryAllocator* allocator, char* memory, size_t size, const char* file, int line, bool allocatNodesSeperately);
char* reallocateMemoryAndLeakInformation(TestMemoryAllocator* allocator, char* memory, size_t size, const char* file, size_t line, bool allocatNodesSeperately);

void addMemoryCorruptionInformation(char* memory);
void checkForCorruption(MemoryLeakDetectorNode* node, const char* file, int line, TestMemoryAllocator* allocator, bool allocateNodesSeperately);
void checkForCorruption(MemoryLeakDetectorNode* node, const char* file, size_t line, TestMemoryAllocator* allocator, bool allocateNodesSeperately);
};

#endif
12 changes: 6 additions & 6 deletions include/CppUTest/MemoryLeakDetectorMallocMacros.h
Expand Up @@ -21,10 +21,10 @@ extern "C"
{
#endif

extern void* cpputest_malloc_location(size_t size, const char* file, int line);
extern void* cpputest_calloc_location(size_t count, size_t size, const char* file, int line);
extern void* cpputest_realloc_location(void *, size_t, const char* file, int line);
extern void cpputest_free_location(void* buffer, const char* file, int line);
extern void* cpputest_malloc_location(size_t size, const char* file, size_t line);
extern void* cpputest_calloc_location(size_t count, size_t size, const char* file, size_t line);
extern void* cpputest_realloc_location(void *, size_t, const char* file, size_t line);
extern void cpputest_free_location(void* buffer, const char* file, size_t line);

#ifdef __cplusplus
}
Expand Down Expand Up @@ -52,8 +52,8 @@ extern "C"
{
#endif

extern char* cpputest_strdup_location(const char* str, const char* file, int line);
extern char* cpputest_strndup_location(const char* str, size_t n, const char* file, int line);
extern char* cpputest_strdup_location(const char* str, const char* file, size_t line);
extern char* cpputest_strndup_location(const char* str, size_t n, const char* file, size_t line);

#ifdef __cplusplus
}
Expand Down
8 changes: 4 additions & 4 deletions include/CppUTest/MemoryLeakDetectorNewMacros.h
Expand Up @@ -51,13 +51,13 @@
#endif
#endif

void* operator new(size_t size, const char* file, int line) UT_THROW (std::bad_alloc);
void* operator new[](size_t size, const char* file, int line) UT_THROW (std::bad_alloc);
void* operator new(size_t size, const char* file, size_t line) UT_THROW (std::bad_alloc);
void* operator new[](size_t size, const char* file, size_t line) UT_THROW (std::bad_alloc);
void* operator new(size_t size) UT_THROW(std::bad_alloc);
void* operator new[](size_t size) UT_THROW(std::bad_alloc);

void operator delete(void* mem, const char* file, int line) UT_NOTHROW;
void operator delete[](void* mem, const char* file, int line) UT_NOTHROW;
void operator delete(void* mem, const char* file, size_t line) UT_NOTHROW;
void operator delete[](void* mem, const char* file, size_t line) UT_NOTHROW;
void operator delete(void* mem) UT_NOTHROW;
void operator delete[](void* mem) UT_NOTHROW;
#if __cplusplus >= 201402L
Expand Down
18 changes: 9 additions & 9 deletions include/CppUTest/MemoryLeakWarningPlugin.h
Expand Up @@ -31,8 +31,8 @@
#include "TestPlugin.h"
#include "MemoryLeakDetectorNewMacros.h"

#define IGNORE_ALL_LEAKS_IN_TEST() MemoryLeakWarningPlugin::getFirstPlugin()->ignoreAllLeaksInTest()
#define EXPECT_N_LEAKS(n) MemoryLeakWarningPlugin::getFirstPlugin()->expectLeaksInTest(n)
#define IGNORE_ALL_LEAKS_IN_TEST() if (MemoryLeakWarningPlugin::getFirstPlugin()) MemoryLeakWarningPlugin::getFirstPlugin()->ignoreAllLeaksInTest()
#define EXPECT_N_LEAKS(n) if (MemoryLeakWarningPlugin::getFirstPlugin()) MemoryLeakWarningPlugin::getFirstPlugin()->expectLeaksInTest(n)

extern void crash_on_allocation_number(unsigned alloc_number);

Expand All @@ -48,10 +48,10 @@ class MemoryLeakWarningPlugin: public TestPlugin
virtual void preTestAction(UtestShell& test, TestResult& result) _override;
virtual void postTestAction(UtestShell& test, TestResult& result) _override;

virtual const char* FinalReport(int toBeDeletedLeaks = 0);
virtual const char* FinalReport(size_t toBeDeletedLeaks = 0);

void ignoreAllLeaksInTest();
void expectLeaksInTest(int n);
void expectLeaksInTest(size_t n);

void destroyGlobalDetectorAndTurnOffMemoryLeakDetectionInDestructor(bool des);

Expand All @@ -76,14 +76,14 @@ class MemoryLeakWarningPlugin: public TestPlugin
MemoryLeakDetector* memLeakDetector_;
bool ignoreAllWarnings_;
bool destroyGlobalDetectorAndTurnOfMemoryLeakDetectionInDestructor_;
int expectedLeaks_;
int failureCount_;
size_t expectedLeaks_;
size_t failureCount_;

static MemoryLeakWarningPlugin* firstPlugin_;
};

extern void* cpputest_malloc_location_with_leak_detection(size_t size, const char* file, int line);
extern void* cpputest_realloc_location_with_leak_detection(void* memory, size_t size, const char* file, int line);
extern void cpputest_free_location_with_leak_detection(void* buffer, const char* file, int line);
extern void* cpputest_malloc_location_with_leak_detection(size_t size, const char* file, size_t line);
extern void* cpputest_realloc_location_with_leak_detection(void* memory, size_t size, const char* file, size_t line);
extern void cpputest_free_location_with_leak_detection(void* buffer, const char* file, size_t line);

#endif
4 changes: 2 additions & 2 deletions include/CppUTest/SimpleString.h
Expand Up @@ -101,8 +101,8 @@ class SimpleString
static const char* StrStr(const char* s1, const char* s2);
static char ToLower(char ch);
static int MemCmp(const void* s1, const void *s2, size_t n);
static char* allocStringBuffer(size_t size, const char* file, int line);
static void deallocStringBuffer(char* str, const char* file, int line);
static char* allocStringBuffer(size_t size, const char* file, size_t line);
static void deallocStringBuffer(char* str, const char* file, size_t line);
private:
char *buffer_;

Expand Down

0 comments on commit f7b4d15

Please sign in to comment.