[PATCH 02/38] docs: kdoc_re: don't go past the end of a line

From: Mauro Carvalho Chehab

Date: Wed Feb 18 2026 - 05:13:33 EST


The logic which checks if the line ends with ";" is currently
broken: it may try to read past the buffer.

Fix it by checking before trying to access line[pos].

Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@xxxxxxxxxx>
Acked-by: Randy Dunlap <rdunlap@xxxxxxxxxxxxx>
Tested-by: Randy Dunlap <rdunlap@xxxxxxxxxxxxx>
Reviewed-by: Aleksandr Loktionov <aleksandr.loktionov@xxxxxxxxx>
---
tools/lib/python/kdoc/kdoc_re.py | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tools/lib/python/kdoc/kdoc_re.py b/tools/lib/python/kdoc/kdoc_re.py
index 774dd747ecb0..6c44fcce0415 100644
--- a/tools/lib/python/kdoc/kdoc_re.py
+++ b/tools/lib/python/kdoc/kdoc_re.py
@@ -269,7 +269,7 @@ class NestedMatch:
out += new_sub

# Drop end ';' if any
- if line[pos] == ';':
+ if pos < len(line) and line[pos] == ';':
pos += 1

cur_pos = pos
--
2.52.0