mirror of
https://github.com/fastfetch-cli/fastfetch.git
synced 2026-10-30 00:37:23 +01:00
Windows: fix possible crashes
This commit is contained in:
@@ -26,7 +26,7 @@ const char* ffDetectBatteryImpl(FFinstance* instance, FFlist* results)
|
||||
ffStrbufInit(&battery->modelName);
|
||||
ffGetWmiObjString(pclsObj, L"Name", &battery->modelName);
|
||||
|
||||
uint64_t chemistry;
|
||||
uint64_t chemistry = 0;
|
||||
ffGetWmiObjUnsigned(pclsObj, L"Chemistry", &chemistry);
|
||||
switch(chemistry)
|
||||
{
|
||||
@@ -38,6 +38,7 @@ const char* ffDetectBatteryImpl(FFinstance* instance, FFlist* results)
|
||||
case 6: ffStrbufInitS(&battery->technology, "Lithium-ion"); break;
|
||||
case 7: ffStrbufInitS(&battery->technology, "Zinc air"); break;
|
||||
case 8: ffStrbufInitS(&battery->technology, "Lithium Polymer"); break;
|
||||
default: ffStrbufInit(&battery->technology); break;
|
||||
}
|
||||
|
||||
uint64_t capacity;
|
||||
@@ -59,12 +60,13 @@ const char* ffDetectBatteryImpl(FFinstance* instance, FFlist* results)
|
||||
case 9: ffStrbufInitS(&battery->status, "Charging and Critical"); break;
|
||||
case 10: ffStrbufInitS(&battery->status, "Undefined"); break;
|
||||
case 11: ffStrbufInitS(&battery->status, "Partially Charged"); break;
|
||||
default: ffStrbufInit(&battery->status); break;
|
||||
}
|
||||
|
||||
battery->temperature = FF_BATTERY_TEMP_UNSET;
|
||||
}
|
||||
|
||||
pclsObj->Release();
|
||||
if(pclsObj) pclsObj->Release();
|
||||
pEnumerator->Release();
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
@@ -19,9 +19,7 @@ void ffDetectFontImpl(const FFinstance* instance, FFFontResult* result)
|
||||
IWbemClassObject *pclsObj = NULL;
|
||||
ULONG uReturn = 0;
|
||||
|
||||
pEnumerator->Next(WBEM_INFINITE, 1, &pclsObj, &uReturn);
|
||||
|
||||
if(uReturn == 0)
|
||||
if(FAILED(pEnumerator->Next(WBEM_INFINITE, 1, &pclsObj, &uReturn)) || uReturn == 0)
|
||||
{
|
||||
ffStrbufInitS(&result->error, "No WMI result returned");
|
||||
pEnumerator->Release();
|
||||
|
||||
@@ -38,7 +38,7 @@ const char* ffDetectGPUImpl(FFlist* gpus, const FFinstance* instance)
|
||||
gpu->coreCount = FF_GPU_CORE_COUNT_UNSET;
|
||||
}
|
||||
|
||||
pclsObj->Release();
|
||||
if(pclsObj) pclsObj->Release();
|
||||
pEnumerator->Release();
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
@@ -23,9 +23,7 @@ extern "C" void ffDetectHostImpl(FFHostResult* host)
|
||||
IWbemClassObject *pclsObj = NULL;
|
||||
ULONG uReturn = 0;
|
||||
|
||||
pEnumerator->Next(WBEM_INFINITE, 1, &pclsObj, &uReturn);
|
||||
|
||||
if(uReturn == 0)
|
||||
if(FAILED(pEnumerator->Next(WBEM_INFINITE, 1, &pclsObj, &uReturn)) || uReturn == 0)
|
||||
{
|
||||
ffStrbufInitS(&host->error, "No Wmi result returned");
|
||||
pEnumerator->Release();
|
||||
|
||||
@@ -10,11 +10,18 @@ static void addNewIp(FFlist* list, const wchar_t* name, const char* addr, bool i
|
||||
FFLocalIpResult* ip = (FFLocalIpResult*) ffListAdd(list);
|
||||
|
||||
int len = (int)wcslen(name);
|
||||
int size_needed = WideCharToMultiByte(CP_UTF8, 0, name, len, NULL, 0, NULL, NULL);
|
||||
ffStrbufInitA(&ip->name, (uint32_t)size_needed + 1);
|
||||
WideCharToMultiByte(CP_UTF8, 0, name, len, ip->name.chars, size_needed, NULL, NULL);
|
||||
ip->name.length = (uint32_t)size_needed;
|
||||
ip->name.chars[size_needed] = '\0';
|
||||
if(len > 0)
|
||||
{
|
||||
int size_needed = WideCharToMultiByte(CP_UTF8, 0, name, len, NULL, 0, NULL, NULL);
|
||||
ffStrbufInitA(&ip->name, (uint32_t)size_needed + 1);
|
||||
WideCharToMultiByte(CP_UTF8, 0, name, len, ip->name.chars, size_needed, NULL, NULL);
|
||||
ip->name.length = (uint32_t)size_needed;
|
||||
ip->name.chars[size_needed] = '\0';
|
||||
}
|
||||
else
|
||||
{
|
||||
ffStrbufInitS(&ip->name, "*");
|
||||
}
|
||||
|
||||
ffStrbufInitS(&ip->addr, addr);
|
||||
ip->ipv6 = ipv6;
|
||||
|
||||
@@ -37,6 +37,6 @@ next:
|
||||
if(users->length == 0)
|
||||
ffStrbufAppendS(error, "Unable to detect users");
|
||||
|
||||
pclsObj->Release();
|
||||
if(pclsObj) pclsObj->Release();
|
||||
pEnumerator->Release();
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
#include <synchapi.h>
|
||||
#include <wchar.h>
|
||||
#include <math.h>
|
||||
|
||||
//https://learn.microsoft.com/en-us/windows/win32/wmisdk/example--getting-wmi-data-from-the-local-computer
|
||||
//https://learn.microsoft.com/en-us/windows/win32/cimwin32prov/computer-system-hardware-classes
|
||||
@@ -232,7 +233,7 @@ bool ffGetWmiObjSigned(IWbemClassObject* obj, const wchar_t* key, int64_t* integ
|
||||
case VT_UI4: *integer = (int64_t)vtProp.uintVal; break;
|
||||
case VT_UI8: *integer = (int64_t)vtProp.ullVal; break;
|
||||
case VT_BOOL: *integer = vtProp.boolVal != VARIANT_FALSE; break;
|
||||
default: result = false;
|
||||
default: *integer = 0; result = false;
|
||||
}
|
||||
}
|
||||
VariantClear(&vtProp);
|
||||
@@ -266,7 +267,7 @@ bool ffGetWmiObjUnsigned(IWbemClassObject* obj, const wchar_t* key, uint64_t* in
|
||||
case VT_UI4: *integer = vtProp.uintVal; break;
|
||||
case VT_UI8: *integer = vtProp.ullVal; break;
|
||||
case VT_BOOL: *integer = vtProp.boolVal != VARIANT_FALSE; break;
|
||||
default: result = false;
|
||||
default: *integer = 0; result = false;
|
||||
}
|
||||
}
|
||||
VariantClear(&vtProp);
|
||||
@@ -302,7 +303,7 @@ bool ffGetWmiObjReal(IWbemClassObject* obj, const wchar_t* key, double* real)
|
||||
case VT_R4: *real = vtProp.fltVal; break;
|
||||
case VT_R8: *real = vtProp.dblVal; break;
|
||||
case VT_BOOL: *real = vtProp.boolVal != VARIANT_FALSE; break;
|
||||
default: result = false;
|
||||
default: *real = NAN; result = false;
|
||||
}
|
||||
}
|
||||
VariantClear(&vtProp);
|
||||
|
||||
Reference in New Issue
Block a user