From: Jan Dubois Date: Thu, 4 Jan 2007 12:20:21 +0000 (-0800) Subject: Add error handling to win32_ansipath X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=ae6198af6119a45e6060c5903f4eddcd7b0f9ade;p=p5sagit%2Fp5-mst-13.2.git Add error handling to win32_ansipath Message-ID: p4raw-id: //depot/perl@29689 --- 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; }