This is the mail archive of the libc-alpha@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH v3] Replace use of snprintf with strfrom in libm tests


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]