From d8fcd3d2821a6a451e41398231205e651e267a2a Mon Sep 17 00:00:00 2001 From: Sven Strickroth Date: Tue, 29 Jan 2019 17:34:42 +0100 Subject: [PATCH] Don't use alloca Signed-off-by: Sven Strickroth --- test/UnitTests/libgitTest.cpp | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/test/UnitTests/libgitTest.cpp b/test/UnitTests/libgitTest.cpp index 192d3e0a4..d48bbe810 100644 --- a/test/UnitTests/libgitTest.cpp +++ b/test/UnitTests/libgitTest.cpp @@ -1,6 +1,6 @@ // TortoiseGit - a Windows shell extension for easy version control -// Copyright (C) 2016-2018 - TortoiseGit +// Copyright (C) 2016-2019 - TortoiseGit // This program is free software; you can redistribute it and/or // modify it under the terms of the GNU General Public License @@ -176,11 +176,12 @@ TEST(libgit, RefreshIndex) g_Git.CheckMsysGitDir(); size_t size; _wgetenv_s(&size, nullptr, 0, L"PATH"); - EXPECT_LT(0U, size); - TCHAR* oldEnv = (TCHAR*)alloca(size * sizeof(TCHAR)); + ASSERT_LT(0U, size); + auto oldEnv = std::make_unique(size); ASSERT_TRUE(oldEnv); - _wgetenv_s(&size, oldEnv, size, L"PATH"); + _wgetenv_s(&size, oldEnv.get(), size, L"PATH"); _wputenv_s(L"PATH", g_Git.m_Environment.GetEnv(L"PATH")); + SCOPE_EXIT { _wputenv_s(L"PATH", oldEnv.get()); }; EXPECT_TRUE(CStringUtils::WriteStringToTextFile(g_Git.m_CurrentDir + L"\\somefile.txt", L"some content")); g_Git.RefreshGitIndex(); @@ -249,8 +250,6 @@ TEST(libgit, RefreshIndex) } g_Git.RefreshGitIndex(); - - _wputenv_s(L"PATH", oldEnv); } TEST(libgit, IncludeIf) -- 2.11.4.GIT