MCPcopy Create free account
hub / github.com/apache/mesos / CheckPrintf

Function CheckPrintf

support/cpplint.py:4904–4930  ·  view source on GitHub ↗

Check for printf related issues. Args: filename: The name of the current file. clean_lines: A CleansedLines instance containing the file. linenum: The number of the line to check. error: The function to call with any errors found.

(filename, clean_lines, linenum, error)

Source from the content-addressed store, hash-verified

4902
4903
4904def CheckPrintf(filename, clean_lines, linenum, error):
4905 """Check for printf related issues.
4906
4907 Args:
4908 filename: The name of the current file.
4909 clean_lines: A CleansedLines instance containing the file.
4910 linenum: The number of the line to check.
4911 error: The function to call with any errors found.
4912 """
4913 line = clean_lines.elided[linenum]
4914
4915 # When snprintf is used, the second argument shouldn't be a literal.
4916 match = Search(r'snprintf\s*\(([^,]*),\s*([0-9]*)\s*,', line)
4917 if match and match.group(2) != '0':
4918 # If 2nd arg is zero, snprintf is used to calculate size.
4919 error(filename, linenum, 'runtime/printf', 3,
4920 'If you can, use sizeof(%s) instead of %s as the 2nd arg '
4921 'to snprintf.' % (match.group(1), match.group(2)))
4922
4923 # Check if some verboten C functions are being used.
4924 if Search(r'\bsprintf\s*\(', line):
4925 error(filename, linenum, 'runtime/printf', 5,
4926 'Never use sprintf. Use snprintf instead.')
4927 match = Search(r'\b(strcpy|strcat)\s*\(', line)
4928 if match:
4929 error(filename, linenum, 'runtime/printf', 4,
4930 'Almost always, snprintf is better than %s' % match.group(1))
4931
4932
4933def IsDerivedFunction(clean_lines, linenum):

Callers 1

CheckLanguageFunction · 0.85

Calls 2

SearchFunction · 0.85
errorFunction · 0.85

Tested by

no test coverage detected