class warning

A warning instance.

  • Returned by warningclass report_return_warning() method (many overloads).
  • Use to manually retract the warning, if necessary, during the drop phase of incremental analyses. You will only need to manually retract warnings if automatic retraction (managed by passing a warning_retraction_info argument to warningclass report_return_warning() or report()) does not provide sufficient flexibility.

See the manual section on Warnings: Instances and Groups for more information about warning instances.

warning Details

class cs.warning

A warning instance.

__init__(serialized)

Constructor.

Parameters:serialized (str) – A serialized warning instance, as produced by warning.serialize().
Raises:result.ERROR_INVALID_ARGUMENT
>>> wc = analysis.create_warningclass('Suspicious Point')
>>> try:
...    w = wc.report_return_warning(project.current().procedures_vector()[2].entry_point(), 'I do not trust this point')
... except result as r:
...    print('problem reporting warning', r)
...    w = None
...
Rendering `Suspicious Point' Warning... done
Reporting `Suspicious Point' Warning at C:\alex\test\apitest.cpp:9
>>> s = w.serialize()
>>> wc2 = warning(s)
>>> wc2
<cs.warning ...>
__hash__()

Get a hash value for a warning .

Return type:int
>>> wc = analysis.create_warningclass('Suspicious Point')
>>> try:
...    w = wc.report_return_warning(project.current().procedures_vector()[2].entry_point(), 'I do not trust this point')
... except result as r:
...    print('problem reporting warning', r)
...    w = None
...
Rendering `Suspicious Point' Warning... done
Reporting `Suspicious Point' Warning at C:\alex\test\apitest.cpp:9
>>> hash(w)
268435454
__repr__()

Get a representation of a warning object that includes information useful for debugging.

Return type:str
Returns:The string representation.
>>> wc = analysis.create_warningclass('Suspicious Point')
>>> try:
...    w = wc.report_return_warning(project.current().procedures_vector()[2].entry_point(), 'I do not trust this point')
... except result as r:
...    print('problem reporting warning', r)
...    w = None
...
Rendering `Suspicious Point' Warning... done
Reporting `Suspicious Point' Warning at C:\alex\test\apitest.cpp:9
>>> repr(w)
'<cs.warning ...>'
__str__()

Get a simple string representation of a warning object.

Return type:str
Returns:The string representation.
>>> wc = analysis.create_warningclass('Suspicious Point')
>>> try:
...    w = wc.report_return_warning(project.current().procedures_vector()[2].entry_point(), 'I do not trust this point')
... except result as r:
...    print('problem reporting warning', r)
...    w = None
...
Rendering `Suspicious Point' Warning... done
Reporting `Suspicious Point' Warning at C:\alex\test\apitest.cpp:9
>>> str(w)
'<cs.warning ...>'
retract()

Manually retract a warning instance.

Return type:NoneType
Raises:result.ELEMENT_NOT_PRESENT

Call this method in a drop phase visitor (see Visitor Decorators) to manually retract a warning instance. Support for calling this function from visitors in other analysis phases is experimental and may be removed in future versions.

>>> # perform in drop visitor
>>> wc = analysis.create_warningclass('Suspicious Point')
>>> try:
...    w1 = wc.report_return_warning(project.current().procedures_vector()[2].entry_point(),
...                                  'I do not trust this point and will continue not to trust it')
...    w2 = wc.report_return_warning(project.current().procedures_vector()[2].entry_point().solitary_cfg_target(),
...                                  'I do not trust this point but will change my mind')
... except result as r:
...    print('problem reporting warning', r)
...    (w1,w2) = (None,None)
...
Rendering `Suspicious Point' Warning... done
Reporting `Suspicious Point' Warning at C:\alex\test\apitest.cpp:9
Rendering `Suspicious Point' Warning... done
Reporting `Suspicious Point' Warning at C:\alex\test\apitest.cpp:11
>>> if w2 is not None:
...    w2.retract()
...
serialize()

Serialize a warning instance.

Return type:str
Returns:The serialized form of the warning instance.
>>> wc = analysis.create_warningclass('Suspicious Point')
>>> try:
...    w = wc.report_return_warning(project.current().procedures_vector()[2].entry_point(), 'I do not trust this point')
... except result as r:
...    print('problem reporting warning', r)
...    w = None
...
Rendering `Suspicious Point' Warning... done
Reporting `Suspicious Point' Warning at C:\alex\test\apitest.cpp:9
>>> w.serialize()
'3 -6 268435457'