This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
Re: [PATCH v3] Replace use of snprintf with strfrom in libm tests
- From: Joseph Myers <joseph at codesourcery dot com>
- To: "Gabriel F. T. Gomes" <gftg at linux dot vnet dot ibm dot com>
- Cc: <libc-alpha at sourceware dot org>
- Date: Mon, 19 Dec 2016 22:52:27 +0000
- Subject: Re: [PATCH v3] Replace use of snprintf with strfrom in libm tests
- Authentication-results: sourceware.org; auth=none
- References: <1482182728-12524-1-git-send-email-gftg@linux.vnet.ibm.com>
On Mon, 19 Dec 2016, Gabriel F. T. Gomes wrote:
> +/* Converts VALUE (a floating-point number) to string and writes it to DEST.
> + PRECISION specifies the number of fractional digits that should be printed.
> + CONVERSION is the conversion specifier, such as in printf, e.g. 'f' or 'a'.
> + The output is prepended with an empty space if VALUE is non-negative and if
> + SPACE is true. The function fmt_ftostr calls one of the strfrom functions
> + and returns the same code. */
> +static int
> +fmt_ftostr (char *dest, size_t size, bool space, int precision,
> + const char *conversion, FLOAT value)
As far as I can see, all calls to this function have the following
properties:
* The return value is not used.
* The "space" argument is always 1.
So make the function return void and always have the "space" semantics
rather than having that argument at all. This avoids at least three
problems: (a) if you're returning a value indicating the number of
characters output, it needs to account for the added space, which this
implementation does not; (b) by using bool you're relying on implicit
inclusion of <stdbool.h> by include/fenv.h (that is, you'd need to add an
include of <stdbool.h> to avoid the test breaking if we stop tests using
internal headers as much as possible); (c) when using bool you should use
"true" instead of 1.
--
Joseph S. Myers
joseph@codesourcery.com