postgrespro / pgsphere

PgSphere provides spherical data types, functions, operators, and indexing for PostgreSQL.
https://pgsphere.org
BSD 3-Clause "New" or "Revised" License
16 stars 15 forks source link

Fix warnings in output.c #51

Closed vitcpp closed 10 months ago

vitcpp commented 10 months ago

The variable sphere_output_precision type is changed to int because sprintf requires this argument to be of type int when used as the precision specificator (argument for '*' symbol in the sprintf template).

vitcpp commented 10 months ago

@esabol It is interesting, that I tried this:

sprintf(&buf[0], "%.*gd, (int)sphere_output_precision, ...

And I found that it doesn't fix the warning on my side. I use gcc 11.3.0. The warning is enabled by -Wformat-overflow. Some heuristic in gcc is used in this case. It seems it somehow defines that sphere_output_precision may be much greater than DBL_DIG. I can't explain why such change doesn't fix the warning but change the type to int fixes it.

vitcpp commented 10 months ago

The warnings are fixed for Focal dist. The rest will be fixed in PR #39. Lets incorporate this patch first, #39 will be the next.