MCPcopy Create free account
hub / github.com/alibaba/GraphScope / CheckPrintf

Function CheckPrintf

analytical_engine/misc/cpplint.py:5448–5474  ·  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

5446
5447
5448def CheckPrintf(filename, clean_lines, linenum, error):
5449 """Check for printf related issues.
5450
5451 Args:
5452 filename: The name of the current file.
5453 clean_lines: A CleansedLines instance containing the file.
5454 linenum: The number of the line to check.
5455 error: The function to call with any errors found.
5456 """
5457 line = clean_lines.elided[linenum]
5458
5459 # When snprintf is used, the second argument shouldn't be a literal.
5460 match = Search(r'snprintf\s*\(([^,]*),\s*([0-9]*)\s*,', line)
5461 if match and match.group(2) != '0':
5462 # If 2nd arg is zero, snprintf is used to calculate size.
5463 error(filename, linenum, 'runtime/printf', 3,
5464 'If you can, use sizeof(%s) instead of %s as the 2nd arg '
5465 'to snprintf.' % (match.group(1), match.group(2)))
5466
5467 # Check if some verboten C functions are being used.
5468 if Search(r'\bsprintf\s*\(', line):
5469 error(filename, linenum, 'runtime/printf', 5,
5470 'Never use sprintf. Use snprintf instead.')
5471 match = Search(r'\b(strcpy|strcat)\s*\(', line)
5472 if match:
5473 error(filename, linenum, 'runtime/printf', 4,
5474 'Almost always, snprintf is better than %s' % match.group(1))
5475
5476
5477def IsDerivedFunction(clean_lines, linenum):

Callers 1

CheckLanguageFunction · 0.85

Calls 2

SearchFunction · 0.85
groupMethod · 0.45

Tested by

no test coverage detected