Skip to contentSkip to conversation

src: remove last_line from struct location

PATCH New Pablo Neira Ayuso 1 participant 2 messages Dec 12, 2024 netfilter

lore
Share & tools
lore

Pablo Neira Ayuso

author maintainer
#0 lore raw

PATCH 1/2 src: remove last_line from struct location

This 4 bytes field is never used, remove it.

This does not shrink struct location in x86_64 due to alignment.

---
 include/nftables.h | 1 -
 src/parser_bison.y | 3 +--
 src/parser_json.c  | 1 -
 src/scanner.l      | 1 -
 4 files changed, 1 insertion(+), 5 deletions(-)
include/nftables.h +0 -1
index 7d891b439a2d..a6f0e6128887 100644
@@ -161,7 +161,6 @@ struct location {
 			off_t			line_offset;
 
 			unsigned int		first_line;
-			unsigned int		last_line;
 			unsigned int		first_column;
 			unsigned int		last_column;
 		};
src/parser_bison.y +1 -2
index 6e8b639104fc..e107ddfd3e4e 100644
@@ -105,12 +105,11 @@ static void location_update(struct location *loc, struct location *rhs, int n)
 		loc->line_offset  = rhs[1].line_offset;
 		loc->first_line   = rhs[1].first_line;
 		loc->first_column = rhs[1].first_column;
-		loc->last_line    = rhs[n].last_line;
 		loc->last_column  = rhs[n].last_column;
 	} else {
 		loc->indesc       = rhs[0].indesc;
 		loc->line_offset  = rhs[0].line_offset;
-		loc->first_line   = loc->last_line   = rhs[0].last_line;
+		loc->first_line   = rhs[0].first_line;
 		loc->first_column = loc->last_column = rhs[0].last_column;
 	}
 }
src/parser_json.c +0 -1
index 5ac5f0270d32..17bc38b565ae 100644
@@ -123,7 +123,6 @@ static void json_lib_error(struct json_ctx *ctx, json_error_t *err)
 		.indesc = &json_indesc,
 		.line_offset = err->position - err->column,
 		.first_line = err->line,
-		.last_line = err->line,
 		.first_column = err->column,
 		/* no information where problematic part ends :( */
 		.last_column = err->column,
src/scanner.l +0 -1
index ecdba404b2cd..4a340b00fdc6 100644
@@ -80,7 +80,6 @@ static void update_pos(struct parser_state *state, struct location *loc,
 {
 	loc->indesc			= state->indesc;
 	loc->first_line			= state->indesc->lineno;
-	loc->last_line			= state->indesc->lineno;
 	loc->first_column		= state->indesc->column;
 	loc->last_column		= state->indesc->column + len - 1;
 	state->indesc->column		+= len;
Signature · 1 line
2.30.2
author maintainer
#1 lore raw

PATCH 2/2 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.

---
 include/nftables.h | 3 +--
 src/scanner.l      | 9 ++++++++-
 2 files changed, 9 insertions(+), 3 deletions(-)
include/nftables.h +1 -2
index a6f0e6128887..2e0d91486a29 100644
@@ -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;
src/scanner.l +8 -1
index 4a340b00fdc6..9ccbc22d2120 100644
@@ -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)
Signature · 1 line
2.30.2