bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

use of thread-unsafe localeconv in vasprintf


From: Simon Josefsson
Subject: use of thread-unsafe localeconv in vasprintf
Date: Sat, 17 Mar 2007 13:30:47 +0100
User-agent: Gnus/5.110006 (No Gnus v0.6) Emacs/22.0.94 (gnu/linux)

In gsasl I have a script that try to help me make sure I don't use
thread unsafe functions (included below for reference), and after
updating gnulib for it, it triggers on vasnprintf.c:

../lib/gl/vasnprintf.c:#include <locale.h>      /* localeconv() */
../lib/gl/vasnprintf.c:                             localeconv () -> 
decimal_point;
../lib/gl/vasnprintf.c:                             localeconv () -> 
decimal_point;

According to:

http://www.opengroup.org/onlinepubs/009695399/functions/localeconv.html

"The localeconv() function need not be reentrant. A function that is
not required to be reentrant is not required to be thread-safe."

Is there a thread-safe replacement for localeconv?  If not, can we
install something like the patch below, to allow thread-safe
vasnprintf?

--- vasnprintf.c        12 Mar 2007 12:41:12 +0100      1.28
+++ vasnprintf.c        17 Mar 2007 13:29:42 +0100      
@@ -34,7 +34,9 @@
 # include "vasnprintf.h"
 #endif
 
+#if !DONT_USE_LOCALECONV
 #include <locale.h>    /* localeconv() */
+#endif
 #include <stdio.h>     /* snprintf(), sprintf() */
 #include <stdlib.h>    /* abort(), malloc(), realloc(), free() */
 #include <string.h>    /* memcpy(), strlen() */
@@ -497,8 +499,10 @@
                              if ((flags & FLAG_ALT)
                                  || mantissa > 0.0L || precision > 0)
                                {
-                                 const char *point =
-                                   localeconv () -> decimal_point;
+                                 const char *point = ".";
+#if !DONT_USE_LOCALECONV
+                                 point = localeconv () -> decimal_point;
+#endif
                                  /* The decimal point is always a single byte:
                                     either '.' or ','.  */
                                  *p++ = (point[0] != '\0' ? point[0] : '.');
@@ -645,8 +649,10 @@
                              if ((flags & FLAG_ALT)
                                  || mantissa > 0.0 || precision > 0)
                                {
-                                 const char *point =
-                                   localeconv () -> decimal_point;
+                                 const char *point = ".";
+#if !DONT_USE_LOCALECONV
+                                 point = localeconv () -> decimal_point;
+#endif
                                  /* The decimal point is always a single byte:
                                     either '.' or ','.  */
                                  *p++ = (point[0] != '\0' ? point[0] : '.');

/Simon

#!/bin/sh

# Copyright (C) 2004, 2005 Simon Josefsson
#
# This file is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2, or (at your option)
# any later version.
#
# This file is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this file; if not, write to the Free Software Foundation,
# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.

FILES="$@"
FILES=${FILES:-$THREADSAFETY_FILES}

if test -z "$FILES"; then
    echo "Usage: $0 [FILE...]"
    exit 1
fi

# http://www.opengroup.org/onlinepubs/009695399/functions/xsh_chap02_09.html
UNSAFE="asctime basename catgets crypt ctime dbm_clearerr dbm_close dbm_delete 
dbm_error dbm_fetch dbm_firstkey dbm_nextkey dbm_open dbm_store dirname dlerror 
drand48 ecvt encrypt endgrent endpwent endutxent fcvt ftw gcvt getc_unlocked 
getchar_unlocked getdate getenv getgrent getgrgid getgrnam gethostbyaddr 
gethostbyname gethostent getlogin getnetbyaddr getnetbyname getnetent getopt 
getprotobyname getprotobynumber getprotoent getpwent getpwnam getpwuid 
getservbyname getservbyport getservent getutxent getutxid getutxline gmtime 
hcreate hdestroy hsearch inet_ntoa l64a lgamma lgammaf lgammal localeconv 
localtime lrand48 mrand48 nftw nl_langinfo ptsname putc_unlocked 
putchar_unlocked putenv pututxline rand readdir setenv setgrent setkey setpwent 
setutxent strerror strtok ttyname unsetenv wcstombs wctomb"

set -- $UNSAFE
cmd="-e [^_0-9a-z]($1"
shift
while test "$1"; do
    cmd="${cmd}|$1"
    shift
done
cmd="${cmd})[^_0-9a-z]*\("

if egrep $cmd $FILES; then
    exit 1
fi

exit 0




reply via email to

[Prev in Thread] Current Thread [Next in Thread]