CodeQL documentation

Wrong number of arguments for format

ID: py/percent-format/wrong-arguments
Kind: problem
Security severity: 
Severity: error
Precision: very-high
Tags:
   - quality
   - reliability
   - correctness
   - external/cwe/cwe-685
Query suites:
   - python-security-and-quality.qls

Click to see the query in the CodeQL repository

A formatting expression, that is an expression of the format fmt % arguments must have the correct number of arguments on the right hand side of the expression. Otherwise, a TypeError will be raised.

Recommendation

Change the format to match the arguments and ensure that the right hand argument always has the correct number of elements.

Example

In the following example the right hand side of the formatting operation can be of length 2, which does not match the format string.

def unsafe_format():
    if unlikely_condition():
        args = (1,2)
    else:
        args = (1, 2, 3)
    return "%s %s %s" % args

References

  • © GitHub, Inc.
  • Terms
  • Privacy
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy