Checker for raw __builtin_memcpy — use FL_BUILTIN_MEMCPY instead.
| 20 | |
| 21 | |
| 22 | class BuiltinMemcpyChecker(FileContentChecker): |
| 23 | """Checker for raw __builtin_memcpy — use FL_BUILTIN_MEMCPY instead.""" |
| 24 | |
| 25 | def __init__(self): |
| 26 | self.violations: dict[str, list[tuple[int, str]]] = {} |
| 27 | |
| 28 | def should_process_file(self, file_path: str) -> bool: |
| 29 | """Check if file should be processed.""" |
| 30 | if not file_path.endswith((".cpp", ".h", ".hpp", ".ino", ".cpp.hpp")): |
| 31 | return False |
| 32 | |
| 33 | # Skip the file that defines FL_BUILTIN_MEMCPY |
| 34 | if file_path.endswith("compiler_control.h"): |
| 35 | return False |
| 36 | |
| 37 | # Skip third-party code |
| 38 | if "/third_party/" in file_path.replace("\\", "/"): |
| 39 | return False |
| 40 | |
| 41 | return True |
| 42 | |
| 43 | def check_file_content(self, file_content: FileContent) -> list[str]: |
| 44 | """Check file content for raw __builtin_memcpy usage.""" |
| 45 | violations: list[tuple[int, str]] = [] |
| 46 | in_multiline_comment = False |
| 47 | |
| 48 | for line_number, line in enumerate(file_content.lines, 1): |
| 49 | stripped = line.strip() |
| 50 | |
| 51 | # Track multi-line comment state |
| 52 | if "/*" in line: |
| 53 | in_multiline_comment = True |
| 54 | if "*/" in line: |
| 55 | in_multiline_comment = False |
| 56 | continue |
| 57 | |
| 58 | if in_multiline_comment: |
| 59 | continue |
| 60 | |
| 61 | if stripped.startswith("//"): |
| 62 | continue |
| 63 | |
| 64 | code_part = line.split("//")[0] |
| 65 | |
| 66 | # Skip #define lines that define the macro wrapper itself |
| 67 | if "#define" in code_part and "FL_BUILTIN_MEMCPY" in code_part: |
| 68 | continue |
| 69 | |
| 70 | # Fast check before regex |
| 71 | if "__builtin_memcpy" not in code_part: |
| 72 | continue |
| 73 | |
| 74 | if BUILTIN_MEMCPY_PATTERN.search(code_part): |
| 75 | violations.append( |
| 76 | ( |
| 77 | line_number, |
| 78 | f"Use FL_BUILTIN_MEMCPY instead of __builtin_memcpy: {stripped}\n" |
| 79 | f" Rationale: FL_BUILTIN_MEMCPY wraps __builtin_memcpy for portability.\n" |
no outgoing calls
no test coverage detected