From 541ec1c9feb26a3ed1eb38dc07428cb2b7c3d539 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Branimir=20Karad=C5=BEi=C4=87?= Date: Wed, 4 Jan 2017 20:09:53 -0800 Subject: [PATCH] Fixed getTempPath. --- include/bx/os.h | 19 ++++++++++++------- tests/misc_test.cpp | 2 +- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/include/bx/os.h b/include/bx/os.h index ddc3781..f58bb1f 100644 --- a/include/bx/os.h +++ b/include/bx/os.h @@ -237,14 +237,16 @@ namespace bx #else const char* ptr = ::getenv(_name); uint32_t len = 0; + bool result = false; if (NULL != ptr) { len = (uint32_t)strlen(ptr); - } - bool result = len != 0 && len < *_inOutSize; - if (len < *_inOutSize) - { - strcpy(_out, ptr); + + result = len != 0 && len < *_inOutSize; + if (len < *_inOutSize) + { + strcpy(_out, ptr); + } } *_inOutSize = len; @@ -324,11 +326,14 @@ namespace bx NULL }; - for (const char** tmp = s_tmp; tmp != NULL; ++tmp) + for (const char** tmp = s_tmp; *tmp != NULL; ++tmp) { uint32_t len = *_inOutSize; + *_out = '\0'; bool result = getenv(*tmp, _out, &len); - if (len != 0 + + if (result + && len != 0 && len < *_inOutSize) { *_inOutSize = len; diff --git a/tests/misc_test.cpp b/tests/misc_test.cpp index 88f5b34..89d60b1 100644 --- a/tests/misc_test.cpp +++ b/tests/misc_test.cpp @@ -6,7 +6,7 @@ TEST(getProcessMemoryUsed) CHECK(0 != bx::getProcessMemoryUsed() ); // DBG("bx::getProcessMemoryUsed %d", bx::getProcessMemoryUsed() ); - char tmpDir[PATH_MAX]; + char tmpDir[512]; uint32_t len = BX_COUNTOF(tmpDir); CHECK(bx::getTempPath(tmpDir, &len) ); }