From 1ba01ae30179f2a8998a11d70df713a205922f5f Mon Sep 17 00:00:00 2001 From: Steve Hay Date: Wed, 27 Jun 2007 17:08:01 +0000 Subject: 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 --- ext/POSIX/POSIX.xs | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) (limited to 'ext/POSIX/POSIX.xs') diff --git a/ext/POSIX/POSIX.xs b/ext/POSIX/POSIX.xs index 388a260244..9ddfd3ae48 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) -- cgit v1.2.1