OSDN Git Service

Fix GitHub issue #252: Crash when generating patch for multiple files and a file...
authorTakashi Sawanaka <sdottaka@users.sourceforge.net>
Sun, 19 Jan 2020 16:07:00 +0000 (01:07 +0900)
committerTakashi Sawanaka <sdottaka@users.sourceforge.net>
Sun, 19 Jan 2020 16:07:00 +0000 (01:07 +0900)
Src/DiffWrapper.cpp
Src/PatchTool.cpp
Src/diffutils/src/io.c
Src/diffutils/src/mystat.cpp

index d21ceea..47c3c84 100644 (file)
@@ -968,10 +968,10 @@ String CDiffWrapper::FormatSwitchString() const
                switches = _T(" ");
                break;
        case DIFF_OUTPUT_CONTEXT:
-               switches = _T(" C");
+               switches = (m_options.m_contextLines > 0) ? _T(" -C ") : _T(" -c");
                break;
        case DIFF_OUTPUT_UNIFIED:
-               switches = _T(" U");
+               switches = (m_options.m_contextLines > 0) ? _T(" -U ") : _T(" -u");
                break;
 #if 0
        case DIFF_OUTPUT_ED:
@@ -992,7 +992,8 @@ String CDiffWrapper::FormatSwitchString() const
 #endif
        }
 
-       if (m_options.m_contextLines > 0)
+       if ((m_options.m_outputStyle == DIFF_OUTPUT_CONTEXT || m_options.m_outputStyle == DIFF_OUTPUT_UNIFIED) &&
+               m_options.m_contextLines > 0)
        {
                TCHAR tmpNum[5] = {0};
                _itot_s(m_options.m_contextLines, tmpNum, 10);
@@ -1000,16 +1001,16 @@ String CDiffWrapper::FormatSwitchString() const
        }
 
        if (ignore_all_space_flag > 0)
-               switches += _T("w");
+               switches += _T(" -w");
 
        if (ignore_blank_lines_flag > 0)
-               switches += _T("B");
+               switches += _T(" -B");
 
        if (ignore_case_flag > 0)
-               switches += _T("i");
+               switches += _T(" -i");
 
        if (ignore_space_change_flag > 0)
-               switches += _T("b");
+               switches += _T(" -b");
 
        return switches;
 }
@@ -1534,13 +1535,13 @@ void CDiffWrapper::WritePatchFile(struct change * script, file_data * inf)
 
        if (strcmp(inf[0].name, "NUL") == 0)
        {
-               free((void *)inf[0].name);
-               inf[0].name = _strdup("/dev/null");
+               free((void *)inf_patch[0].name);
+               inf_patch[0].name = _strdup("/dev/null");
        }
        if (strcmp(inf[1].name, "NUL") == 0)
        {
-               free((void *)inf[1].name);
-               inf[1].name = _strdup("/dev/null");
+               free((void *)inf_patch[1].name);
+               inf_patch[1].name = _strdup("/dev/null");
        }
 
        // Output patchfile
index b372ae8..d4cb58c 100644 (file)
@@ -26,8 +26,6 @@
 #include "DiffWrapper.h"
 #include "PathContext.h"
 #include "PatchDlg.h"
-#include "TFile.h"
-#include "TempFile.h"
 #include "paths.h"
 #include "Merge.h"
 
@@ -126,16 +124,11 @@ 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 ? emptyFile.GetPath() : tFiles.lfile;
-                       String filename2 = tFiles.rfile.length() == 0 ? emptyFile.GetPath() : tFiles.rfile;
+                       String filename1 = tFiles.lfile.length() == 0 ? _T("NUL") : tFiles.lfile;
+                       String filename2 = tFiles.rfile.length() == 0 ? _T("NUL") : tFiles.rfile;
                        
                        // Set up DiffWrapper
                        m_diffWrapper.SetPaths(PathContext(filename1, filename2), false);
index 75a9560..c91805f 100644 (file)
@@ -1012,14 +1012,15 @@ read_files (struct file_data filevec[], int pretend_binary, int *bin_file)
         appears_binary |= sip (&filevec[1], skip_test | appears_binary);
     }
        
-       // Are both files Open and Regular (no Pipes, Directories, Devices (e.g. NUL))
+       // Are both files Open and Regular (no Pipes, Directories, Devices (except NUL))
        if (filevec[0].desc < 0 || filevec[1].desc < 0 ||
-               !(S_ISREG (filevec[0].stat.st_mode)) || !(S_ISREG (filevec[1].stat.st_mode))   )
-       {
-               assert(!S_ISCHR(filevec[0].stat.st_mode) || strcmp(filevec[0].name, "NUL")==0);
-               assert(!S_ISCHR(filevec[1].stat.st_mode) || strcmp(filevec[1].name, "NUL")==0);
+        (!(S_ISREG (filevec[0].stat.st_mode)) && strcmp(filevec[0].name, "NUL") != 0) ||
+               (!(S_ISREG (filevec[1].stat.st_mode)) && strcmp(filevec[1].name, "NUL") != 0))
+      {
+               assert(!S_ISCHR(filevec[0].stat.st_mode));
+               assert(!S_ISCHR(filevec[1].stat.st_mode));
                return appears_binary;
-       }
+      }
 
   if (appears_binary)
        {
index 15a4c66..3d65098 100644 (file)
@@ -7,7 +7,10 @@
 \r
 inline time_t filetime_to_time_t(const FILETIME& ft)\r
 {\r
-       return ((static_cast<time_t>(ft.dwHighDateTime) << 32) + ft.dwLowDateTime) / 10000000ULL - 11644473600ULL;\r
+       if (ft.dwHighDateTime == 0 && ft.dwLowDateTime == 0)\r
+               return 0;\r
+       else\r
+               return ((static_cast<time_t>(ft.dwHighDateTime) << 32) + ft.dwLowDateTime) / 10000000ULL - 11644473600ULL;\r
 }\r
 \r
 template<typename FileInfo>\r