diff options
| author | deraadt <> | 2006-10-29 18:45:56 +0000 |
|---|---|---|
| committer | deraadt <> | 2006-10-29 18:45:56 +0000 |
| commit | aede99584cb0d715ac3f7c41068bc88f09d2a61b (patch) | |
| tree | e411f8b9691e52e1f9798a36d7cf41201ee8300d /src/lib/libc/stdlib/ecvt.c | |
| parent | 182ec138408d8727b97aa8a6b7faef3a1c05037b (diff) | |
| download | openbsd-aede99584cb0d715ac3f7c41068bc88f09d2a61b.tar.gz openbsd-aede99584cb0d715ac3f7c41068bc88f09d2a61b.tar.bz2 openbsd-aede99584cb0d715ac3f7c41068bc88f09d2a61b.zip | |
make __dtoa & strtod() thread-safe useing the same method as newer gdtoa
codebase. tested mostly by ckuethe and myself. __dtoa() use now requires
a call to __freedtoa()
Diffstat (limited to '')
| -rw-r--r-- | src/lib/libc/stdlib/ecvt.c | 14 |
1 files changed, 10 insertions, 4 deletions
diff --git a/src/lib/libc/stdlib/ecvt.c b/src/lib/libc/stdlib/ecvt.c index eb0e428996..719370a8f3 100644 --- a/src/lib/libc/stdlib/ecvt.c +++ b/src/lib/libc/stdlib/ecvt.c | |||
| @@ -1,4 +1,4 @@ | |||
| 1 | /* $OpenBSD: ecvt.c,v 1.5 2006/01/10 16:18:37 millert Exp $ */ | 1 | /* $OpenBSD: ecvt.c,v 1.6 2006/10/29 18:45:56 deraadt Exp $ */ |
| 2 | 2 | ||
| 3 | /* | 3 | /* |
| 4 | * Copyright (c) 2002, 2006 Todd C. Miller <Todd.Miller@courtesan.com> | 4 | * Copyright (c) 2002, 2006 Todd C. Miller <Todd.Miller@courtesan.com> |
| @@ -25,13 +25,14 @@ | |||
| 25 | #include <string.h> | 25 | #include <string.h> |
| 26 | 26 | ||
| 27 | extern char *__dtoa(double, int, int, int *, int *, char **); | 27 | extern char *__dtoa(double, int, int, int *, int *, char **); |
| 28 | extern void __freedtoa(char *); | ||
| 28 | static char *__cvt(double, int, int *, int *, int, int); | 29 | static char *__cvt(double, int, int *, int *, int, int); |
| 29 | 30 | ||
| 30 | static char * | 31 | static char * |
| 31 | __cvt(double value, int ndigit, int *decpt, int *sign, int fmode, int pad) | 32 | __cvt(double value, int ndigit, int *decpt, int *sign, int fmode, int pad) |
| 32 | { | 33 | { |
| 33 | static char *s; | 34 | static char *s; |
| 34 | char *p, *rve; | 35 | char *p, *rve, c; |
| 35 | size_t siz; | 36 | size_t siz; |
| 36 | 37 | ||
| 37 | if (ndigit == 0) { | 38 | if (ndigit == 0) { |
| @@ -64,15 +65,20 @@ __cvt(double value, int ndigit, int *decpt, int *sign, int fmode, int pad) | |||
| 64 | if (*decpt == 9999) { | 65 | if (*decpt == 9999) { |
| 65 | /* Infinity or Nan, convert to inf or nan like printf */ | 66 | /* Infinity or Nan, convert to inf or nan like printf */ |
| 66 | *decpt = 0; | 67 | *decpt = 0; |
| 67 | return(*p == 'I' ? "inf" : "nan"); | 68 | c = *p; |
| 69 | __freedtoa(p); | ||
| 70 | return(c == 'I' ? "inf" : "nan"); | ||
| 68 | } | 71 | } |
| 69 | /* Make a local copy and adjust rve to be in terms of s */ | 72 | /* Make a local copy and adjust rve to be in terms of s */ |
| 70 | if (pad && fmode) | 73 | if (pad && fmode) |
| 71 | siz += *decpt; | 74 | siz += *decpt; |
| 72 | if ((s = (char *)malloc(siz)) == NULL) | 75 | if ((s = (char *)malloc(siz)) == NULL) { |
| 76 | __freedtoa(p); | ||
| 73 | return(NULL); | 77 | return(NULL); |
| 78 | } | ||
| 74 | (void) strlcpy(s, p, siz); | 79 | (void) strlcpy(s, p, siz); |
| 75 | rve = s + (rve - p); | 80 | rve = s + (rve - p); |
| 81 | __freedtoa(p); | ||
| 76 | } | 82 | } |
| 77 | 83 | ||
| 78 | /* Add trailing zeros */ | 84 | /* Add trailing zeros */ |
