Checks for invalid increment *count++. For example following function: void increment_counter(int* count) { *count++; } is invalid, because it effectively does count++, moving pointer, and should be replaced with ++*count, (*count)++ or *count += 1. Args: filename: The name of
(filename, clean_lines, linenum, error)
| 1735 | |
| 1736 | |
| 1737 | def CheckInvalidIncrement(filename, clean_lines, linenum, error): |
| 1738 | """Checks for invalid increment *count++. |
| 1739 | |
| 1740 | For example following function: |
| 1741 | void increment_counter(int* count) { |
| 1742 | *count++; |
| 1743 | } |
| 1744 | is invalid, because it effectively does count++, moving pointer, and should |
| 1745 | be replaced with ++*count, (*count)++ or *count += 1. |
| 1746 | |
| 1747 | Args: |
| 1748 | filename: The name of the current file. |
| 1749 | clean_lines: A CleansedLines instance containing the file. |
| 1750 | linenum: The number of the line to check. |
| 1751 | error: The function to call with any errors found. |
| 1752 | """ |
| 1753 | line = clean_lines.elided[linenum] |
| 1754 | if _RE_PATTERN_INVALID_INCREMENT.match(line): |
| 1755 | error(filename, linenum, 'runtime/invalid_increment', 5, |
| 1756 | 'Changing pointer instead of value (or unused value of operator*).') |
| 1757 | |
| 1758 | |
| 1759 | class _BlockInfo(object): |