Skip to content

Commit b5acb2a

Browse files
committed
Address faulty identification of closing #endif for guard annotation
1 parent 0f6bbc5 commit b5acb2a

1 file changed

Lines changed: 8 additions & 5 deletions

File tree

scripts/fix_header_guards.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,11 @@ def check_header_guard(file_path: Path, root: Path) -> tuple[bool, str | None]:
3838
define_idx, define_macro = i, m.group(1)
3939
break
4040

41-
for i in range(len(lines) - 1, max(len(lines) - 10, -1), -1):
42-
if m := re.match(r"#endif\s*//\s*(\w+)\s*$", lines[i]):
43-
endif_macro = m.group(1)
41+
for i in range(len(lines) - 1, -1, -1):
42+
line = lines[i].strip()
43+
if line.startswith("#endif"):
44+
if m := re.match(r"#endif\s*//\s*(\w+)\s*$", lines[i]):
45+
endif_macro = m.group(1)
4446
break
4547

4648
if ifndef_idx is None or define_idx is None:
@@ -71,8 +73,9 @@ def fix_header_guard(file_path: Path, root: Path) -> bool:
7173
define_idx = i
7274
break
7375

74-
for i in range(len(lines) - 1, max(len(lines) - 10, -1), -1):
75-
if re.match(r"#endif\s*//\s*\w+\s*$", lines[i]):
76+
for i in range(len(lines) - 1, -1, -1):
77+
line = lines[i].strip()
78+
if line.startswith("#endif"):
7679
endif_idx = i
7780
break
7881

0 commit comments

Comments
 (0)