pbiering / ipv6calc

ipv6calc
https://www.deepspace6.net/projects/ipv6calc.html
Other
46 stars 15 forks source link

Fix compiler warning related to predefined defaults for external lib and database dir #24

Closed pbiering closed 3 years ago

pbiering commented 3 years ago

Currently idea missing how to proper fix this without breaking existing code:

gcc -o libipv6calc_db_wrapper.so.3.1.0 libipv6calc_db_wrapper.o libipv6calc_db_wrapper_MMDB.o libipv6calc_db_wrapper_GeoIP2.o libipv6calc_db_wrapper_IP2Location.o libipv6calc_db_wrapper_DBIP2.o libipv6calc_db_wrapper_External.o libipv6calc_db_wrapper_BuiltIn.o -lcrypto -Wl,-z,relro -Wl,--as-needed  -Wl,-z,now -specs=/usr/lib/rpm/redhat/redhat-hardened-ld  -ldb -shared -Wl,-soname,libipv6calc_db_wrapper.so.3.1.0
libipv6calc_db_wrapper_External.h:69:13: warning: type of 'external_db_dir' does not match original declaration [-Wlto-type-mismatch]
   69 | extern char external_db_dir[NI_MAXHOST];
      |             ^
libipv6calc_db_wrapper_External.c:33:6: note: array types have different bounds
   33 | char external_db_dir[NI_MAXHOST] = EXTERNAL_DB;
      |      ^
libipv6calc_db_wrapper_External.c:33:6: note: 'external_db_dir' was previously declared here
libipv6calc_db_wrapper_IP2Location.h:597:13: warning: type of 'ip2location_db_dir' does not match original declaration [-Wlto-type-mismatch]
  597 | extern char ip2location_db_dir[NI_MAXHOST];
      |             ^
libipv6calc_db_wrapper_IP2Location.c:33:6: note: array types have different bounds
   33 | char ip2location_db_dir[NI_MAXHOST] = IP2LOCATION_DB;
      |      ^
libipv6calc_db_wrapper_IP2Location.c:33:6: note: 'ip2location_db_dir' was previously declared here
libipv6calc_db_wrapper_IP2Location.h:596:13: warning: type of 'ip2location_lib_file' does not match original declaration [-Wlto-type-mismatch]
  596 | extern char ip2location_lib_file[NI_MAXHOST];
      |             ^
libipv6calc_db_wrapper_IP2Location.c:45:6: note: array types have different bounds
   45 | char ip2location_lib_file[NI_MAXHOST] = IP2LOCATION_DYN_LIB;
      |      ^
libipv6calc_db_wrapper_IP2Location.c:45:6: note: 'ip2location_lib_file' was previously declared here
grayed commented 3 years ago

That's because you forcefully redefine NI_MAXHOST in your code (see lib/ipv6calc_inttypes.h). At one point (in libipv6calc_db_wrapper_IP2Location.h) with NI_MAXHOST coming from system is in use, thus declaring array of one size; then [ipv6calc_inttypes.h] gets included in source code file as well, and then array gets defined with a different size.

Correct solution would be either to stop defining NI_MAXHOST, or make sure compatibility header(-s) defining all such things come in all source code files exactly between system and local headers.

grayed commented 3 years ago

Oh, and using NI_MAXHOST instead of PATH_MAX for filesystem paths sounds like a very bad idea.

pbiering commented 3 years ago

Thank you for digging into, will review and fix this next.

pbiering commented 3 years ago

Oh, and using NI_MAXHOST instead of PATH_MAX for filesystem paths sounds like a very bad idea.

Replacement of NI_MAXHOST by PATH_MAX where applicable: https://github.com/pbiering/ipv6calc/commit/01a949a7cd854ea521efde577eeeeb1022b1e12c

pbiering commented 3 years ago

Replacement of NI_MAXHOST by IPV6CALC_STRING_MAX where still used: https://github.com/pbiering/ipv6calc/commit/9b8170f10469270a273a5b8f6bfcd68db1299f8f