diff --git a/src/Tester.cpp b/src/Tester.cpp index cd8c8c94fa75..aa680165550f 100644 --- a/src/Tester.cpp +++ b/src/Tester.cpp @@ -77,9 +77,8 @@ static void MobiSaveImage(const char* filePathBase, size_t imgNo, ByteSlice img) } const char* ext = GfxFileExtFromData(img); CrashAlwaysIf(!ext); - char* path = str::Format("%s_img_%d%s", filePathBase, (int)imgNo, ext); + TempStr path = str::FormatTemp("%s_img_%d%s", filePathBase, (int)imgNo, ext); file::WriteFile(path, img); - str::Free(path); } static void MobiSaveImages(const char* filePathBase, MobiDoc* mb) { diff --git a/src/Uninstaller.cpp b/src/Uninstaller.cpp index d2a316613e5a..5bb3549a0a5c 100644 --- a/src/Uninstaller.cpp +++ b/src/Uninstaller.cpp @@ -170,7 +170,7 @@ static bool UninstallerOnWmCommand(WPARAM wp) { #define kInstallerWindowClassName L"SUMATRA_PDF_INSTALLER_FRAME" static void CreateUninstallerWindow() { - AutoFreeWstr title = str::Format(_TR("SumatraPDF %s Uninstaller"), CURR_VERSION_STR); + TempStr title = str::FormatTemp(_TRA("SumatraPDF %s Uninstaller"), CURR_VERSION_STRA); int x = CW_USEDEFAULT; int y = CW_USEDEFAULT; int dx = GetInstallerWinDx(); @@ -178,7 +178,7 @@ static void CreateUninstallerWindow() { HMODULE h = GetModuleHandleW(nullptr); DWORD dwStyle = WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU | WS_CLIPCHILDREN; auto winCls = kInstallerWindowClassName; - gHwndFrame = CreateWindowW(winCls, title.Get(), dwStyle, x, y, dx, dy, nullptr, nullptr, h, nullptr); + gHwndFrame = CreateWindowW(winCls, ToWStrTemp(title), dwStyle, x, y, dx, dy, nullptr, nullptr, h, nullptr); DpiScale(gHwndFrame, dx, dy); HwndResizeClientSize(gHwndFrame, dx, dy); @@ -189,8 +189,8 @@ static void CreateUninstallerWindow() { static void ShowUsage() { // Note: translation services aren't initialized at this point, so English only - char* caption = str::JoinTemp(kAppName, " Uninstaller Usage"); - AutoFreeStr msg = str::Format( + TempStr caption = str::JoinTemp(kAppName, " Uninstaller Usage"); + TempStr msg = str::FormatTemp( "uninstall.exe [/s][/d ]\n\ \n\ /s\tuninstalls %s silently (without user interaction).\n\ @@ -408,7 +408,7 @@ static void InitSelfDelete() { return; } logf("Created self-delete batch script '%s'\n", scriptPath); - AutoFreeStr cmdLine = str::Format("cmd.exe /C \"%s\"", scriptPath); + TempStr cmdLine = str::FormatTemp("cmd.exe /C \"%s\"", scriptPath); DWORD flags = CREATE_NO_WINDOW; LaunchProcess(cmdLine, nullptr, flags); } diff --git a/src/UpdateCheck.cpp b/src/UpdateCheck.cpp index c002bdf2a89d..140b47124e14 100644 --- a/src/UpdateCheck.cpp +++ b/src/UpdateCheck.cpp @@ -479,7 +479,7 @@ void UpdateSelfTo(const char* path) { // had time to exit so that we can overwrite it ::Sleep(gCli->sleepMs); - const char* srcPath = GetExePathTemp(); + TempStr srcPath = GetExePathTemp(); bool ok = file::Copy(path, srcPath, false); // TODO: maybe retry if copy fails under the theory that the file // might be temporarily locked @@ -489,6 +489,6 @@ void UpdateSelfTo(const char* path) { } logf("UpdateSelfTo: copied self to file\n"); - AutoFreeStr args = str::Format(R"(-sleep-ms 500 -delete-file "%s")", srcPath); - CreateProcessHelper(path, args.Get()); + TempStr args = str::FormatTemp(R"(-sleep-ms 500 -delete-file "%s")", srcPath); + CreateProcessHelper(path, args); } diff --git a/src/tools/plugin-test.cpp b/src/tools/plugin-test.cpp index d806ca3a1a08..22b45576c8cf 100644 --- a/src/tools/plugin-test.cpp +++ b/src/tools/plugin-test.cpp @@ -30,9 +30,10 @@ LRESULT CALLBACK PluginParentWndProc(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp) if (WM_CREATE == msg) { // run SumatraPDF.exe with the -plugin command line argument PluginStartData* data = (PluginStartData*)((CREATESTRUCT*)lp)->lpCreateParams; - AutoFreeStr cmdLine(str::Format("-plugin %d \"%s\"", hwnd, data->filePath)); + auto path = data->filePath; + TempStr cmdLine = str::FormatTemp("-plugin %d \"%s\"", hwnd, path); if (data->fileOriginUrl) { - cmdLine.Set(str::Format("-plugin \"%s\" %d \"%s\"", data->fileOriginUrl, hwnd, data->filePath)); + cmdLine = str::FormatTemp("-plugin \"%s\" %d \"%s\"", data->fileOriginUrl, hwnd, path); } ShellExecute(hwnd, L"open", ToWStrTemp(data->sumatraPath), ToWStrTemp(cmdLine), nullptr, SW_SHOW); } else if (WM_SIZE == msg) { diff --git a/src/uia/PageProvider.cpp b/src/uia/PageProvider.cpp index 9aa73978d9dc..ad3053cf9a5f 100644 --- a/src/uia/PageProvider.cpp +++ b/src/uia/PageProvider.cpp @@ -192,7 +192,8 @@ HRESULT STDMETHODCALLTYPE SumatraUIAutomationPageProvider::GetPropertyValue(PROP if (propertyId == UIA_NamePropertyId) { pRetVal->vt = VT_BSTR; - pRetVal->bstrVal = SysAllocString(AutoFreeWstr(str::Format(L"Page %d", pageNum))); + TempStr s = str::FormatTemp("Page %d", pageNum); + pRetVal->bstrVal = SysAllocString(ToWStrTemp(s)); return S_OK; } else if (propertyId == UIA_IsValuePatternAvailablePropertyId) { pRetVal->vt = VT_BOOL; diff --git a/src/utils/FileUtil.cpp b/src/utils/FileUtil.cpp index 9939e94b3bf9..c3ba77893f2d 100644 --- a/src/utils/FileUtil.cpp +++ b/src/utils/FileUtil.cpp @@ -710,10 +710,11 @@ int GetZoneIdentifier(const char* filePath) { } bool SetZoneIdentifier(const char* filePath, int zoneId) { - char* path = str::JoinTemp(filePath, ":Zone.Identifier"); - AutoFreeWstr id(str::Format(L"%d", zoneId)); - WCHAR* pathW = ToWStrTemp(path); - return WritePrivateProfileStringW(L"ZoneTransfer", L"ZoneId", id, pathW); + TempStr path = str::JoinTemp(filePath, ":Zone.Identifier"); + TempStr id = str::FormatTemp("%d", zoneId); + TempWStr idw = ToWStrTemp(id); + TempWStr pathW = ToWStrTemp(path); + return WritePrivateProfileStringW(L"ZoneTransfer", L"ZoneId", idw, pathW); } bool DeleteZoneIdentifier(const char* filePath) {