]> git.ipfire.org Git - thirdparty/nftables.git/commitdiff
meta: fix compiler warning in date_type_parse()
authorLukas Straub <lukasstraub2@web.de>
Tue, 5 Apr 2022 16:43:30 +0000 (16:43 +0000)
committerPablo Neira Ayuso <pablo@netfilter.org>
Tue, 5 Apr 2022 19:59:41 +0000 (21:59 +0200)
After commit 0210097879 ("meta: time: use uint64_t instead of time_t")
there is a compiler warning due to comparison of the return value from
parse_iso_date with -1, which is now implicitly cast to uint64_t.

Fix this by making parse_iso_date take a pointer to the tstamp and
return bool instead.

Fixes: 0210097879 ("meta: time: use uint64_t instead of time_t")
Signed-off-by: Lukas Straub <lukasstraub2@web.de>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
src/meta.c

index c0e2608db1ae30e2ee08844aaab56569a7c1ad8c..80ace25b8c97b4ecb453e8cd301f71871ccdf1f3 100644 (file)
@@ -405,7 +405,7 @@ static void date_type_print(const struct expr *expr, struct output_ctx *octx)
                nft_print(octx, "Error converting timestamp to printed time");
 }
 
-static time_t parse_iso_date(const char *sym)
+static bool parse_iso_date(uint64_t *tstamp, const char *sym)
 {
        struct tm tm, *cur_tm;
        time_t ts;
@@ -419,7 +419,7 @@ static time_t parse_iso_date(const char *sym)
        if (strptime(sym, "%F", &tm))
                goto success;
 
-       return -1;
+       return false;
 
 success:
        /*
@@ -436,7 +436,9 @@ success:
                return ts;
 
        /* Substract tm_gmtoff to get the current time */
-       return ts - cur_tm->tm_gmtoff;
+       *tstamp = ts - cur_tm->tm_gmtoff;
+
+       return true;
 }
 
 static struct error_record *date_type_parse(struct parse_ctx *ctx,
@@ -446,7 +448,7 @@ static struct error_record *date_type_parse(struct parse_ctx *ctx,
        const char *endptr = sym->identifier;
        uint64_t tstamp;
 
-       if ((tstamp = parse_iso_date(sym->identifier)) != -1)
+       if (parse_iso_date(&tstamp, sym->identifier))
                goto success;
 
        tstamp = strtoul(sym->identifier, (char **) &endptr, 10);