From: Steve Hay Date: Wed, 27 Jun 2007 17:08:01 +0000 (+0000) Subject: Fix POSIX::setlocale(): the CRT function returns a pointer to a X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=1ba01ae30179f2a8998a11d70df713a205922f5f;p=p5sagit%2Fp5-mst-13.2.git Fix POSIX::setlocale(): the CRT function returns a pointer to a buffer that may be overwritten by subsequent calls to the CRT function, so we must make a safe copy of that buffer for our own use. This fixes lib/locale.t on Win32 with the Borland compiler, but presumably could affect other compilers too. p4raw-id: //depot/perl@31482 --- diff --git a/ext/POSIX/POSIX.xs b/ext/POSIX/POSIX.xs index 388a260..9ddfd3a 100644 --- a/ext/POSIX/POSIX.xs +++ b/ext/POSIX/POSIX.xs @@ -1108,9 +1108,14 @@ char * setlocale(category, locale = 0) int category char * locale + PREINIT: + char * retval; CODE: - RETVAL = setlocale(category, locale); - if (RETVAL) { + retval = setlocale(category, locale); + if (retval) { + /* Save retval since subsequent setlocale() calls + * may overwrite it. */ + RETVAL = savepv(retval); #ifdef USE_LOCALE_CTYPE if (category == LC_CTYPE #ifdef LC_ALL @@ -1163,9 +1168,13 @@ setlocale(category, locale = 0) } #endif /* USE_LOCALE_NUMERIC */ } + else + RETVAL = NULL; OUTPUT: RETVAL - + CLEANUP: + if (RETVAL) + Safefree(RETVAL); NV acos(x)