MCPcopy Index your code
hub / github.com/nodejs/node / CheckPrintf

Function CheckPrintf

tools/cpplint.py:6339–6375  ·  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

6337
6338
6339def CheckPrintf(filename, clean_lines, linenum, error):
6340 """Check for printf related issues.
6341
6342 Args:
6343 filename: The name of the current file.
6344 clean_lines: A CleansedLines instance containing the file.
6345 linenum: The number of the line to check.
6346 error: The function to call with any errors found.
6347 """
6348 line = clean_lines.elided[linenum]
6349
6350 # When snprintf is used, the second argument shouldn't be a literal.
6351 match = re.search(r"snprintf\s*\(([^,]*),\s*([0-9]*)\s*,", line)
6352 if match and match.group(2) != "0":
6353 # If 2nd arg is zero, snprintf is used to calculate size.
6354 error(
6355 filename,
6356 linenum,
6357 "runtime/printf",
6358 3,
6359 "If you can, use"
6360 f" sizeof({match.group(1)}) instead of {match.group(2)}"
6361 " as the 2nd arg to snprintf.",
6362 )
6363
6364 # Check if some verboten C functions are being used.
6365 if re.search(r"\bsprintf\s*\(", line):
6366 error(filename, linenum, "runtime/printf", 5, "Never use sprintf. Use snprintf instead.")
6367 match = re.search(r"\b(strcpy|strcat)\s*\(", line)
6368 if match:
6369 error(
6370 filename,
6371 linenum,
6372 "runtime/printf",
6373 4,
6374 f"Almost always, snprintf is better than {match.group(1)}",
6375 )
6376
6377
6378def IsDerivedFunction(clean_lines, linenum):

Callers 1

CheckLanguageFunction · 0.85

Calls 2

errorFunction · 0.50
searchMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…