]> git.ipfire.org Git - thirdparty/nftables.git/commitdiff
src: shrink line_offset in struct location to 4 bytes
authorPablo Neira Ayuso <pablo@netfilter.org>
Thu, 12 Dec 2024 23:06:14 +0000 (00:06 +0100)
committerPablo Neira Ayuso <pablo@netfilter.org>
Thu, 2 Jan 2025 18:58:11 +0000 (19:58 +0100)
line_offset of 2^32 bytes should be enough.

This requires the removal of the last_line field (in a previous patch) to
shrink struct expr to 112 bytes.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
include/nftables.h
src/scanner.l

index a6f0e6128887db8060d393a6dfe9f7230e774644..2e0d91486a2948fe55498fc559ede32532502be8 100644 (file)
@@ -158,8 +158,7 @@ struct location {
        const struct input_descriptor           *indesc;
        union {
                struct {
-                       off_t                   line_offset;
-
+                       unsigned int            line_offset;
                        unsigned int            first_line;
                        unsigned int            first_column;
                        unsigned int            last_column;
index 4a340b00fdc66d29cfe5c325add2d20a9e982009..9ccbc22d212043876ab70273238e8424ba85c772 100644 (file)
@@ -88,8 +88,15 @@ static void update_pos(struct parser_state *state, struct location *loc,
 static void update_offset(struct parser_state *state, struct location *loc,
                          unsigned int len)
 {
+       uint32_t line_offset;
+
        state->indesc->token_offset     += len;
-       loc->line_offset                = state->indesc->line_offset;
+       if (state->indesc->line_offset > UINT32_MAX)
+               line_offset = UINT32_MAX;
+       else
+               line_offset = state->indesc->line_offset;
+
+       loc->line_offset                = line_offset;
 }
 
 static void reset_pos(struct parser_state *state, struct location *loc)