MCPcopy Create free account
hub / github.com/dmtcp/dmtcp / CheckPrintf

Function CheckPrintf

util/cpplint.py:4826–4852  ·  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

4824
4825
4826def CheckPrintf(filename, clean_lines, linenum, error):
4827 """Check for printf related issues.
4828
4829 Args:
4830 filename: The name of the current file.
4831 clean_lines: A CleansedLines instance containing the file.
4832 linenum: The number of the line to check.
4833 error: The function to call with any errors found.
4834 """
4835 line = clean_lines.elided[linenum]
4836
4837 # When snprintf is used, the second argument shouldn't be a literal.
4838 match = Search(r'snprintf\s*\(([^,]*),\s*([0-9]*)\s*,', line)
4839 if match and match.group(2) != '0':
4840 # If 2nd arg is zero, snprintf is used to calculate size.
4841 error(filename, linenum, 'runtime/printf', 3,
4842 'If you can, use sizeof(%s) instead of %s as the 2nd arg '
4843 'to snprintf.' % (match.group(1), match.group(2)))
4844
4845 # Check if some verboten C functions are being used.
4846 if Search(r'\bsprintf\s*\(', line):
4847 error(filename, linenum, 'runtime/printf', 5,
4848 'Never use sprintf. Use snprintf instead.')
4849 match = Search(r'\b(strcpy|strcat)\s*\(', line)
4850 if match:
4851 error(filename, linenum, 'runtime/printf', 4,
4852 'Almost always, snprintf is better than %s' % match.group(1))
4853
4854
4855def IsDerivedFunction(clean_lines, linenum):

Callers 1

CheckLanguageFunction · 0.85

Calls 2

SearchFunction · 0.85
errorFunction · 0.85

Tested by

no test coverage detected