]> git.ipfire.org Git - thirdparty/FORT-validator.git/commitdiff
Feature test macro review (cont.)
authorAlberto Leiva Popper <ydahhrk@gmail.com>
Tue, 3 Oct 2023 21:26:08 +0000 (15:26 -0600)
committerAlberto Leiva Popper <ydahhrk@gmail.com>
Tue, 3 Oct 2023 23:28:23 +0000 (17:28 -0600)
I found a couple of symbols I missed during the previous macro review:

- getline(). This forces POSIX >= 2008.
- IN6_ARE_ADDR_EQUAL(). I can't find where this is supposed to be
  standardized, so I decided to ditch it.

Also, declaring these macros in every dependent file is scaling poorly,
so I moved them to the CC directives, unifying them in the process.
_POSIX_C_SOURCE is now 200809L, and _XOPEN_SOURCE is 700 (to match).

Also, reduce -std to c99. I don't really have an issue with gnu11, but
it looks like the delta is heavily underutilized in the project.
Might revert it later.

Finally, update the unit tests.

32 files changed:
src/Makefile.am
src/alloc.c
src/asn1/asn1c/BIT_STRING.c
src/asn1/asn1c/GeneralizedTime.c
src/asn1/asn1c/OBJECT_IDENTIFIER.c
src/asn1/asn1c/UTCTime.c
src/asn1/asn1c/asn_bit_data.c
src/asn1/asn1c/asn_internal.c
src/asn1/asn1c/ber_tlv_tag.c
src/asn1/asn1c/constraints.c
src/cache/local_cache.c
src/config.c
src/data_structure/path_builder.c
src/file.c
src/json_handler.c
src/line_file.c
src/log.c
src/object/manifest.c
src/rtr/rtr.c
src/types/address.c
src/types/address.h
src/types/vrp.c
src/xml/relax_ng.c
test/Makefile.am
test/cache/local_cache_test.c
test/line_file_test.c
test/mock.c
test/rtr/db/db_table_test.c
test/rtr/db/vrps_test.c
test/rtr/pdu_handler_test.c
test/rtr/pdu_test.c
test/tal_test.c

index d4c47bb9498ae59b933a771f9db17fb2a9df87e2..19db79a77f6605906ad8ae7a6c2853cb8ef96b34 100644 (file)
@@ -120,10 +120,11 @@ fort_SOURCES += xml/relax_ng.c xml/relax_ng.h
 include asn1/asn1c/Makefile.include
 fort_SOURCES += $(ASN_MODULE_SRCS) $(ASN_MODULE_HDRS)
 
-fort_CFLAGS  = -Wall -Wno-cpp -Wpedantic
+fort_CFLAGS  = -Wall -Wpedantic
 # Feel free to temporarily remove this one if you're not using gcc 7.3.0.
 #fort_CFLAGS += $(GCC_WARNS)
-fort_CFLAGS += -std=gnu11 -O2 -g $(FORT_FLAGS) ${XML2_CFLAGS}
+fort_CFLAGS += -std=c99 -D_POSIX_C_SOURCE=200809 -D_XOPEN_SOURCE=700
+fort_CFLAGS += -O2 -g $(FORT_FLAGS) ${XML2_CFLAGS}
 if BACKTRACE_ENABLED
 fort_CFLAGS += -DBACKTRACE_ENABLED
 endif
index 78e36e7a0404369f8742e39c7ef27d21979130f3..84c8d834ca174e50fb992f7ef6d9c7e5c0910969 100644 (file)
@@ -1,5 +1,3 @@
-#define _XOPEN_SOURCE 500 /* strdup() */
-
 #include "alloc.h"
 
 #include "log.h"
index ff3a4765d048aa9e381b3d22ba14257244d3985c..4e0637cd0be6e63b19ecbe1f23410dbf07881bad 100644 (file)
@@ -3,8 +3,6 @@
  * Redistribution and modifications are permitted subject to BSD license.
  */
 
-#define _XOPEN_SOURCE 500 /* snprintf() */
-
 #include <assert.h>
 
 #include "asn1/asn1c/asn_internal.h"
index badade4adc00c4d334d562c1b3b0027a52a01f0f..e9b12a6bead63d590c053f8128201665e046f603 100644 (file)
@@ -6,9 +6,6 @@
 #define        _REENTRANT                      /* for Sun */
 #define __EXTENSIONS__                  /* for Sun */
 
-#define _XOPEN_SOURCE 600 /* snprintf(), timezone */
-#define _POSIX_C_SOURCE 200112L /* gmtime_r(), localtime_r(), tzset() */
-
 #include "asn1/asn1c/asn_internal.h"
 #include "asn1/asn1c/GeneralizedTime.h"
 
index fc40fa18a632e499a020c49a36e0fe6dfa695895..a94b81f9518f94064b675e85657f2e8eda8dc7d9 100644 (file)
@@ -3,8 +3,6 @@
  * Redistribution and modifications are permitted subject to BSD license.
  */
 
-#define _XOPEN_SOURCE 500 /* snprintf() */
-
 #include "asn1/asn1c/asn_internal.h"
 #include "asn1/asn1c/INTEGER.h"
 #include "asn1/asn1c/OBJECT_IDENTIFIER.h"
index cf8df4f5d4663c9bbaff3cb25ee219159af2a58d..8609140759b06773a8d8f91cb8985336ebc5850f 100644 (file)
@@ -3,8 +3,6 @@
  * Redistribution and modifications are permitted subject to BSD license.
  */
 
-#define _XOPEN_SOURCE 500 /* snprintf() */
-
 #include "asn1/asn1c/asn_internal.h"
 #include "asn1/asn1c/UTCTime.h"
 #include "asn1/asn1c/GeneralizedTime.h"
index 121f4843fdc6283f1de5484f2190b4c4957a967e..85602f4f915078b98230d1923046f4bba9d215b1 100644 (file)
@@ -4,8 +4,6 @@
  * Redistribution and modifications are permitted subject to BSD license.
  */
 
-#define _XOPEN_SOURCE 500 /* snprintf() */
-
 #include <assert.h>
 
 #include "asn1/asn1c/asn_system.h"
index 11cd788f99f7ec12da7126a2005bc931dcd3f006..771ce94601704e4884f59a83511af68153abae10 100644 (file)
@@ -1,5 +1,3 @@
-#define _XOPEN_SOURCE 500 /* vsnprintf() */
-
 #include "asn1/asn1c/asn_internal.h"
 
 #include <stdarg.h>
index ce961c0d844ec54940391c7a90694e8aad688c68..b0c7879239de3787c6aa211f74da13f22dad2e4a 100644 (file)
@@ -3,8 +3,6 @@
  * Redistribution and modifications are permitted subject to BSD license.
  */
 
-#define _XOPEN_SOURCE 500 /* snprintf() */
-
 #include "asn1/asn1c/asn_internal.h"
 #include "asn1/asn1c/ber_tlv_tag.h"
 #include <errno.h>
index b3325aecfdc8cf0cc5332949143307abef15a18c..3cfbe94c646eb01af20d5b6f574ba1de63681f0f 100644 (file)
@@ -1,5 +1,3 @@
-#define _XOPEN_SOURCE 500 /* vsnprintf() */
-
 #include "asn1/asn1c/asn_internal.h"
 #include "asn1/asn1c/constraints.h"
 #include <stdarg.h>
index e8c162964e2dcc58a174c9de5e9fd3bf1a6dd6ae..e58a1260429f14ade8726305cd6da27ed467476a 100644 (file)
@@ -1,6 +1,3 @@
-#define _XOPEN_SOURCE 600 /* strptime() */
-#define _POSIX_C_SOURCE 200112L /* localtime_r(), strtok_r() */
-
 #include "cache/local_cache.h"
 
 #include <time.h>
index 7598a6615a6ee9746b07fd440b69d7e8284178bb..531f55003a6afcef246d75ae8f583a622874bf75 100644 (file)
@@ -1,5 +1,3 @@
-#define _GNU_SOURCE /* getopt_long() */
-
 #include "config.h"
 
 #include <getopt.h>
index b94045405569a697e3397d19b3ba6e91857ce42b..3783992749bb77b66db53e528e83c8969d3102d3 100644 (file)
@@ -1,5 +1,3 @@
-#define _XOPEN_SOURCE 500 /* snprintf() */
-
 #include "data_structure/path_builder.h"
 
 #include <errno.h>
index 42013f988243e1e7921a232b686ec39510264ab8..678e951762623d2267b62cd53a133c9b743cfcbd 100644 (file)
@@ -1,6 +1,3 @@
-#define _XOPEN_SOURCE 600 /* nftw() */
-#define _POSIX_C_SOURCE 200112L /* fileno() */
-
 #include "file.h"
 
 #include <ftw.h>
index ed801ce4e004d35067aaef32fafe4d43705e2f20..19f3cd687fccfeaca3186a163b039efa180129d1 100644 (file)
@@ -1,5 +1,3 @@
-#define _POSIX_C_SOURCE 200112L /* strtok_r() */
-
 #include "json_handler.h"
 
 #include <errno.h>
index 81144511596ff79d18b38c9064166ab76c6cebf1..8dc44c405017d223e6a34f4709b7e951cc7bf3cd 100644 (file)
@@ -87,6 +87,9 @@ lfile_read(struct line_file *lfile, char **result)
         * because getline is normally meant to be used repeatedly with a
         * recycled buffer. (free() is a no-op if its argument is NULL so go
         * nuts.)
+        *
+        * Update: If you remove getline(), consider downgrading _POSIX_C_SOURCE
+        * to 200112L. (And _XOPEN_SOURCE to 600.)
         */
 
        string = NULL;
index c4a45ed0836a5a467fd92b181717de1b5fe580d7..b82370c01749369642de9e9dce05cb62b1a5d023 100644 (file)
--- a/src/log.c
+++ b/src/log.c
@@ -1,6 +1,3 @@
-#define _XOPEN_SOURCE 600 /* vsnprintf() */
-#define _POSIX_C_SOURCE 200112L /* localtime_r() */
-
 #include "log.h"
 
 #ifdef BACKTRACE_ENABLED
index bf6df56d4aa074c85db609063a0a9a4992620087..39309a5d9e8008a11564a95b78e0568dea17f542 100644 (file)
@@ -1,5 +1,3 @@
-#define _POSIX_C_SOURCE 200112L /* localtime_r() */
-
 #include "object/manifest.h"
 
 #include "algorithm.h"
index 230928c46ad8730307b966d72f223ca68c37d137..41130dda83dcba855b7b7af86ac6d5c3ba2554ea 100644 (file)
@@ -1,6 +1,3 @@
-/* getaddrinfo(), freeaddrinfo(), gai_strerror() */
-#define _POSIX_C_SOURCE 200112L
-
 #include "rtr/rtr.h"
 
 #include <errno.h>
index e7a34047351d83836317c3022b37043268672e07..ee1c56d9177e994cae845707576ae59f8a7cc5d7 100644 (file)
@@ -130,6 +130,17 @@ ipv6_suffix_mask(unsigned int prefix_len, struct in6_addr *result)
        }
 }
 
+bool
+addr6_equals(struct in6_addr const *a, struct in6_addr const *b)
+{
+       unsigned int i;
+       for (i = 0; i < INET_ADDRSTRLEN; i++) {
+               if (a->s6_addr[i] != b->s6_addr[i])
+                       return false;
+       }
+       return true;
+}
+
 bool
 prefix4_equals(struct ipv4_prefix const *a, struct ipv4_prefix const *b)
 {
@@ -139,7 +150,7 @@ prefix4_equals(struct ipv4_prefix const *a, struct ipv4_prefix const *b)
 bool
 prefix6_equals(struct ipv6_prefix const *a, struct ipv6_prefix const *b)
 {
-       return (a->len == b->len) && IN6_ARE_ADDR_EQUAL(&a->addr, &b->addr);
+       return (a->len == b->len) && addr6_equals(&a->addr, &b->addr);
 }
 
 /**
index e586bcd48a9b79d295e361872d18755ada508941..d695e0d2aa71b22c659829341987322cfeaa6d8c 100644 (file)
@@ -31,6 +31,8 @@ void in6_addr_init(struct in6_addr *, uint32_t, uint32_t, uint32_t, uint32_t);
 uint32_t u32_suffix_mask(unsigned int);
 void ipv6_suffix_mask(unsigned int, struct in6_addr *);
 
+bool addr6_equals(struct in6_addr const *, struct in6_addr const *);
+
 bool prefix4_equals(struct ipv4_prefix const *, struct ipv4_prefix const *);
 bool prefix6_equals(struct ipv6_prefix const *, struct ipv6_prefix const *);
 
index 1585bc47bd5077dd4fdcf0b1d78b20c05ea0e025..648944d8c09abeda88994292e37177e1d0bbfad1 100644 (file)
@@ -16,7 +16,7 @@ vrp_equals(struct vrp const *a, struct vrp const *b)
        case AF_INET:
                return a->prefix.v4.s_addr == b->prefix.v4.s_addr;
        case AF_INET6:
-               return IN6_ARE_ADDR_EQUAL(&a->prefix.v6, &b->prefix.v6);
+               return addr6_equals(&a->prefix.v6, &b->prefix.v6);
        }
 
        pr_crit("Unknown address family: %u", a->addr_fam);
index 091560264d36e5fd1aeb34078816962365dce21e..00d8a109ffe28b6527236d543e2d01071b09b215 100644 (file)
@@ -1,5 +1,3 @@
-#define _XOPEN_SOURCE 500 /* vsnprintf() */
-
 #include "xml/relax_ng.h"
 
 #include <stdarg.h>
index c6e293994ea6a51b8da3dd8ccd6d5cec792eeabc..80dbc94e16b0b40baa87707fdb31b13bae29492e 100644 (file)
@@ -12,7 +12,9 @@ if USE_TESTS
 # <mumble>_CFLAGS is not defined.
 # Otherwise it must be included manually:
 #      mumble_mumble_CFLAGS = ${AM_CFLAGS} flag1 flag2 flag3 ...
-AM_CFLAGS = -pedantic -Wall -std=gnu11 -I../src -DUNIT_TESTING ${CHECK_CFLAGS} ${XML2_CFLAGS}
+AM_CFLAGS =  -pedantic -Wall
+AM_CFLAGS += -std=c99 -D_POSIX_C_SOURCE=200809 -D_XOPEN_SOURCE=700
+AM_CFLAGS += -I../src -DUNIT_TESTING ${CHECK_CFLAGS} ${XML2_CFLAGS}
 # Reminder: As opposed to AM_CFLAGS, "AM_LDADD" is not idiomatic automake, and
 # autotools will even reprehend us if we declare it. Therefore, I came up with
 # "my" own "ldadd". Unlike AM_CFLAGS, it needs to be manually added to every
index fb9ceaa14fcb9bac7c54683c3e73dadd92691f64..3dd4d13f2191c5d67629464b3a7e491e460c6277 100644 (file)
@@ -1,7 +1,5 @@
 /* This test will create temporal directory "tmp/". Needs permissions. */
 
-#define _XOPEN_SOURCE 500 /* snprintf() */
-
 #include "cache/local_cache.c"
 
 #include <check.h>
index 01a4ab5c55ee46928696b4dd2c73b812f55f37a7..9a374da92f8ba1889381a448844c4e49cfaafe00 100644 (file)
@@ -1,5 +1,3 @@
-#define _XOPEN_SOURCE 500
-
 #include <check.h>
 #include <errno.h>
 #include <stdlib.h>
index eb83f51ab66bc35d51be49c11ed53ec5f3e7a1ec..9d63e9a44458897881d7d0a6f4616e002c133ab5 100644 (file)
@@ -3,6 +3,8 @@
 #include <errno.h>
 #include <arpa/inet.h>
 #include "state.h"
+#include "config/filename_format.h"
+#include "config/mode.h"
 #include "incidence/incidence.h"
 
 /**
index df837fbd8979b3005b7b2eb7ee0333dbf8f604ea..16fa0b3ad9aabd5eb15acd059798933e88c2475f 100644 (file)
@@ -38,7 +38,7 @@ vrp_equals_v6(struct vrp const *vrp, uint8_t as, uint32_t addr,
 
        return (AF_INET6 == vrp->addr_fam)
            && (as == vrp->asn)
-           && IN6_ARE_ADDR_EQUAL(&tmp, &vrp->prefix.v6)
+           && addr6_equals(&tmp, &vrp->prefix.v6)
            && (prefix_len == vrp->prefix_length)
            && (max_prefix_len == vrp->max_prefix_length);
 }
index e0bbc5b9e6f5cbd36350757f8d9221b482411980..d5726b971ca8e3dc7ebfeabe872f8d8b4ab0b206 100644 (file)
@@ -1,5 +1,3 @@
-#define _XOPEN_SOURCE 500 /* nftw() */
-
 #include <check.h>
 #include <stdbool.h>
 #include <stdlib.h>
@@ -71,7 +69,7 @@ static const bool deltas_4to4[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, };
 unsigned int deltas_lifetime = 5;
 
 MOCK_UINT(config_get_deltas_lifetime, deltas_lifetime, void)
-MOCK_VOID(cache_prepare, void)
+MOCK_INT(cache_prepare, 0, void)
 
 /* Test functions */
 
@@ -137,7 +135,7 @@ get_vrp_index(struct vrp const *vrp)
 
        case AF_INET6:
                in6_addr_init(&tmp, 0x20010DB8u, 0, 0, 0);
-               ck_assert(IN6_ARE_ADDR_EQUAL(&tmp, &vrp->prefix.v6));
+               ck_assert(addr6_equals(&tmp, &vrp->prefix.v6));
                ck_assert_uint_eq(96, vrp->prefix_length);
                ck_assert_uint_eq(120, vrp->max_prefix_length);
                family_bit = 1;
index 181483a2e6be3de22cceb5fac7371282c9343ea2..2215192a075c4dfaa5bf0002590946a3690ae809 100644 (file)
@@ -1,5 +1,3 @@
-#define _XOPEN_SOURCE 500
-
 #include <check.h>
 #include <stdlib.h>
 #include <unistd.h>
@@ -27,7 +25,7 @@
 MOCK_ABORT_INT(read_int32, struct pdu_reader *reader, uint32_t *result)
 MOCK_ABORT_INT(read_int8, struct pdu_reader *reader, uint8_t *result)
 
-MOCK_VOID(cache_prepare, void)
+MOCK_INT(cache_prepare, 0, void)
 
 MOCK_INT(slurm_apply, 0, struct db_table *base, struct db_slurm **slurm)
 MOCK_ABORT_VOID(db_slurm_destroy, struct db_slurm *db)
index e326b6cf83613c32728cff9141caa2a47de0d910..fd622643f1acaa1adb8444d0125dd6b60ef03e1c 100644 (file)
@@ -174,7 +174,7 @@ START_TEST(test_ipv6_prefix_from_stream)
        ck_assert_uint_eq(pdu.max_length, 35);
        ck_assert_uint_eq(pdu.zero, 36);
        in6_addr_init(&tmp, 0x25262728, 0x292a2b2c, 0x2d2e2f30, 0x31323334);
-       ck_assert(IN6_ARE_ADDR_EQUAL(&tmp, &pdu.ipv6_prefix));
+       ck_assert(addr6_equals(&tmp, &pdu.ipv6_prefix));
        ck_assert_uint_eq(pdu.asn, 0x35363738);
 }
 END_TEST
index 04614c5e61031feffab3b38ceaf37d5672c06e8a..c553a0c499bcd753473ac3568968f3ad2be0577b 100644 (file)
@@ -1,5 +1,3 @@
-#define _XOPEN_SOURCE 500 /* nftw() */
-
 #include "object/tal.c"
 
 #include <check.h>