Fix compiler warning related to predefined defaults for external lib and database dir
Closed this issue · 5 comments
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
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.
Oh, and using NI_MAXHOST
instead of PATH_MAX
for filesystem paths sounds like a very bad idea.
Thank you for digging into, will review and fix this next.