Skip to content

Commit af60418

Browse files
committed
Fix some VS2019 warnings, Fix empty unicode strings, Improve macro usage
1 parent 952c7ed commit af60418

File tree

12 files changed

+56
-55
lines changed

12 files changed

+56
-55
lines changed

ProcessHacker/memedit.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ VOID PhShowMemoryEditorDialog(
120120
return;
121121
}
122122

123-
if (SelectOffset != -1)
123+
if (SelectOffset != ULONG_MAX)
124124
PostMessage(context->WindowHandle, WM_PH_SELECT_OFFSET, SelectOffset, SelectLength);
125125

126126
PhRegisterDialog(context->WindowHandle);
@@ -138,7 +138,7 @@ VOID PhShowMemoryEditorDialog(
138138
else
139139
SetForegroundWindow(context->WindowHandle);
140140

141-
if (SelectOffset != -1)
141+
if (SelectOffset != ULONG_MAX)
142142
PostMessage(context->WindowHandle, WM_PH_SELECT_OFFSET, SelectOffset, SelectLength);
143143

144144
// Just in case.
@@ -542,7 +542,7 @@ INT_PTR CALLBACK PhpMemoryEditorDlgProc(
542542
case WM_PH_SELECT_OFFSET:
543543
{
544544
HexEdit_SetEditMode(context->HexEditHandle, EDIT_ASCII);
545-
HexEdit_SetSel(context->HexEditHandle, (ULONG)wParam, (ULONG)wParam + (ULONG)lParam);
545+
HexEdit_SetSel(context->HexEditHandle, (ULONG)wParam, PtrToUlong(PTR_ADD_OFFSET(wParam, lParam)));
546546
}
547547
break;
548548
}

ProcessHacker/procprp.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -459,9 +459,9 @@ BOOLEAN PhPropPageDlgProcHeader(
459459
_In_ HWND hwndDlg,
460460
_In_ UINT uMsg,
461461
_In_ LPARAM lParam,
462-
_Out_ LPPROPSHEETPAGE *PropSheetPage,
463-
_Out_ PPH_PROCESS_PROPPAGECONTEXT *PropPageContext,
464-
_Out_ PPH_PROCESS_ITEM *ProcessItem
462+
_Out_opt_ LPPROPSHEETPAGE *PropSheetPage,
463+
_Out_opt_ PPH_PROCESS_PROPPAGECONTEXT *PropPageContext,
464+
_Out_opt_ PPH_PROCESS_ITEM *ProcessItem
465465
)
466466
{
467467
LPPROPSHEETPAGE propSheetPage;

ProcessHacker/prpgwmi.c

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -142,22 +142,25 @@ HRESULT PhpWmiProviderExecMethod(
142142
VariantClear(&variant);
143143
}
144144

145-
if (
146-
PhEqualString(Entry->NamespacePath, namespacePath, FALSE) &&
147-
PhEqualString(Entry->ProviderName, providerName, FALSE) &&
148-
PhEqualString(Entry->UserName, userName, FALSE)
149-
)
145+
if (namespacePath && providerName && userName && instancePath)
150146
{
151-
status = IWbemServices_ExecMethod(
152-
wbemServices,
153-
instancePath->Buffer,
154-
Method,
155-
0,
156-
NULL,
157-
wbemClassObject,
158-
NULL,
159-
NULL
160-
);
147+
if (
148+
PhEqualString(Entry->NamespacePath, namespacePath, FALSE) &&
149+
PhEqualString(Entry->ProviderName, providerName, FALSE) &&
150+
PhEqualString(Entry->UserName, userName, FALSE)
151+
)
152+
{
153+
status = IWbemServices_ExecMethod(
154+
wbemServices,
155+
instancePath->Buffer,
156+
Method,
157+
0,
158+
NULL,
159+
wbemClassObject,
160+
NULL,
161+
NULL
162+
);
163+
}
161164
}
162165

163166
if (instancePath)

ProcessHacker/thrdlist.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -610,7 +610,7 @@ BOOLEAN NTAPI PhpThreadTreeNewCallback(
610610
if (PhFormatToBuffer(&format, 1, node->ThreadIdText, sizeof(node->ThreadIdText), &returnLength))
611611
{
612612
getCellText->Text.Buffer = node->ThreadIdText;
613-
getCellText->Text.Length = returnLength - sizeof(WCHAR); // minus null terminator
613+
getCellText->Text.Length = returnLength - sizeof(UNICODE_NULL); // minus null terminator
614614
}
615615
}
616616
break;
@@ -630,7 +630,7 @@ BOOLEAN NTAPI PhpThreadTreeNewCallback(
630630
if (PhFormatToBuffer(&format, 1, node->CpuUsageText, sizeof(node->CpuUsageText), &returnLength))
631631
{
632632
getCellText->Text.Buffer = node->CpuUsageText;
633-
getCellText->Text.Length = returnLength - sizeof(WCHAR); // minus null terminator
633+
getCellText->Text.Length = returnLength - sizeof(UNICODE_NULL);
634634
}
635635
}
636636
else if (cpuUsage != 0 && PhCsShowCpuBelow001)
@@ -644,7 +644,7 @@ BOOLEAN NTAPI PhpThreadTreeNewCallback(
644644
if (PhFormatToBuffer(format, 2, node->CpuUsageText, sizeof(node->CpuUsageText), &returnLength))
645645
{
646646
getCellText->Text.Buffer = node->CpuUsageText;
647-
getCellText->Text.Length = returnLength - sizeof(WCHAR);
647+
getCellText->Text.Length = returnLength - sizeof(UNICODE_NULL);
648648
}
649649
}
650650
}
@@ -894,7 +894,7 @@ BOOLEAN NTAPI PhpThreadTreeNewCallback(
894894
if (PhFormatToBuffer(&format, 1, node->ThreadIdHexText, sizeof(node->ThreadIdHexText), &returnLength))
895895
{
896896
getCellText->Text.Buffer = node->ThreadIdHexText;
897-
getCellText->Text.Length = returnLength - sizeof(WCHAR); // minus null terminator
897+
getCellText->Text.Length = returnLength - sizeof(UNICODE_NULL);
898898
}
899899
}
900900
break;

phlib/include/phbasesup.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -742,8 +742,8 @@ typedef struct _PH_RELATIVE_BYTESREF
742742
ULONG Offset;
743743
} PH_RELATIVE_BYTESREF, *PPH_RELATIVE_BYTESREF, PH_RELATIVE_STRINGREF, *PPH_RELATIVE_STRINGREF;
744744

745-
#define PH_STRINGREF_INIT(String) { sizeof(String) - sizeof(WCHAR), (String) }
746-
#define PH_BYTESREF_INIT(String) { sizeof(String) - sizeof(CHAR), (String) }
745+
#define PH_STRINGREF_INIT(String) { sizeof(String) - sizeof(UNICODE_NULL), (String) }
746+
#define PH_BYTESREF_INIT(String) { sizeof(String) - sizeof(ANSI_NULL), (String) }
747747

748748
FORCEINLINE
749749
VOID

phlib/include/phnative.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1285,7 +1285,7 @@ PhCreatePipeEx(
12851285
_Out_ PHANDLE PipeReadHandle,
12861286
_Out_ PHANDLE PipeWriteHandle,
12871287
_In_ BOOLEAN InheritHandles,
1288-
_In_ PSECURITY_DESCRIPTOR SecurityDescriptor
1288+
_In_opt_ PSECURITY_DESCRIPTOR SecurityDescriptor
12891289
);
12901290

12911291
PHLIBAPI

phlib/include/phutil.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ PHLIBAPI
212212
INT
213213
NTAPI
214214
PhShowMessage(
215-
_In_ HWND hWnd,
215+
_In_opt_ HWND hWnd,
216216
_In_ ULONG Type,
217217
_In_ PWSTR Format,
218218
...
@@ -226,7 +226,7 @@ PHLIBAPI
226226
INT
227227
NTAPI
228228
PhShowMessage2(
229-
_In_ HWND hWnd,
229+
_In_opt_ HWND hWnd,
230230
_In_ ULONG Buttons,
231231
_In_opt_ PWSTR Icon,
232232
_In_opt_ PWSTR Title,

phlib/include/symprvp.h

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -62,12 +62,12 @@ typedef BOOL (WINAPI *_SymGetLineFromAddrW64)(
6262
typedef ULONG64 (WINAPI *_SymLoadModuleExW)(
6363
_In_ HANDLE ProcessHandle,
6464
_In_opt_ HANDLE FileHandle,
65-
_In_ PCWSTR ImageName,
66-
_In_ PCWSTR ModuleName,
65+
_In_opt_ PCWSTR ImageName,
66+
_In_opt_ PCWSTR ModuleName,
6767
_In_ ULONG64 BaseOfDll,
6868
_In_ ULONG DllSize,
69-
_In_ PMODLOAD_DATA Data,
70-
_In_ ULONG Flags
69+
_In_opt_ PMODLOAD_DATA Data,
70+
_In_opt_ ULONG Flags
7171
);
7272

7373
typedef ULONG (WINAPI *_SymGetOptions)();
@@ -125,9 +125,9 @@ typedef BOOL (WINAPI *_MiniDumpWriteDump)(
125125
_In_ ULONG ProcessId,
126126
_In_ HANDLE FileHandle,
127127
_In_ MINIDUMP_TYPE DumpType,
128-
_In_ PMINIDUMP_EXCEPTION_INFORMATION ExceptionParam,
129-
_In_ PMINIDUMP_USER_STREAM_INFORMATION UserStreamParam,
130-
_In_ PMINIDUMP_CALLBACK_INFORMATION CallbackParam
128+
_In_opt_ PMINIDUMP_EXCEPTION_INFORMATION ExceptionParam,
129+
_In_opt_ PMINIDUMP_USER_STREAM_INFORMATION UserStreamParam,
130+
_In_opt_ PMINIDUMP_CALLBACK_INFORMATION CallbackParam
131131
);
132132

133133
typedef UINT_PTR (CALLBACK *_SymbolServerGetOptions)(

phlib/lsasup.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -528,11 +528,11 @@ VOID PhInitializeCapabilitySidCache(
528528
PhDereferenceObject(capabilityListFileName);
529529
}
530530

531-
if (PhIsNullOrEmptyString(capabilityListString))
531+
if (!capabilityListString)
532532
return;
533533

534534
PhInitializeArray(CapabilitySidArrayList, sizeof(PH_CAPABILITY_ENTRY), 800);
535-
remainingPart = capabilityListString->sr;
535+
remainingPart = PhGetStringRef(capabilityListString);
536536

537537
while (remainingPart.Length != 0)
538538
{

phlib/native.c

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1123,7 +1123,7 @@ NTSTATUS PhQueryEnvironmentVariable(
11231123
}
11241124
else
11251125
{
1126-
RtlInitUnicodeString(&variableValueUs, UNICODE_NULL);
1126+
RtlInitEmptyUnicodeString(&variableValueUs, NULL, 0);
11271127
}
11281128

11291129
status = RtlQueryEnvironmentVariable_U(
@@ -3550,8 +3550,7 @@ BOOLEAN NTAPI PhpEnumProcessModulesCallback(
35503550
NULL
35513551
)))
35523552
{
3553-
// HACK: Fixup the module load count.
3554-
// Temp fix until PhpModuleQueryWorker can be used for 'Stage2'.
3553+
// Fixup the module load count. (dmex)
35553554
Entry->ObsoleteLoadCount = (USHORT)ldrDagNode.LoadCount;
35563555
}
35573556
}
@@ -3860,7 +3859,7 @@ BOOLEAN NTAPI PhpEnumProcessModules32Callback(
38603859
{
38613860
// Read the base DLL name string and add a null terminator.
38623861

3863-
baseDllNameBuffer = PhAllocate(nativeEntry.BaseDllName.Length + sizeof(WCHAR));
3862+
baseDllNameBuffer = PhAllocate(nativeEntry.BaseDllName.Length + sizeof(UNICODE_NULL));
38643863

38653864
if (NT_SUCCESS(NtReadVirtualMemory(
38663865
ProcessHandle,
@@ -3882,7 +3881,7 @@ BOOLEAN NTAPI PhpEnumProcessModules32Callback(
38823881

38833882
// Read the full DLL name string and add a null terminator.
38843883

3885-
fullDllNameBuffer = PhAllocate(nativeEntry.FullDllName.Length + sizeof(WCHAR));
3884+
fullDllNameBuffer = PhAllocate(nativeEntry.FullDllName.Length + sizeof(UNICODE_NULL));
38863885

38873886
if (NT_SUCCESS(NtReadVirtualMemory(
38883887
ProcessHandle,
@@ -3942,8 +3941,7 @@ BOOLEAN NTAPI PhpEnumProcessModules32Callback(
39423941
NULL
39433942
)))
39443943
{
3945-
// HACK: Fixup the module load count.
3946-
// Temp fix until PhpModuleQueryWorker can be used for 'Stage2'.
3944+
// Fixup the module load count. (dmex)
39473945
nativeEntry.ObsoleteLoadCount = (USHORT)ldrDagNode32.LoadCount;
39483946
}
39493947
}
@@ -5841,10 +5839,10 @@ PPH_STRING PhGetFileName(
58415839
PH_STRINGREF systemRoot;
58425840

58435841
PhGetSystemRoot(&systemRoot);
5844-
newFileName = PhCreateStringEx(NULL, systemRoot.Length + sizeof(WCHAR) + FileName->Length);
5842+
newFileName = PhCreateStringEx(NULL, systemRoot.Length + sizeof(UNICODE_NULL) + FileName->Length);
58455843
memcpy(newFileName->Buffer, systemRoot.Buffer, systemRoot.Length);
58465844
newFileName->Buffer[systemRoot.Length / sizeof(WCHAR)] = OBJ_NAME_PATH_SEPARATOR;
5847-
memcpy(PTR_ADD_OFFSET(newFileName->Buffer, systemRoot.Length + sizeof(WCHAR)), FileName->Buffer, FileName->Length);
5845+
memcpy(PTR_ADD_OFFSET(newFileName->Buffer, systemRoot.Length + sizeof(UNICODE_NULL)), FileName->Buffer, FileName->Length);
58485846
}
58495847
else if (FileName->Length != 0 && FileName->Buffer[0] == OBJ_NAME_PATH_SEPARATOR)
58505848
{
@@ -5862,7 +5860,7 @@ PPH_STRING PhGetFileName(
58625860
// If the file name starts with "\Windows", prepend the system drive.
58635861
if (PhStartsWithString2(newFileName, L"\\Windows", TRUE))
58645862
{
5865-
newFileName = PhCreateStringEx(NULL, FileName->Length + sizeof(WCHAR) * sizeof(WCHAR));
5863+
newFileName = PhCreateStringEx(NULL, FileName->Length + sizeof(UNICODE_NULL) * sizeof(WCHAR));
58665864
newFileName->Buffer[0] = USER_SHARED_DATA->NtSystemRoot[0];
58675865
newFileName->Buffer[1] = ':';
58685866
memcpy(&newFileName->Buffer[2], FileName->Buffer, FileName->Length);
@@ -6801,7 +6799,7 @@ NTSTATUS PhQueryValueKey(
68016799
}
68026800
else
68036801
{
6804-
RtlInitUnicodeString(&valueName, NULL);
6802+
RtlInitEmptyUnicodeString(&valueName, NULL, 0);
68056803
}
68066804

68076805
bufferSize = 0x100;
@@ -7451,7 +7449,7 @@ NTSTATUS PhCreatePipeEx(
74517449
_Out_ PHANDLE PipeReadHandle,
74527450
_Out_ PHANDLE PipeWriteHandle,
74537451
_In_ BOOLEAN InheritHandles,
7454-
_In_ PSECURITY_DESCRIPTOR SecurityDescriptor
7452+
_In_opt_ PSECURITY_DESCRIPTOR SecurityDescriptor
74557453
)
74567454
{
74577455
NTSTATUS status;

phlib/symprv.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -540,7 +540,7 @@ PPH_STRING PhGetSymbolFromAddress(
540540
ULONG64 displacement;
541541
PPH_STRING modFileName = NULL;
542542
PPH_STRING modBaseName = NULL;
543-
ULONG64 modBase;
543+
ULONG64 modBase = 0;
544544
PPH_STRING symbolName = NULL;
545545

546546
if (Address == 0)

phlib/util.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ PPH_STRING PhGetUserDefaultLocaleName(
255255

256256
if (NT_SUCCESS(RtlLcidToLocaleName(PhGetUserDefaultLCID(), &localeNameUs, 0, FALSE)))
257257
{
258-
return PhCreateString(localeName);
258+
return PhCreateStringFromUnicodeString(&localeNameUs);
259259
}
260260

261261
return NULL;
@@ -411,7 +411,7 @@ PPH_STRING PhGetWin32Message(
411411
* \return The user's response.
412412
*/
413413
INT PhShowMessage(
414-
_In_ HWND hWnd,
414+
_In_opt_ HWND hWnd,
415415
_In_ ULONG Type,
416416
_In_ PWSTR Format,
417417
...
@@ -435,7 +435,7 @@ INT PhShowMessage(
435435
}
436436

437437
INT PhShowMessage2(
438-
_In_ HWND hWnd,
438+
_In_opt_ HWND hWnd,
439439
_In_ ULONG Buttons,
440440
_In_opt_ PWSTR Icon,
441441
_In_opt_ PWSTR Title,

0 commit comments

Comments
 (0)