fixed static analysis errors reported by Visual Studio 2015

This commit is contained in:
Gregory Pakosz 2016-01-26 17:30:29 +01:00
parent 7d47fc87f1
commit 8ad3792af0
2 changed files with 19 additions and 5 deletions

View File

@ -76,6 +76,8 @@ int main(int argc, char** argv)
if (length > 0)
{
path = (char*)malloc(length + 1);
if (!path)
abort();
wai_getExecutablePath(path, length, &dirname_length);
path[length] = '\0';
@ -90,6 +92,8 @@ int main(int argc, char** argv)
if (length > 0)
{
path = (char*)malloc(length + 1);
if (!path)
abort();
wai_getModulePath(path, length, &dirname_length);
path[length] = '\0';

View File

@ -58,7 +58,7 @@ extern "C" {
static int WAI_PREFIX(getModulePath_)(HMODULE module, char* out, int capacity, int* dirname_length)
{
wchar_t buffer1[MAX_PATH];
wchar_t buffer1[1];
wchar_t buffer2[MAX_PATH];
wchar_t* path = NULL;
int length = -1;
@ -77,15 +77,25 @@ static int WAI_PREFIX(getModulePath_)(HMODULE module, char* out, int capacity, i
DWORD size_ = size;
do
{
wchar_t* path_;
path_ = (wchar_t*)WAI_REALLOC(path, sizeof(wchar_t) * size_ * 2);
if (!path_)
break;
size_ *= 2;
path = (wchar_t*)WAI_REALLOC(path, sizeof(wchar_t) * size_);
size = GetModuleFileNameW(NULL, path, size_);
} while (size == size_);
path = path_;
size = GetModuleFileNameW(module, path, size_);
}
while (size == size_);
if (size == size_)
break;
}
else
path = buffer1;
_wfullpath(buffer2, path, MAX_PATH);
if (!_wfullpath(buffer2, path, MAX_PATH))
break;
length_ = WideCharToMultiByte(CP_UTF8, 0, buffer2, -1, out, capacity, NULL, NULL);
if (length_ == 0)