Skip to content
Permalink
Browse files

Fix GitHub issue #252: Crash when generating patch for multiple files…

… and a file only on one side
  • Loading branch information
sdottaka committed Jan 11, 2020
1 parent 7678fd2 commit 8ef3d8ec1141a769810fe8a3aceaf31a442d59f9
Showing with 11 additions and 3 deletions.
  1. +2 −1 Src/DiffWrapper.cpp
  2. +9 −2 Src/PatchTool.cpp
@@ -1482,7 +1482,8 @@ void CDiffWrapper::WritePatchFile(struct change * script, file_data * inf)
path2 = m_files[1];
path1 = paths::ToUnixPath(path1);
path2 = paths::ToUnixPath(path2);
if (ucr::CheckForInvalidUtf8(inf_patch[0].linbuf[inf_patch[0].linbuf_base], inf_patch[0].buffered_chars))
if ((inf_patch[0].linbuf && ucr::CheckForInvalidUtf8(inf_patch[0].linbuf[inf_patch[0].linbuf_base], inf_patch[0].buffered_chars)) ||
(inf_patch[1].linbuf && ucr::CheckForInvalidUtf8(inf_patch[1].linbuf[inf_patch[1].linbuf_base], inf_patch[1].buffered_chars)))
{
inf_patch[0].name = _strdup(ucr::toThreadCP(path1).c_str());
inf_patch[1].name = _strdup(ucr::toThreadCP(path2).c_str());
@@ -26,6 +26,8 @@
#include "DiffWrapper.h"
#include "PathContext.h"
#include "PatchDlg.h"
#include "TFile.h"
#include "TempFile.h"
#include "paths.h"
#include "Merge.h"

@@ -124,11 +126,16 @@ int CPatchTool::CreatePatch()
m_diffWrapper.WritePatchFileHeader(dlgPatch.m_outputStyle, dlgPatch.m_appendFile);
m_diffWrapper.SetAppendFiles(true);

TempFile emptyFile;
emptyFile.Create();
TFile file(emptyFile.GetPath());
file.setLastModified(Poco::Timestamp::fromEpochTime(0));

for (size_t index = 0; index < fileCount; index++)
{
const PATCHFILES& tFiles = dlgPatch.GetItemAt(index);
String filename1 = tFiles.lfile.length() == 0 ? _T("NUL") : tFiles.lfile;
String filename2 = tFiles.rfile.length() == 0 ? _T("NUL") : tFiles.rfile;
String filename1 = tFiles.lfile.length() == 0 ? emptyFile.GetPath() : tFiles.lfile;
String filename2 = tFiles.rfile.length() == 0 ? emptyFile.GetPath() : tFiles.rfile;

// Set up DiffWrapper
m_diffWrapper.SetPaths(PathContext(filename1, filename2), false);

0 comments on commit 8ef3d8e

Please sign in to comment.
You can’t perform that action at this time.