From ae6198af6119a45e6060c5903f4eddcd7b0f9ade Mon Sep 17 00:00:00 2001 From: Jan Dubois Date: Thu, 4 Jan 2007 04:20:21 -0800 Subject: [PATCH] Add error handling to win32_ansipath Message-ID: p4raw-id: //depot/perl@29689 --- win32/win32.c | 42 +++++++++++++++++++++++------------------- 1 file changed, 23 insertions(+), 19 deletions(-) diff --git a/win32/win32.c b/win32/win32.c index 0162127..4a90d0a 100644 --- a/win32/win32.c +++ b/win32/win32.c @@ -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; } -- 2.7.4