From c16a8c71ce7f67534a808fecca24d1aa767c7b90 Mon Sep 17 00:00:00 2001 From: Amaan Qureshi Date: Tue, 18 Jul 2023 05:27:48 -0400 Subject: [PATCH] fix: pass a value_id the same size of predicate_capture_ids's elements to avoid big-endian integer narrowing This solves a bug on big-endian architectures where the value would be later passed by reference as an elements "view" before being inserted. The issue is it is casted as a void pointer, and when writing uint16_t's of size 1, only 2 of the 4 bytes are written. This is okay for little-endian systems, but not big-endian --- lib/src/query.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/src/query.c b/lib/src/query.c index 64ab57e2..b44fd9c8 100644 --- a/lib/src/query.c +++ b/lib/src/query.c @@ -1788,7 +1788,8 @@ static bool ts_query__analyze_patterns(TSQuery *self, unsigned *error_offset) { ) { TSQueryPredicateStep *step = &self->predicate_steps.contents[j]; if (step->type == TSQueryPredicateStepTypeCapture) { - array_insert_sorted_by(&predicate_capture_ids, , step->value_id); + uint16_t value_id = step->value_id; + array_insert_sorted_by(&predicate_capture_ids, , value_id); } }