MCPcopy Create free account
hub / github.com/cpputest/cpputest / addMemoryDump

Method addMemoryDump

src/CppUTest/MemoryLeakDetector.cpp:62–101  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

60}
61
62void SimpleStringBuffer::addMemoryDump(const void* memory, size_t memorySize)
63{
64 const unsigned char* byteMemory = (const unsigned char*)memory;
65 const size_t maxLineBytes = 16;
66 size_t currentPos = 0;
67 size_t p;
68
69 while (currentPos < memorySize) {
70 add(" %04lx: ", (unsigned long) currentPos);
71 size_t bytesInLine = memorySize - currentPos;
72 if (bytesInLine > maxLineBytes) {
73 bytesInLine = maxLineBytes;
74 }
75 const size_t leftoverBytes = maxLineBytes - bytesInLine;
76
77 for (p = 0; p < bytesInLine; p++) {
78 add("%02hx ", (unsigned short) byteMemory[currentPos + p]);
79 if (p == ((maxLineBytes / 2) - 1)) {
80 add(" ");
81 }
82 }
83 for (p = 0; p < leftoverBytes; p++) {
84 add(" ");
85 }
86 if (leftoverBytes > (maxLineBytes/2)) {
87 add(" ");
88 }
89
90 add("|");
91 for (p = 0; p < bytesInLine; p++) {
92 char toAdd = (char)byteMemory[currentPos + p];
93 if (toAdd < ' ' || toAdd > '~') {
94 toAdd = '.';
95 }
96 add("%c", (int)toAdd);
97 }
98 add("|\n");
99 currentPos += bytesInLine;
100 }
101}
102
103char* SimpleStringBuffer::toString()
104{

Callers 2

reportMemoryLeakMethod · 0.80
TESTFunction · 0.80

Calls

no outgoing calls

Tested by 1

TESTFunction · 0.64