Skip to content

Commit 728f0ea

Browse files
committed
DBG: fix various issues pointed out by Visual Studio code analysis
1 parent d62f7f4 commit 728f0ea

22 files changed

+71
-93
lines changed

src/bridge/bridgegraph.h

Lines changed: 15 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -40,16 +40,16 @@ typedef struct
4040

4141
struct BridgeCFNode
4242
{
43-
duint parentGraph; //function of which this node is a part
44-
duint start; //start of the block
45-
duint end; //end of the block (inclusive)
46-
duint brtrue; //destination if condition is true
47-
duint brfalse; //destination if condition is false
48-
duint icount; //number of instructions in node
49-
bool terminal; //node is a RET
50-
bool split; //node is a split (brtrue points to the next node)
51-
bool indirectcall; //node contains indirect calls (call reg, call [reg+X])
52-
void* userdata; //user data
43+
duint parentGraph = 0; //function of which this node is a part
44+
duint start = 0; //start of the block
45+
duint end = 0; //end of the block (inclusive)
46+
duint brtrue = 0; //destination if condition is true
47+
duint brfalse = 0; //destination if condition is false
48+
duint icount = 0; //number of instructions in node
49+
bool terminal = false; //node is a RET
50+
bool split = false; //node is a split (brtrue points to the next node)
51+
bool indirectcall = false; //node contains indirect calls (call reg, call [reg+X])
52+
void* userdata = nullptr; //user data
5353
std::vector<duint> exits; //exits (including brtrue and brfalse)
5454
std::vector<BridgeCFInstruction> instrs; //block instructions
5555

@@ -61,7 +61,9 @@ struct BridgeCFNode
6161
__debugbreak();
6262
}
6363

64-
explicit BridgeCFNode(const BridgeCFNodeList* nodeList, bool freedata)
64+
BridgeCFNode() = default;
65+
66+
BridgeCFNode(const BridgeCFNodeList* nodeList, bool freedata)
6567
{
6668
if(!nodeList)
6769
__debugbreak();
@@ -81,30 +83,10 @@ struct BridgeCFNode
8183
__debugbreak();
8284
}
8385

84-
explicit BridgeCFNode(duint parentGraph, duint start, duint end)
86+
BridgeCFNode(duint parentGraph, duint start, duint end)
8587
: parentGraph(parentGraph),
8688
start(start),
87-
end(end),
88-
brtrue(0),
89-
brfalse(0),
90-
icount(0),
91-
terminal(false),
92-
indirectcall(false),
93-
split(false),
94-
userdata(nullptr)
95-
{
96-
}
97-
98-
explicit BridgeCFNode()
99-
: parentGraph(0),
100-
start(0),
101-
end(0),
102-
brtrue(0),
103-
brfalse(0),
104-
icount(0),
105-
terminal(false),
106-
split(false),
107-
userdata(nullptr)
89+
end(end)
10890
{
10991
}
11092

src/dbg/TraceRecord.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
TraceRecordManager TraceRecord;
1515

16-
TraceRecordManager::TraceRecordManager() : instructionCounter(0)
16+
TraceRecordManager::TraceRecordManager()
1717
{
1818
ModuleNames.emplace_back("");
1919
}

src/dbg/TraceRecord.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -94,11 +94,11 @@ class TraceRecordManager
9494
std::unordered_map<duint, TraceRecordPage> TraceRecord;
9595
std::vector<std::string> ModuleNames;
9696
unsigned int getModuleIndex(const String & moduleName);
97-
unsigned int instructionCounter;
97+
unsigned int instructionCounter = 0;
9898

99-
bool rtEnabled;
100-
bool rtPrevInstAvailable;
101-
HANDLE rtFile;
99+
bool rtEnabled = false;
100+
bool rtPrevInstAvailable = false;
101+
HANDLE rtFile = nullptr;
102102

103103
REGDUMPWORD rtOldContext;
104104
bool rtOldContextChanged[(FIELD_OFFSET(REGDUMP, lastError) + sizeof(DWORD)) / sizeof(duint)];

src/dbg/WinInet-Downloader/downslib.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ downslib_error downslib_download(const char* url,
7878

7979
// Get HTTP content length
8080
char buffer[2048];
81+
memset(buffer, 0, sizeof(buffer));
8182
DWORD dwLen = sizeof(buffer);
8283
unsigned long long total_bytes = 0;
8384
if(HttpQueryInfoA(hUrl, HTTP_QUERY_CONTENT_LENGTH, buffer, &dwLen, 0))

src/dbg/analysis/advancedanalysis.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ class AdvancedAnalysis : public Analysis
4343

4444
String ToString() const
4545
{
46-
return StringUtils::sprintf("start: p\nend: p\nfunction: %p", start, end, parentGraph);
46+
return StringUtils::sprintf("start: %p\nend: %p\nfunction: %p", start, end, parentGraph);
4747
}
4848
};
4949

src/dbg/commands/cmd-undocumented.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,7 @@ bool cbInstrZydis(int argc, char* argv[])
291291
dprintf_untranslated("register: %s\n", cp.RegName(op.reg.value));
292292
break;
293293
case ZYDIS_OPERAND_TYPE_IMMEDIATE:
294-
dprintf_untranslated("immediate: 0x%p\n", op.imm.value);
294+
dprintf_untranslated("immediate: 0x%p\n", op.imm.value.u);
295295
break;
296296
case ZYDIS_OPERAND_TYPE_MEMORY:
297297
{

src/dbg/datainst_helper.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -114,14 +114,12 @@ duint decodesimpledata(const unsigned char* buffer, ENCODETYPE type)
114114

115115
struct DataInstruction
116116
{
117-
ENCODETYPE type;
117+
ENCODETYPE type = enc_unknown;
118118
String operand;
119119
};
120120

121121
bool parsedatainstruction(const char* instruction, DataInstruction & di)
122122
{
123-
di.type = enc_unknown;
124-
di.operand.clear();
125123
String instStr = StringUtils::Trim(String(instruction));
126124
size_t pos = instStr.find_first_of(" \t");
127125
String opcode = instStr.substr(0, pos);

src/dbg/expressionfunctions.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@ class ExpressionFunctions
1919
struct Function
2020
{
2121
String name;
22-
int argc;
22+
int argc = 0;
2323
CBEXPRESSIONFUNCTION cbFunction;
24-
void* userdata;
24+
void* userdata = nullptr;
2525
std::vector<String> aliases;
2626
};
2727

src/dbg/exprfunc.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -457,7 +457,7 @@ namespace Exprfunc
457457

458458
duint exinfo(duint index)
459459
{
460-
if(index >= 16)
460+
if(index >= EXCEPTION_MAXIMUM_PARAMETERS)
461461
return 0;
462462
return getLastExceptionInfo().ExceptionRecord.ExceptionInformation[index];
463463
}

src/dbg/formatfunctions.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class FormatFunctions
2020
{
2121
String type;
2222
CBFORMATFUNCTION cbFunction;
23-
void* userdata;
23+
void* userdata = nullptr;
2424
std::vector<String> aliases;
2525
};
2626

src/dbg/module.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,9 @@ struct MODEXPORT : SymbolInfoGui
6464

6565
struct MODIMPORT : SymbolInfoGui
6666
{
67-
size_t moduleIndex; //index in MODINFO.importModules
68-
DWORD iatRva;
69-
duint ordinal; //equal to -1 if imported by name
67+
size_t moduleIndex = 0; //index in MODINFO.importModules
68+
DWORD iatRva = 0;
69+
duint ordinal = -1; //equal to -1 if imported by name
7070
String name;
7171
String undecoratedName;
7272

src/dbg/msgqueue.cpp

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,7 @@
33
// Allocate a message stack
44
MESSAGE_STACK* MsgAllocStack()
55
{
6-
auto stack = new MESSAGE_STACK;
7-
8-
stack->WaitingCalls = 0;
9-
stack->Destroy = false;
10-
11-
return stack;
6+
return new MESSAGE_STACK();
127
}
138

149
// Free a message stack

src/dbg/msgqueue.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ class MESSAGE_STACK
2020
public:
2121
Concurrency::unbounded_buffer<MESSAGE> msgs;
2222

23-
int WaitingCalls; // Number of threads waiting
24-
bool Destroy; // Destroy stack as soon as possible
23+
int WaitingCalls = 0; // Number of threads waiting
24+
bool Destroy = false; // Destroy stack as soon as possible
2525
};
2626

2727
// Function definitions

src/dbg/pdbdiafile.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ class PDBDiaFile
1919
struct Query_t
2020
{
2121
std::function<bool(DiaSymbol_t &)> callback;
22-
bool collectUndecoratedNames;
23-
bool collectSize;
22+
bool collectUndecoratedNames = false;
23+
bool collectSize = false;
2424
};
2525

2626
private:

src/dbg/pdbdiatypes.h

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -58,17 +58,17 @@ struct DiaValidationData_t
5858

5959
struct DiaSymbol_t
6060
{
61-
DiaSymbolType type;
62-
uint64_t virtualAddress;
63-
uint64_t size;
64-
uint32_t offset;
65-
uint32_t disp;
66-
uint32_t segment;
67-
DiaReachableType reachable;
68-
DiaReturnableType returnable;
69-
DiaCallingConvention convention;
70-
bool perfectSize;
71-
bool publicSymbol;
61+
DiaSymbolType type = DiaSymbolType::ANY;
62+
uint64_t virtualAddress = 0;
63+
uint64_t size = 0;
64+
uint32_t offset = 0;
65+
uint32_t disp = 0;
66+
uint32_t segment = 0;
67+
DiaReachableType reachable = DiaReachableType::UNKNOWN;
68+
DiaReturnableType returnable = DiaReturnableType::UNKNOWN;
69+
DiaCallingConvention convention = DiaCallingConvention::UNKNOWN;
70+
bool perfectSize = false;
71+
bool publicSymbol = false;
7272
std::string name;
7373
std::string undecoratedName;
7474
};

src/dbg/stringutils.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -398,7 +398,7 @@ void StringUtils::ReplaceAll(WString & s, const WString & from, const WString &
398398
}
399399
}
400400

401-
String StringUtils::vsprintf(const char* format, va_list args)
401+
String StringUtils::vsprintf(_In_z_ _Printf_format_string_ const char* format, va_list args)
402402
{
403403
char sbuffer[64] = "";
404404
if(_vsnprintf_s(sbuffer, _TRUNCATE, format, args) != -1)
@@ -419,7 +419,7 @@ String StringUtils::vsprintf(const char* format, va_list args)
419419
return String(buffer.data());
420420
}
421421

422-
String StringUtils::sprintf(_Printf_format_string_ const char* format, ...)
422+
String StringUtils::sprintf(_In_z_ _Printf_format_string_ const char* format, ...)
423423
{
424424
va_list args;
425425
va_start(args, format);
@@ -428,7 +428,7 @@ String StringUtils::sprintf(_Printf_format_string_ const char* format, ...)
428428
return result;
429429
}
430430

431-
WString StringUtils::vsprintf(const wchar_t* format, va_list args)
431+
WString StringUtils::vsprintf(_In_z_ _Printf_format_string_ const wchar_t* format, va_list args)
432432
{
433433
wchar_t sbuffer[64] = L"";
434434
if(_vsnwprintf_s(sbuffer, _TRUNCATE, format, args) != -1)
@@ -449,7 +449,7 @@ WString StringUtils::vsprintf(const wchar_t* format, va_list args)
449449
return WString(buffer.data());
450450
}
451451

452-
WString StringUtils::sprintf(_Printf_format_string_ const wchar_t* format, ...)
452+
WString StringUtils::sprintf(_In_z_ _Printf_format_string_ const wchar_t* format, ...)
453453
{
454454
va_list args;
455455
va_start(args, format);

src/dbg/symbolinfo.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
struct SYMBOLCBDATA
1818
{
1919
CBSYMBOLENUM cbSymbolEnum;
20-
void* user;
20+
void* user = nullptr;
2121
std::vector<char> decoratedSymbol;
2222
std::vector<char> undecoratedSymbol;
2323
};

src/dbg/symbolsourcebase.h

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,12 @@ struct SymbolInfoGui
1515

1616
struct SymbolInfo : SymbolInfoGui
1717
{
18-
duint rva;
19-
duint size;
20-
int32 disp;
18+
duint rva = 0;
19+
duint size = 0;
20+
int32 disp = 0;
2121
String decoratedName;
2222
String undecoratedName;
23-
bool publicSymbol;
23+
bool publicSymbol = false;
2424

2525
void convertToGuiSymbol(duint modbase, SYMBOLINFO* info) const override
2626
{
@@ -35,10 +35,10 @@ struct SymbolInfo : SymbolInfoGui
3535

3636
struct LineInfo
3737
{
38-
duint rva;
39-
duint size;
40-
duint disp;
41-
int lineNumber;
38+
duint rva = 0;
39+
duint size = 0;
40+
duint disp = 0;
41+
int lineNumber = 0;
4242
String sourceFile;
4343
};
4444

src/dbg/symbolundecorator.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,9 @@ enum
5757
X_UNDNAME_NO_PTR64 = 0x20000, //Does not include ptr64 in output.
5858
};
5959

60-
#if _MSC_VER != 1800
60+
#if _MSC_VER == 1800 || _MSC_VER == 1900 || (_MSC_VER >= 1910 && _MSC_VER <= 1921)
61+
// Tested compiler version
62+
#else
6163
#error unDNameEx is undocumented and possibly unsupported on your runtime! Uncomment this line if you understand the risks and want continue regardless...
6264
#endif //_MSC_VER
6365

src/dbg/types.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,8 @@ namespace Types
6565
std::string owner; //Function owner
6666
std::string name; //Function identifier
6767
std::string rettype; //Function return type
68-
CallingConvention callconv; //Function calling convention
69-
bool noreturn; //Function does not return (ExitProcess, _exit)
68+
CallingConvention callconv = Cdecl; //Function calling convention
69+
bool noreturn = false; //Function does not return (ExitProcess, _exit)
7070
std::vector<Member> args; //Function arguments
7171
};
7272

@@ -87,7 +87,7 @@ namespace Types
8787
std::string kind;
8888
std::string name;
8989
std::string owner;
90-
int size;
90+
int size = 0;
9191
};
9292

9393
explicit TypeManager();

src/dbg/variable.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,18 +23,18 @@ struct VAR_VALUE
2323
{
2424
union
2525
{
26-
duint value;
26+
duint value = 0;
2727
std::vector<unsigned char>* data;
2828
} u;
29-
VAR_VALUE_TYPE type;
30-
int size;
29+
VAR_VALUE_TYPE type = VAR_UINT;
30+
int size = 0;
3131
};
3232

3333
struct VAR
3434
{
3535
String name;
3636
String alias;
37-
VAR_TYPE type;
37+
VAR_TYPE type = VAR_SYSTEM;
3838
VAR_VALUE value;
3939
};
4040

src/dbg/xrefs.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
struct XREFSINFO : AddrInfo
55
{
6-
XREFTYPE type;
6+
XREFTYPE type = XREF_NONE;
77
std::unordered_map<duint, XREF_RECORD> references;
88
};
99

0 commit comments

Comments
 (0)