texlive[54925] Build/source/texk/kpathsea: improve long path support

commits+kakuto at tug.org commits+kakuto at tug.org
Tue Apr 28 14:05:19 CEST 2020


Revision: 54925
          http://tug.org/svn/texlive?view=revision&revision=54925
Author:   kakuto
Date:     2020-04-28 14:05:18 +0200 (Tue, 28 Apr 2020)
Log Message:
-----------
improve long path support (windows only)

Modified Paths:
--------------
    trunk/Build/source/texk/kpathsea/knj.c
    trunk/Build/source/texk/kpathsea/readable.c

Modified: trunk/Build/source/texk/kpathsea/knj.c
===================================================================
--- trunk/Build/source/texk/kpathsea/knj.c	2020-04-28 10:17:42 UTC (rev 54924)
+++ trunk/Build/source/texk/kpathsea/knj.c	2020-04-28 12:05:18 UTC (rev 54925)
@@ -118,19 +118,23 @@
     int i;
     unsigned char *fnn;
     unsigned char *p;
+    size_t len;
+
     assert(filename && mode);
+    len = strlen(filename);
 /*
   Support very long input path name, longer than _MAX_PATH for
   Windows, if it really exists and input name is given in
   full-absolute path in a command line.
 */
-    fnn = xmalloc(strlen(filename) + 10);
-    if ((filename[0] == '/' && filename[1] == '/') ||
-        (filename[0] == '\\' && filename[1] == '\\' && filename[2] != '?')) {
+    fnn = xmalloc(len + 10);
+    if (len > 2 && ((filename[0] == '/' && filename[1] == '/') ||
+        (filename[0] == '\\' && filename[1] == '\\' &&
+         filename[2] != '?'))) {
        filename += 2;
        strcpy (fnn, "\\\\?\\UNC\\");
        strcat (fnn, filename);
-    } else if (filename[1] == ':') {
+    } else if (len > 2 && filename[1] == ':') {
        strcpy (fnn, "\\\\?\\");
        strcat (fnn, filename);
     } else {
@@ -174,19 +178,23 @@
     int i;
     unsigned char *fnn;
     unsigned char *p;
+    size_t len;
+
     assert(filename && mode);
+    len = strlen(filename);
 /*
   Support very long input path name, longer than _MAX_PATH for
   Windows, if it really exists and input name is given in
   full-absolute path in a command line.
 */
-    fnn = xmalloc(strlen(filename) + 10);
-    if ((filename[0] == '/' && filename[1] == '/') ||
-        (filename[0] == '\\' && filename[1] == '\\' && filename[2] != '?')) {
+    fnn = xmalloc(len + 10);
+    if (len > 2 && ((filename[0] == '/' && filename[1] == '/') ||
+        (filename[0] == '\\' && filename[1] == '\\' &&
+         filename[2] != '?'))) {
        filename += 2;
        strcpy (fnn, "\\\\?\\UNC\\");
        strcat (fnn, filename);
-    } else if (filename[1] == ':') {
+    } else if (len > 2 && filename[1] == ':') {
        strcpy (fnn, "\\\\?\\");
        strcat (fnn, filename);
     } else {

Modified: trunk/Build/source/texk/kpathsea/readable.c
===================================================================
--- trunk/Build/source/texk/kpathsea/readable.c	2020-04-28 10:17:42 UTC (rev 54924)
+++ trunk/Build/source/texk/kpathsea/readable.c	2020-04-28 12:05:18 UTC (rev 54925)
@@ -43,19 +43,20 @@
   wchar_t *fnw;
   unsigned char *fnn;
   unsigned char *p;
+  size_t len = strlen(fn);
 
-  fnn = xmalloc(strlen(fn) + 10);
+  fnn = xmalloc(len + 10);
 /*
   Support very long input path name, longer than _MAX_PATH for
   Windows, if it really exists and input name is given in
   full-absolute path in a command line.
 */
-  if ((fn[0] == '/' && fn[1] == '/') ||
-      (fn[0] == '\\' && fn[1] == '\\' && fn[2] != '?')) {
+  if (len > 2 && ((fn[0] == '/' && fn[1] == '/') ||
+      (fn[0] == '\\' && fn[1] == '\\' && fn[2] != '?'))) {
     fn += 2;
     strcpy (fnn, "\\\\?\\UNC\\");
     strcat (fnn, fn);
-  } else if (fn[1] == ':') {
+  } else if (len > 2 && fn[1] == ':') {
     strcpy (fnn, "\\\\?\\");
     strcat (fnn, fn);
   } else {



More information about the tex-live-commits mailing list.