@@ 5059-5085 (lines=27) @@ | ||
5056 | 'You seem to be initializing a member variable with itself.') |
|
5057 | ||
5058 | ||
5059 | def CheckPrintf(filename, clean_lines, linenum, error): |
|
5060 | """Check for printf related issues. |
|
5061 | ||
5062 | Args: |
|
5063 | filename: The name of the current file. |
|
5064 | clean_lines: A CleansedLines instance containing the file. |
|
5065 | linenum: The number of the line to check. |
|
5066 | error: The function to call with any errors found. |
|
5067 | """ |
|
5068 | line = clean_lines.elided[linenum] |
|
5069 | ||
5070 | # When snprintf is used, the second argument shouldn't be a literal. |
|
5071 | match = Search(r'snprintf\s*\(([^,]*),\s*([0-9]*)\s*,', line) |
|
5072 | if match and match.group(2) != '0': |
|
5073 | # If 2nd arg is zero, snprintf is used to calculate size. |
|
5074 | error(filename, linenum, 'runtime/printf', 3, |
|
5075 | 'If you can, use sizeof(%s) instead of %s as the 2nd arg ' |
|
5076 | 'to snprintf.' % (match.group(1), match.group(2))) |
|
5077 | ||
5078 | # Check if some verboten C functions are being used. |
|
5079 | if Search(r'\bsprintf\s*\(', line): |
|
5080 | error(filename, linenum, 'runtime/printf', 5, |
|
5081 | 'Never use sprintf. Use snprintf instead.') |
|
5082 | match = Search(r'\b(strcpy|strcat)\s*\(', line) |
|
5083 | if match: |
|
5084 | error(filename, linenum, 'runtime/printf', 4, |
|
5085 | 'Almost always, snprintf is better than %s' % match.group(1)) |
|
5086 | ||
5087 | ||
5088 | def IsDerivedFunction(clean_lines, linenum): |
@@ 5059-5085 (lines=27) @@ | ||
5056 | 'You seem to be initializing a member variable with itself.') |
|
5057 | ||
5058 | ||
5059 | def CheckPrintf(filename, clean_lines, linenum, error): |
|
5060 | """Check for printf related issues. |
|
5061 | ||
5062 | Args: |
|
5063 | filename: The name of the current file. |
|
5064 | clean_lines: A CleansedLines instance containing the file. |
|
5065 | linenum: The number of the line to check. |
|
5066 | error: The function to call with any errors found. |
|
5067 | """ |
|
5068 | line = clean_lines.elided[linenum] |
|
5069 | ||
5070 | # When snprintf is used, the second argument shouldn't be a literal. |
|
5071 | match = Search(r'snprintf\s*\(([^,]*),\s*([0-9]*)\s*,', line) |
|
5072 | if match and match.group(2) != '0': |
|
5073 | # If 2nd arg is zero, snprintf is used to calculate size. |
|
5074 | error(filename, linenum, 'runtime/printf', 3, |
|
5075 | 'If you can, use sizeof(%s) instead of %s as the 2nd arg ' |
|
5076 | 'to snprintf.' % (match.group(1), match.group(2))) |
|
5077 | ||
5078 | # Check if some verboten C functions are being used. |
|
5079 | if Search(r'\bsprintf\s*\(', line): |
|
5080 | error(filename, linenum, 'runtime/printf', 5, |
|
5081 | 'Never use sprintf. Use snprintf instead.') |
|
5082 | match = Search(r'\b(strcpy|strcat)\s*\(', line) |
|
5083 | if match: |
|
5084 | error(filename, linenum, 'runtime/printf', 4, |
|
5085 | 'Almost always, snprintf is better than %s' % match.group(1)) |
|
5086 | ||
5087 | ||
5088 | def IsDerivedFunction(clean_lines, linenum): |