Bill-Gray / star_cats

Code to access and extract data from a variety of star catalogues
GNU General Public License v3.0
17 stars 7 forks source link

Help Building star_cats #2

Open Wellington-Froelich opened 4 months ago

Wellington-Froelich commented 4 months ago

Hi I would love some help building star_cats. Thanks

Bill-Gray commented 4 months ago

Anything in particular? What have you tried?

Wellington-Froelich commented 4 months ago

Hi Bill, just trying to make it and it threw me this warning message:

gaia32.c: In function 'extract_gaia32_stars_callback':
gaia32.c:113:31: error: '.cat' directive writing 4 bytes into a region of size between 0 and 7 [-Werror=format-overflow=]
  113 |       sprintf( filename, "%03d.cat", zone_number);
      |                               ^~~~
In function 'get_gaia32_zone_file',
    inlined from 'extract_gaia32_stars_callback' at gaia32.c:189:21:
gaia32.c:113:7: note: 'sprintf' output between 8 and 15 bytes into a destination of size 10
  113 |       sprintf( filename, "%03d.cat", zone_number);
      |       ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
cc1.exe: all warnings being treated as errors
make: *** [makefile:71: gaia32.o] Error 1

I know it's just a warning, but I am hesitant to change anything

Bill-Gray commented 4 months ago

Well, that's interesting. (And good for me to know about.)

I've just posted commit ea45b91bf49c358b8903a73d858f0 to fix this. Your compiler is bright enough to notice that filename is ten bytes long. If zone_number were, say, 123456, then the resulting file name would be 123456.cat (ten bytes long) plus a null terminator, and would overflow the end of the buffer.

In reality, there are 180 zones in the Gaia catalog (at least, in this formulation of it). Adding the line

   assert( zone_number >= -1 && zone_number < 180);

causes the compiler to see there's actually no risk of the filename being more than eight bytes (including the null terminator). So the warning/error goes away.

I say "your compiler" because, while I test my code with a variety of gccs, clangs, MSVCs, and sometimes even OpenWATCOM and so forth of varying ages, I hadn't tried compiling this code with gcc-13 before (just did and replicated the error). The GCC folks keep coming up with ways to spot more subtle bugs/possible bugs. Most of them, truthfully, are not all that helpful. But every now and then, they spot something really horrifying. Often enough that I always compile with maximum warnings and treat warnings as errors ("stop now and fix this thing").

I know it's just a warning, but I am hesitant to change anything

I appreciate hearing about stuff like this. Generally speaking, I do a better job of fixing things if I know about them...

With that, though, a further warning. The code in question extracts data from Dave Tholen's version of the Gaia-DR2 catalogue. I don't think he's made it publicly available. If you're interested, though, I can e-mail him and ask if it is (been a while since we corresponded on the subject). I'll also ask if he's got a more current version... he was thinking about doing that, but I gathered DR2 was basically doing most of what he needed.

Wellington-Froelich commented 4 months ago

Wow, thanks for the prompt reply, Bill! I think that did the trick for me, but maybe a file got deleted in the process: here is the error I am getting now:

gcc -Wextra -Wall -O3 -pedantic -Werror -c cmcrange.c
gcc -Wextra -Wall -O3 -pedantic -Werror -c cmc.c
gcc -o cmcrange cmcrange.o cmc.o
gcc -Wextra -Wall -O3 -pedantic -Werror -c cmc_xvt.c
gcc -o cmc_xvt cmc_xvt.o cmc.o
gcc -Wextra -Wall -O3 -pedantic -Werror -c extr_cmc.c
gcc -Wextra -Wall -O3 -pedantic -Werror -c get_cmc.c
gcc -o extr_cmc extr_cmc.o cmc.o get_cmc.o
gcc -Wextra -Wall -O3 -pedantic -Werror -c gaia32.c
gcc -o gaia_ast gaia_ast.c gaia32.o -I ~/include -L ~/lib -llunar -lm
gaia_ast.c:8:10: fatal error: mpc_func.h: No such file or directory
    8 | #include "mpc_func.h"
      |          ^~~~~~~~~~~~
compilation terminated.
make: *** [makefile:56: gaia_ast] Error 1

I looked around for the file, but couldn't locate it on the repo. Is this a dependency I should locate elsewhere?

Bill-Gray commented 4 months ago

maybe a file got deleted in the process No, I think we simply got past one issue and ran into another.

The gaia_ast program is one I use in my work with the asteroid community. It reads in a file of asteroid observations and can say : hang on, these observations in your data coincide with Gaia stars; they may not actually be of asteroids, or if they are, your data will be contaminated with photons from that star.

I am probably the only person actually using gaia_ast. All the other programs can be built without dependencies. So I've revised the makefile to omit gaia_ast. Do a 'git pull' to get that revised makefile, and everything should build without errors.

If somebody really wants gaia_ast, they can get the lunar repo, build and install that library, and then run make gaia_ast.

Wellington-Froelich commented 4 months ago

Thanks for the help Bill,

I was successfully able to build!