This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Add error handling to win32_ansipath
authorJan Dubois <jand@activestate.com>
Thu, 4 Jan 2007 12:20:21 +0000 (04:20 -0800)
committerRafael Garcia-Suarez <rgarciasuarez@gmail.com>
Fri, 5 Jan 2007 07:47:08 +0000 (07:47 +0000)
Message-ID: <f2oqp2dbdglim8bda4q1kajt9k3cvpqqga@4ax.com>

p4raw-id: //depot/perl@29689

win32/win32.c

index 0162127..4a90d0a 100644 (file)
@@ -1616,11 +1616,14 @@ win32_longpath(char *path)
 static void
 out_of_memory()
 {
-    dTHX;
-    /* Can't use PerlIO to write as it allocates memory */
-    PerlLIO_write(PerlIO_fileno(Perl_error_log),
-                  PL_no_mem, strlen(PL_no_mem));
-    my_exit(1);
+    if (PL_curinterp) {
+        dTHX;
+        /* Can't use PerlIO to write as it allocates memory */
+        PerlLIO_write(PerlIO_fileno(Perl_error_log),
+                      PL_no_mem, strlen(PL_no_mem));
+        my_exit(1);
+    }
+    exit(1);
 }
 
 /* The win32_ansipath() function takes a Unicode filename and converts it
@@ -1655,21 +1658,22 @@ win32_ansipath(const WCHAR *widename)
     WideCharToMultiByte(CP_ACP, WC_NO_BEST_FIT_CHARS, widename, widelen,
                         name, len, NULL, &use_default);
     if (use_default) {
-        WCHAR *shortname;
         DWORD shortlen = GetShortPathNameW(widename, NULL, 0);
-        shortname = win32_malloc(shortlen*sizeof(WCHAR));
-        if (!shortname)
-            out_of_memory();
-        shortlen = GetShortPathNameW(widename, shortname, shortlen)+1;
-
-        len = WideCharToMultiByte(CP_ACP, WC_NO_BEST_FIT_CHARS, shortname, shortlen,
-                                  NULL, 0, NULL, NULL);
-        name = win32_realloc(name, len);
-        if (!name)
-            out_of_memory();
-        WideCharToMultiByte(CP_ACP, WC_NO_BEST_FIT_CHARS, shortname, shortlen,
-                            name, len, NULL, NULL);
-        win32_free(shortname);
+        if (shortlen) {
+            WCHAR *shortname = win32_malloc(shortlen*sizeof(WCHAR));
+            if (!shortname)
+                out_of_memory();
+            shortlen = GetShortPathNameW(widename, shortname, shortlen)+1;
+
+            len = WideCharToMultiByte(CP_ACP, WC_NO_BEST_FIT_CHARS, shortname, shortlen,
+                                      NULL, 0, NULL, NULL);
+            name = win32_realloc(name, len);
+            if (!name)
+                out_of_memory();
+            WideCharToMultiByte(CP_ACP, WC_NO_BEST_FIT_CHARS, shortname, shortlen,
+                                name, len, NULL, NULL);
+            win32_free(shortname);
+        }
     }
     return name;
 }