Author: mturk
Date: Thu Aug 13 13:14:08 2009
New Revision: 803874

URL: http://svn.apache.org/viewvc?rev=803874&view=rev
Log:
Use costant size for maximum non UCS file name length

Modified:
    
commons/sandbox/runtime/trunk/src/main/native/include/arch/windows/acr_arch.h
    commons/sandbox/runtime/trunk/src/main/native/os/win32/dirent.c
    commons/sandbox/runtime/trunk/src/main/native/os/win32/wutil.c

Modified: 
commons/sandbox/runtime/trunk/src/main/native/include/arch/windows/acr_arch.h
URL: 
http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/include/arch/windows/acr_arch.h?rev=803874&r1=803873&r2=803874&view=diff
==============================================================================
--- 
commons/sandbox/runtime/trunk/src/main/native/include/arch/windows/acr_arch.h 
(original)
+++ 
commons/sandbox/runtime/trunk/src/main/native/include/arch/windows/acr_arch.h 
Thu Aug 13 13:14:08 2009
@@ -349,7 +349,7 @@
  * Utility functions
  */
 wchar_t *res_name_from_filenamew(int, wchar_t *, const wchar_t *);
-int utf8_to_unicode_path(wchar_t *, size_t, const char *, size_t);
+int utf8_to_unicode_path(wchar_t *, size_t, const char *);
 int unicode_to_utf8_path(char *, size_t, const wchar_t *);
 
 

Modified: commons/sandbox/runtime/trunk/src/main/native/os/win32/dirent.c
URL: 
http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/win32/dirent.c?rev=803874&r1=803873&r2=803874&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/os/win32/dirent.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/os/win32/dirent.c Thu Aug 13 
13:14:08 2009
@@ -46,7 +46,7 @@
         ACR_SET_OS_ERROR(ACR_ENOTDIR);
         return NULL;
     }
-    if (utf8_to_unicode_path(wpath, ACR_HBUFF_LEN - 2, path, ACR_HBUFF_LEN - 
2))
+    if (utf8_to_unicode_path(wpath, ACR_HBUFF_LEN - 2, path))
         return NULL;
 
     if ((rc = GetFileAttributesW(wpath)) == INVALID_FILE_ATTRIBUTES)
@@ -175,7 +175,7 @@
          */
         mblen = WideCharToMultiByte(CP_UTF8, 0, wfind.cFileName, -1,
                                     entry->d_name, 1023, NULL, 0);
-        if (!mblen)
+        if (mblen == 0 || mblen > 1023)
             return GetLastError();
         entry->d_ino    = 0;
         entry->d_type   = 0;

Modified: commons/sandbox/runtime/trunk/src/main/native/os/win32/wutil.c
URL: 
http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/win32/wutil.c?rev=803874&r1=803873&r2=803874&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/os/win32/wutil.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/os/win32/wutil.c Thu Aug 13 
13:14:08 2009
@@ -40,6 +40,8 @@
     NULL
 };
 
+#define NON_UNC_PATH_LENGTH 248
+
 wchar_t *res_name_from_filenamew(int type, wchar_t *rname,
                                  const wchar_t *fname)
 {
@@ -57,7 +59,7 @@
 }
 
 int utf8_to_unicode_path(wchar_t* retstr, size_t retlen,
-                         const char* srcstr, size_t unc)
+                         const char* srcstr)
 {
     /* TODO: The computations could preconvert the string to determine
      * the true size of the retstr, but that's a memory over speed
@@ -87,7 +89,7 @@
      * Note that a utf-8 name can never result in more wide chars
      * than the original number of utf-8 narrow chars.
      */
-    if (srcremains > unc) {
+    if (srcremains >  NON_UNC_PATH_LENGTH) {
         if (srcstr[1] == ':' && (srcstr[2] == '/' || srcstr[2] == '\\')) {
             wcscpy (retstr, L"\\\\?\\");
             retlen -= 4;
@@ -96,7 +98,7 @@
         else if ((srcstr[0] == '/' || srcstr[0] == '\\')
               && (srcstr[1] == '/' || srcstr[1] == '\\')
               && (srcstr[2] != '?')) {
-            /* Skip the slashes */
+            /* Skip the slashes and ? */
             srcstr += 2;
             srcremains -= 2;
             wcscpy (retstr, L"\\\\?\\UNC\\");


Reply via email to