From: Pablo Neira Ayuso Date: Thu, 12 Dec 2024 23:06:14 +0000 (+0100) Subject: src: shrink line_offset in struct location to 4 bytes X-Git-Tag: v1.1.2~109 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=56ded344bc7ee92ec097314e06997e7991553c17;p=thirdparty%2Fnftables.git src: shrink line_offset in struct location to 4 bytes 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 --- diff --git a/include/nftables.h b/include/nftables.h index a6f0e612..2e0d9148 100644 --- a/include/nftables.h +++ b/include/nftables.h @@ -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; diff --git a/src/scanner.l b/src/scanner.l index 4a340b00..9ccbc22d 100644 --- a/src/scanner.l +++ b/src/scanner.l @@ -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)