[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: c-strtod: improve error checking
From: |
Jim Meyering |
Subject: |
Re: c-strtod: improve error checking |
Date: |
Wed, 21 Jan 2009 14:22:41 +0100 |
Bruno Haible <address@hidden> wrote:
> Here's a proposed patch to improve c_strtod's error checking:
> 1) It currently does not check against a NULL return from newlocale(),
> which can happen for example if out of memory.
> 2) When strtod_l or strtod returns an error, c_strtod fails to preserve
> errno as an error indicator.
Thanks for the fixes.
> 2009-01-21 Bruno Haible <address@hidden>
>
> * lib/c-strtod.c: Include errno.h.
> (C_STRTOD): Check against NULL return from newlocale. Preserve errno
> value from STRTOD_L and STRTOD.
>
> --- lib/c-strtod.c.orig 2009-01-21 12:15:31.000000000 +0100
> +++ lib/c-strtod.c 2009-01-21 12:15:24.000000000 +0100
> @@ -1,6 +1,6 @@
> /* Convert string to double, using the C locale.
>
> - Copyright (C) 2003, 2004, 2006 Free Software Foundation, Inc.
> + Copyright (C) 2003, 2004, 2006, 2009 Free Software Foundation, Inc.
>
> This program is free software: you can redistribute it and/or modify
> it under the terms of the GNU General Public License as published by
> @@ -21,6 +21,7 @@
>
> #include "c-strtod.h"
>
> +#include <errno.h>
> #include <locale.h>
> #include <stdlib.h>
>
> @@ -50,9 +51,18 @@
>
> #ifdef LC_ALL_MASK
>
> - locale_t c_locale = newlocale (LC_ALL_MASK, "C", 0);
> + locale_t c_locale;
> + int saved_errno;
> +
> + c_locale = newlocale (LC_ALL_MASK, "C", (locale_t)0);
I suppose NULL isn't necessarily defined, so ok to add the cast.
But please insert a space between the cast and the "0": (locale_t) 0.
> + if (c_locale == (locale_t)0)
I prefer to avoid casts, so please use this test instead:
if (!c_locale)
- c-strtod: improve error checking, Bruno Haible, 2009/01/21
- Re: c-strtod: improve error checking, Paolo Bonzini, 2009/01/21
- Re: c-strtod: improve error checking,
Jim Meyering <=
- Re: c-strtod: improve error checking, Bruno Haible, 2009/01/21
- Re: c-strtod: improve error checking, Karl Berry, 2009/01/21
- Re: c-strtod: improve error checking, Peter Seebach, 2009/01/21
- Re: c-strtod: improve error checking, Simon Josefsson, 2009/01/21
- Re: NULL macro, Bruno Haible, 2009/01/21
- Re: NULL macro, Simon Josefsson, 2009/01/21