Skip to contentSkip to conversation

fix stream_prev() for invalid (negative) stream

PATCH New Luc Van Oostenryck 1 participant 1 message Jul 29, 2020 Sparse checker

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 fix stream_prev() for invalid (negative) stream

Now that the parent stream is stored as a position, the validity of a stream can't anymore be tested by checking if its number is non-negative because inside a struct position stream number are stored as an unsigned (and changing it to signed would halve the maximum number of stream).

So, add a check against input_stream_nr before returning the previous stream.

Fixes 4c6cbe557c48205f9b3d2aae4c166cd66446b240
---
 tokenize.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
tokenize.c +4 -1
index d68fbcd8eebd..ca842f52882b 100644
@@ -66,7 +66,10 @@ int stream_prev(int stream)
 {
 	if (stream < 0 || stream > input_stream_nr)
 		return -1;
-	return input_streams[stream].pos.stream;
+	stream = input_streams[stream].pos.stream;
+	if (stream > input_stream_nr)
+		return -1;
+	return stream;
 }
 
 static struct position stream_pos(stream_t *stream)
Signature · 1 line
2.28.0