I am working in the kernel space of a project (building in ARM64), and am unable to disable specific warnings for my project. The warning is being treated as an error and will not allow me to compile my project, so you can imagine it is very annoying.
The warning is Error code C4244: '=' conversion from 'ULONG_PTR' to 'ULONG', possible loss of data. I have tried using the #pragma disable warning 4244 however that does not work, I have turned off the "treat warnings as errors" setting in my project, I have "turned off all warnings" in the warnings level project setting.
I seem to have tried everything under the sun and yet I still cannot compile, any solutions? I will post the code throwing the error below so someone might be able to fix, however turning the warning off is just as good :)
ULONG_PTR memory::get_process_id_by_name(PEPROCESS start_process, const char* process_name)
{
PLIST_ENTRY active_process_links;
PEPROCESS current_process = start_process;
do
{
PKPROCESS kproc = (PKPROCESS)current_process;
PDISPATCHER_HEADER header = (PDISPATCHER_HEADER)kproc;
LPSTR current_process_name = (LPSTR)((PUCHAR)current_process + IMAGE_FILE_NAME);
if (header->SignalState == 0 && strcmp(current_process_name, process_name) == 0)
{
return (ULONG_PTR)PsGetProcessId(current_process); //warning occurs here
}
active_process_links = (PLIST_ENTRY)((PUCHAR)current_process + ACTIVE_PROCESS_LINKS_FLINK);
current_process = (PEPROCESS)(active_process_links->Flink);
current_process = (PEPROCESS)((PUCHAR)current_process - ACTIVE_PROCESS_LINKS_FLINK);
} while (start_process != current_process);
return 0;
}
Based on the comments in your last question, the warning should appear at the location where the get_process_id_by_name
function is called, not inside the get_process_id_by_name
function. Because now there is no conversion of ULONG_PTR
to ULONG
inside the function.
This is the documentation for #pragma warning
.
And here is the fixed code:
#pragma warning(push)
#pragma warning(disable: 4305)
#pragma warning(disable: 4309)
void YourFunction()
{
/* ... */
if (ioctl == NF_GET_PROCESS_ID)
{
PNF_PROCESS_ID_REQUEST process_id_request = (PNF_PROCESS_ID_REQUEST)irp->AssociatedIrp.SystemBuffer;
process_id_request->process_id = memory::get_process_id_by_name(IoGetCurrentProcess(), process_id_request->process_name);
if (process_id_request->process_id) {
status = STATUS_SUCCESS;
}
bytes_io = sizeof(NF_PROCESS_ID_REQUEST);
DbgPrintEx(0, 0, " NF_GET_PROCESS_ID\n");
}
/* ... */
}
#pragma warning(pop)