class warningclass

A warning class.

Use analysis.create_warningclass() to create new warningclass objects.

Report a warning with report() (which returns a result ) or report_return_warning() (which returns the reported warning object). Both forms provide the option of specifying retraction information.

  • Use the report_flags argument to these methods to characterize the resulting warning report.
  • Always invoke report_return_warning() methods inside a try block.
Warnings can be reported… report() and report_return_warning()
at a point first argument is a point
with a path first argument is a list of cfg_path_node
with a step path first argument is a step_path
at a code location first three arguments are sfileinst , int, str
with a list of code locations first argument is a list of locations_node
at a line in a specified procedure first three arguments are sfileinst , int, procedure
at a code span in a specified procedure and file instance first six arguments are sfileinst , int, int, int, int, procedure
at a code span in a specified file instance first five arguments are sfileinst , int, int, int, int
with a list of code locations in a procedure first two arguments are list of locations_node , procedure
associated with a file instance first argument is sfileinst
with no association to a file or procedure there are no location arguments

warningclass Details

class cs.warningclass

A warning class.

__init__(other)

Copy constructor.

Parameters:other (warningclass) – The warningclass object to copy.

This copy constructor is provided so that it can be used underlyingly at function calls when warningclass parameters are specified or warningclass return values are assigned. It is unlikely that you will need to call it directly.

>>> # copy constructor underlyingly used in assigning warningclass return value
>>> myclass = analysis.lookup_warningclass('Buffer Underrun')
>>> myclass
<cs.warningclass Buffer Underrun>
__cmp__(other)

Comparison function for warningclass .

Parameters:other (warningclass) – The warningclass object to compare against.
Return type:int
Returns:An integer N, such that:
  • N<0 if self < other
  • N==0 if self == other
  • N>0 if self > other
>>> wc1 = analysis.lookup_warningclass('Buffer Underrun')
>>> wc2 = analysis.lookup_warningclass('Type Underrun')
>>> wc1.__cmp__( wc2)
-1
__eq__(b)

Equality operator for warningclass.

Parameters:b (warningclass) – The warningclass object to compare against.
Return type:bool
Returns:True if self and b compare equal, False otherwise.
>>> wc1 = analysis.lookup_warningclass('Buffer Underrun')
>>> wc2 = analysis.lookup_warningclass('Type Underrun')
>>> wc1 == wc2
False
__ge__(b)

Greater-than-or-equal operator for warningclass.

Parameters:b (warningclass) –
Return type:bool
Returns:True if self >= b , False otherwise.
>>> wc1 = analysis.lookup_warningclass('Buffer Underrun')
>>> wc2 = analysis.lookup_warningclass('Type Underrun')
>>> wc1 >= wc2
False
__gt__(b)

Greater-than operator for warningclass.

Parameters:b (warningclass) –
Return type:bool
Returns:True if self > b , False otherwise.
>>> wc1 = analysis.lookup_warningclass('Buffer Underrun')
>>> wc2 = analysis.lookup_warningclass('Type Underrun')
>>> wc1 > wc2
False
__hash__()

Hash function for warningclass .

Return type:int
Returns:A hash of the warning class.
>>> wc1 = analysis.lookup_warningclass('Buffer Underrun')
>>> hash(wc1)
1105021962
__le__(b)

Less-than-or-equal operator for warningclass.

Parameters:b (warningclass) –
Return type:bool
Returns:True if self <= b , False otherwise.
>>> wc1 = analysis.lookup_warningclass('Buffer Underrun')
>>> wc2 = analysis.lookup_warningclass('Type Underrun')
>>> wc1 <= wc2
True
__lt__(b)

Less-than operator for warningclass.

Parameters:b (warningclass) –
Return type:bool
Returns:True if self < b , False otherwise.
>>> wc1 = analysis.lookup_warningclass('Buffer Underrun')
>>> wc2 = analysis.lookup_warningclass('Type Underrun')
>>> wc1 < wc2
True
__ne__(b)

Inequality operator for warningclass.

Parameters:b (warningclass) –
Return type:bool
Returns:False if self and b compare equal, True otherwise.
>>> wc1 = analysis.lookup_warningclass('Buffer Underrun')
>>> wc2 = analysis.lookup_warningclass('Type Underrun')
>>> wc1 != wc2
True
__repr__()

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

Return type:str
Returns:The string representation.
>>> wc1 = analysis.lookup_warningclass('Buffer Underrun')
>>> repr(wc1)
'<cs.warningclass Buffer Underrun>'
__str__()

Get a simple string representation of a warningclass object.

Return type:str
Returns:The string representation.
>>> wc1 = analysis.lookup_warningclass('Buffer Underrun')
>>> str(wc1)
'Buffer Underrun'
allowed()

Check: are WARNING_FILTER settings such that reported instances of this warning class will be submitted to the hub?

Return type:bool
Returns:True if reported instances of the class will be submitted to the hub, False otherwise.

If you have defined a custom warning class C in a plug-in, you can use a test based on C.allowed() to avoid unnecessary work in the case where C is ignored.

This is the complement of warningclass.always_discarded().

>>> wc1 = analysis.lookup_warningclass('Buffer Underrun')
>>> wc1.allowed()
True
always_discarded()

Check: are WARNING_FILTER settings such that instances of this warning class will always be ignored?

Return type:bool
Returns:True if all instances of the class are being discarded, False otherwise.

If you have defined a custom warning class C in a plug-in, you can use a test based on C.always_discarded() to avoid unnecessary work in the case where C is ignored.

This is the complement of warningclass.allowed().

>>> wc1 = analysis.lookup_warningclass('Buffer Underrun')
>>> wc1.always_discarded()
False
get_id()

Get the ID of a warning class.

Return type:int
Returns:The ID of the warning class.

To get a warningclass given its ID, use analysis.lookup_warningclass(). Note that a single warning class may have different ID values in different analyses.

>>> wc1 = analysis.lookup_warningclass('Buffer Underrun')
>>> wc1.get_id()
39
name()

Get the name of a warning class.

Return type:str
Returns:The warning class name.
>>> wc1 = analysis.lookup_warningclass(39)
>>> wc1.name()
'Buffer Underrun'
report(endbox[, flags =  report_flags.NONE])

Report a warning with no association to a file or procedure.

Parameters:
  • endbox (str) – A short explanation of why the warning has been issued.
  • flags (report_flags) – (optional) report_flags that characterize the report.
Return type:

result

Returns:

A result , as follows:

  • result.SUCCESS if the warning was successfully queued for submission to the hub.
  • result.FILTERED_OUT if the warning was not submitted to the hub because it matched a WARNING_FILTER discard rule in the configuration file.
  • result.TIMEOUT if the time limit specified by configuration file option TIME_LIMIT_RENDER expired.
  • result.ELEMENT_ALREADY_PRESENT if the warning was not submitted to the hub because configuration file option REPORT_SIMILAR_WARNINGS is set to No and a similar warning was previously submitted.

Raises:

The warning will be always be automatically retracted during an incremental build, since the warning is against the entire analysis.

There are multiple methods for reporting a warning with no association to a file or procedure. See the table above for details.

>>> wc_projname = analysis.create_warningclass('Project is called "apitest"')
>>> if project.current().name().lower() == 'apitest':
...    wc_projname.report('''The project's (case-insensitive) name is "apitest".
...        This isn't a problem, just an example of a warning with no association to a file or procedure.''',
...        report_flags.NONE)
...
Rendering `Project is called "apitest"' Warning... done
Reporting `Project is called "apitest"' Warning for analysis
<cs.result SUCCESS>
>>> wc_projname = analysis.create_warningclass('Project is called "apitest"')
>>> if project.current().name().lower() == 'apitest':
...    wc_projname.report('''The project's (case-insensitive) name is "apitest".
...        This isn't a problem, just an example of a warning with no association to a file or procedure.''')
...
Rendering `Project is called "apitest"' Warning... done
Reporting `Project is called "apitest"' Warning for analysis
<cs.result SUCCESS>
report(p)

Report a warning with a path.

Parameters:

p (iterable of cfg_path_node) – The path associated with the warning, with each point on the path described by a cfg_path_node .

Return type:

result

Returns:

A result , as follows:

  • result.SUCCESS if the warning was successfully queued for submission to the hub.
  • result.FILTERED_OUT if the warning was not submitted to the hub because it matched a WARNING_FILTER discard rule in the configuration file.
  • result.TIMEOUT if the time limit specified by configuration file option TIME_LIMIT_RENDER expired.
  • result.NO_SOURCE_CORRESPONDENCE if the warning was not submitted to the hub because no source location for the warning could be determined.
  • result.ELEMENT_ALREADY_PRESENT if the warning was not submitted to the hub because configuration file option REPORT_SIMILAR_WARNINGS is set to No and a similar warning was previously submitted.

Raises:

The warning will be automatically retracted in a subsequent incremental analysis if and only if the compunit containing the first point in p has been modified.

There are multiple methods for reporting a warning with a path. See the table above for details.

>>> wc = analysis.create_warningclass('mymalloc() called after bar()')
>>> def paths_to_pts(currpt, endpts):
...     if currpt.get_kind()==point_kind.EXIT:
...        return []
...     return [[cfg_path_node(targ[0],targ[1],'',cfg_path_node_flags.NONE)] + path                     # intermediate point
...               for targ in currpt.cfg_targets() if targ[0] not in endpts
...               for path in paths_to_pts(targ[0], endpts)]\
...            + [[cfg_path_node(targ[0], targ[1], 'Call to mymalloc()', cfg_path_node_flags.ENDBOX)]   # end point
...               for targ in currpt.cfg_targets() if targ[0] in endpts ]
...
>>> def find_bar_mm_paths(proc):
...     callsites = list(proc.call_sites())
...     bar_calls = [c for c in callsites if c.callee().name()=='bar']
...     mymalloc_calls = [c for c in callsites if c.callee().name()=='mymalloc']
...     if not (callsites and bar_calls and mymalloc_calls):
...        return []
...     return [[cfg_path_node(targ[0], targ[1], 'Call to bar()', cfg_path_node_flags.PRIMARY)] + cfgpath  # start point
...              for s in bar_calls
...              for targ in s.cfg_targets()
...          for cfgpath in paths_to_pts(targ[0], mymalloc_calls)]
...
>>> for cfgpath in find_bar_mm_paths(project.current().find_procedure('foo')):
...    wc.report(cfgpath)
...
Rendering `mymalloc() called after bar()' Warning... done
Reporting `mymalloc() called after bar()' Warning at C:\alex\test\apitest.cpp:37
<cs.result SUCCESS>
Rendering `mymalloc() called after bar()' Warning... done
Reporting `mymalloc() called after bar()' Warning at C:\alex\test\apitest.cpp:37
<cs.result SUCCESS>
report(p, ri)

Report a warning with a path, providing retraction information.

Parameters:
Return type:

result

Returns:

A result , as follows:

  • result.SUCCESS if the warning was successfully queued for submission to the hub.
  • result.FILTERED_OUT if the warning was not submitted to the hub because it matched a WARNING_FILTER discard rule in the configuration file.
  • result.TIMEOUT if the time limit specified by configuration file option TIME_LIMIT_RENDER expired.
  • result.NO_SOURCE_CORRESPONDENCE if the warning was not submitted to the hub because no source location for the warning could be determined.
  • result.ELEMENT_ALREADY_PRESENT if the warning was not submitted to the hub because configuration file option REPORT_SIMILAR_WARNINGS is set to No and a similar warning was previously submitted.

Raises:

The warning will be automatically retracted in a subsequent incremental analysis if and only if one or more of the conditions expressed in ri is satisfied.

>>> wc = analysis.create_warningclass('mymalloc() called after bar()')
>>> def paths_to_pts(currpt, endpts):
...     if currpt.get_kind()==point_kind.EXIT:
...        return []
...     return [[cfg_path_node(targ[0],targ[1],'',cfg_path_node_flags.NONE)] + path                     # intermediate point
...               for targ in currpt.cfg_targets() if targ[0] not in endpts
...               for path in paths_to_pts(targ[0], endpts)]\
...            + [[cfg_path_node(targ[0], targ[1], 'Call to mymalloc()', cfg_path_node_flags.ENDBOX)]   # end point
...               for targ in currpt.cfg_targets() if targ[0] in endpts ]
...
>>> def find_bar_mm_paths(proc):
...     callsites = list(proc.call_sites())
...     bar_calls = [c for c in callsites if c.callee().name()=='bar']
...     mymalloc_calls = [c for c in callsites if c.callee().name()=='mymalloc']
...     if not (callsites and bar_calls and mymalloc_calls):
...        return []
...     return [[cfg_path_node(targ[0], targ[1], 'Call to bar()', cfg_path_node_flags.PRIMARY)] + cfgpath  # start point
...              for s in bar_calls
...              for targ in s.cfg_targets()
...          for cfgpath in paths_to_pts(targ[0], mymalloc_calls)]
...
>>> foofn = project.current().find_procedure('foo')
>>> for cfgpath in find_bar_mm_paths(foofn):
...    wc.report(cfgpath, warning_retraction_info([],[foofn],[]))
...
Rendering `mymalloc() called after bar()' Warning... done
Reporting `mymalloc() called after bar()' Warning at C:\alex\test\apitest.cpp:37
<cs.result SUCCESS>
Rendering `mymalloc() called after bar()' Warning... done
Reporting `mymalloc() called after bar()' Warning at C:\alex\test\apitest.cpp:37
<cs.result SUCCESS>
report(p)

Report a warning with a list of code locations.

Parameters:

p (iterable of locations_node) – The list of code locations ( locations_node ) associated with the warning.

Return type:

result

Returns:

A result , as follows:

  • result.SUCCESS if the warning was successfully queued for submission to the hub.
  • result.FILTERED_OUT if the warning was not submitted to the hub because it matched a WARNING_FILTER discard rule in the configuration file.
  • result.TIMEOUT if the time limit specified by configuration file option TIME_LIMIT_RENDER expired.
  • result.NO_SOURCE_CORRESPONDENCE if the warning was not submitted to the hub because no source location for the warning could be determined.
  • result.ELEMENT_ALREADY_PRESENT if the warning was not submitted to the hub because configuration file option REPORT_SIMILAR_WARNINGS is set to No and a similar warning was previously submitted.

Raises:

The warning will be automatically retracted in a subsequent incremental analysis if and only if the compunit containing the first location in p has been modified.

There are multiple methods for reporting a warning with a list of code locations. See the table above for details.

>>> # The built in 'Recursion' warning class provides more complete checking than this example.
>>> wc = analysis.create_warningclass('One or more calls to recursive function "bar"')
>>> barfn = project.current().find_procedure('bar(int, void *, int)')
>>> if barfn.callers_count() > 0:
...     warning_locations = [locations_node(entry_loc[0], entry_loc[1], '"bar" entry point.', locations_node_flags.ENDBOX)]
...     for c in barfn.callers():
...         call_loc = c.file_line()
...         warning_locations.append(locations_node(call_loc[0], call_loc[1], 'Call to "bar"', locations_node_flags.PRIMARY))
...     wc.report(warning_locations)
...
Rendering `One or more calls to recursive function "bar"' Warning... done
Reporting `One or more calls to recursive function "bar"' Warning at C:\alex\test\apitest.cpp:9
<cs.result SUCCESS>
report(p, ri)

Report a warning with a list of code locations, providing retraction information.

Parameters:
Return type:

result

Returns:

A result , as follows:

  • result.SUCCESS if the warning was successfully queued for submission to the hub.
  • result.FILTERED_OUT if the warning was not submitted to the hub because it matched a WARNING_FILTER discard rule in the configuration file.
  • result.TIMEOUT if the time limit specified by configuration file option TIME_LIMIT_RENDER expired.
  • result.NO_SOURCE_CORRESPONDENCE if the warning was not submitted to the hub because no source location for the warning could be determined.
  • result.ELEMENT_ALREADY_PRESENT if the warning was not submitted to the hub because configuration file option REPORT_SIMILAR_WARNINGS is set to No and a similar warning was previously submitted.

Raises:

The warning will be automatically retracted in a subsequent incremental analysis if and only if one or more of the conditions expressed in ri is satisfied.

There are multiple methods for reporting a warning with a list of code locations. See the table above for details.

>>> # The built in 'Recursion' warning class provides more complete checking than this example.
>>> wc = analysis.create_warningclass('One or more calls to recursive function "bar"')
>>> barfn = project.current().find_procedure('bar(int, void *, int)')
>>> if barfn.callers_count() > 0:
...     caller_set = set([])
...     warning_locations = [locations_node(entry_loc[0], entry_loc[1], '"bar" entry point.', locations_node_flags.ENDBOX)]
...     for c in barfn.callers():
...         caller_set.add(c.get_procedure())
...         call_loc = c.file_line()
...         warning_locations.append(locations_node(call_loc[0], call_loc[1], 'Call to "bar"', locations_node_flags.PRIMARY))
...     wc.report(warning_locations, warning_retraction_info([], list(caller_set), []))
...
Rendering `One or more calls to recursive function "bar"' Warning... done
Reporting `One or more calls to recursive function "bar"' Warning at C:\alex\test\apitest.cpp:9
<cs.result SUCCESS>
report(p, proc)

Report a warning with a list of code locations in a specified procedure.

Parameters:
Return type:

result

Returns:

A result , as follows:

  • result.SUCCESS if the warning was successfully queued for submission to the hub.
  • result.FILTERED_OUT if the warning was not submitted to the hub because it matched a WARNING_FILTER discard rule in the configuration file.
  • result.TIMEOUT if the time limit specified by configuration file option TIME_LIMIT_RENDER expired.
  • result.NO_SOURCE_CORRESPONDENCE if the warning was not submitted to the hub because no source location for the warning could be determined.
  • result.ELEMENT_ALREADY_PRESENT if the warning was not submitted to the hub because configuration file option REPORT_SIMILAR_WARNINGS is set to No and a similar warning was previously submitted.

Raises:

The warning will be automatically retracted in a subsequent incremental analysis if and only if the compunit containing the first location in p has been modified.

There are multiple methods for reporting a warning with a list of code locations in a specified procedure. See the table above for details.

>>> # The built in 'Recursion' warning class provides more complete checking than this example.
>>> wc = analysis.create_warningclass('Function "bar" calls itself')
>>> barfn = project.current().find_procedure('bar(int, void *, int)')
>>> self_calls = [pt for pt in barfn.call_sites_vector() if pt.callee()==barfn]
>>> if self_calls:
...     entry_loc = barfn.entry_point().file_line()
...     warning_locations = [locations_node(entry_loc[0], entry_loc[1], '"bar" entry point.', locations_node_flags.ENDBOX)]
...     for c in self_calls:
...         call_loc = c.file_line()
...         warning_locations.append(locations_node(call_loc[0], call_loc[1], 'Call to "bar"', locations_node_flags.PRIMARY))
...     wc.report(warning_locations, barfn)
...
Rendering `Function "bar" calls itself' Warning... done
Reporting `Function "bar" calls itself' Warning at C:\alex\test\apitest.cpp:9
<cs.result SUCCESS>
report(p, proc, ri)

Report a warning with a list of code locations in a specified procedure, providing retraction information.

Parameters:
Return type:

result

Returns:

A result , as follows:

  • result.SUCCESS if the warning was successfully queued for submission to the hub.
  • result.FILTERED_OUT if the warning was not submitted to the hub because it matched a WARNING_FILTER discard rule in the configuration file.
  • result.TIMEOUT if the time limit specified by configuration file option TIME_LIMIT_RENDER expired.
  • result.NO_SOURCE_CORRESPONDENCE if the warning was not submitted to the hub because no source location for the warning could be determined.
  • result.ELEMENT_ALREADY_PRESENT if the warning was not submitted to the hub because configuration file option REPORT_SIMILAR_WARNINGS is set to No and a similar warning was previously submitted.

Raises:

The warning will be automatically retracted in a subsequent incremental analysis if and only if one or more of the conditions expressed in ri is satisfied.

There are multiple methods for reporting a warning with a list of code locations in a specified procedure. See the table above for details.

>>> # The built in 'Recursion' warning class provides more complete checking than this example.
>>> wc = analysis.create_warningclass('Function "bar" calls itself')
>>> barfn = project.current().find_procedure('bar(int, void *, int)')
>>> self_calls = [pt for pt in barfn.call_sites_vector() if pt.callee()==barfn]
>>> if self_calls:
...     entry_loc = barfn.entry_point().file_line()
...     warning_locations = [locations_node(entry_loc[0], entry_loc[1], '"bar" entry point.', locations_node_flags.ENDBOX)]
...     for c in self_calls:
...         call_loc = c.file_line()
...         warning_locations.append(locations_node(call_loc[0], call_loc[1], 'Call to "bar"', locations_node_flags.PRIMARY))
...     wc.report(warning_locations, barfn, warning_retraction_info([], [barfn],[]))
...
Rendering `Function "bar" calls itself' Warning... done
Reporting `Function "bar" calls itself' Warning at C:\alex\test\apitest.cpp:9
<cs.result SUCCESS>
report(p, endbox, flags, ri)

Report a warning at a point , providing retraction information.

Parameters:
Return type:

result

Returns:

A result , as follows:

  • result.SUCCESS if the warning was successfully queued for submission to the hub.
  • result.FILTERED_OUT if the warning was not submitted to the hub because it matched a WARNING_FILTER discard rule in the configuration file.
  • result.TIMEOUT if the time limit specified by configuration file option TIME_LIMIT_RENDER expired.
  • result.NO_SOURCE_CORRESPONDENCE if the warning was not submitted to the hub because no source location for the warning could be determined.
  • result.ELEMENT_ALREADY_PRESENT if the warning was not submitted to the hub because configuration file option REPORT_SIMILAR_WARNINGS is set to No and a similar warning was previously submitted.

Raises:

result.ERROR_INVALID_PHASE_FOR_OPERATION if called from a drop visitor, or your plug-in’s top-level scope.

This creates a single-event warning where the event is an end box.

The warning will be automatically retracted in a subsequent incremental analysis if and only if one or more of the conditions expressed in ri is satisfied.

There are multiple methods for reporting a warning at a point. See the table above for details.

>>> wc_undeffunc = analysis.create_warningclass('Call to undefined function', '', 10, warningclass_flags.PADDING, warning_significance.RELIABILITY)
>>> mmfunc = project.current().find_procedure('mymalloc(int)')
>>> csite = mmfunc.call_sites_vector()[0]
>>> if csite.callee().get_kind() == procedure_kind.UNDEFINED:
...    # if mymalloc() changes, it may no longer contain the call site
...    # if csite.callee() changes, it may now be defined
...    retract_undef = warning_retraction_info([], [mmfunc, csite.callee()], [])
...    wc_undeffunc.report(csite, 'Call to undefined function "{0}"'.format(csite.callee().name()), report_flags.NONE, retract_undef)
...
Rendering `Call to undefined function' Warning... done
Reporting `Call to undefined function' Warning at C:\alex\test\apitest.cpp:6
<cs.result SUCCESS>
report(p, endbox[, flags =  report_flags.NONE])

Report a warning at a point .

Parameters:
  • p (point) – The point where the warning occurs.
  • endbox (str) – A short explanation of why the warning has been issued.
  • flags (report_flags) – (optional) report_flags that characterize the report.
Return type:

result

Returns:

A result , as follows:

  • result.SUCCESS if the warning was successfully queued for submission to the hub.
  • result.FILTERED_OUT if the warning was not submitted to the hub because it matched a WARNING_FILTER discard rule in the configuration file.
  • result.TIMEOUT if the time limit specified by configuration file option TIME_LIMIT_RENDER expired.
  • result.NO_SOURCE_CORRESPONDENCE if the warning was not submitted to the hub because no source location for the warning could be determined.
  • result.ELEMENT_ALREADY_PRESENT if the warning was not submitted to the hub because configuration file option REPORT_SIMILAR_WARNINGS is set to No and a similar warning was previously submitted.

Raises:

result.ERROR_INVALID_PHASE_FOR_OPERATION if called from a drop visitor, or your plug-in’s top-level scope.

This creates a single-event warning where the event is an end box.

The warning will be automatically retracted in a subsequent incremental analysis if and only if the compunit containing p has been modified.

There are multiple methods for reporting a warning at a point. See the table above for details.

>>> wc_undeffunc = analysis.create_warningclass('Call to undefined function', '', 10, warningclass_flags.PADDING, warning_significance.RELIABILITY)
>>> mmfunc = project.current().find_procedure('mymalloc(int)')
>>> csite = mmfunc.call_sites_vector()[0]
>>> if csite.callee().get_kind() == procedure_kind.UNDEFINED:
...    wc_undeffunc.report(csite, 'Call to undefined function "{0}"'.format(csite.callee().name()), report_flags.ALREADY_XML_ENCODED)
...
Rendering `Call to undefined function' Warning... done
Reporting `Call to undefined function' Warning at C:\alex\test\apitest.cpp:6
<cs.result SUCCESS>
>>> wc_undeffunc = analysis.create_warningclass('Call to undefined function', '', 10, warningclass_flags.PADDING, warning_significance.RELIABILITY)
>>> mmfunc = project.current().find_procedure('mymalloc(int)')
>>> csite = mmfunc.call_sites_vector()[0]
>>> if csite.callee().get_kind() == procedure_kind.UNDEFINED:
...    wc_undeffunc.report(csite, 'Call to undefined function "{0}"'.format(csite.callee().name()))
...
Rendering `Call to undefined function' Warning... done
Reporting `Call to undefined function' Warning at C:\alex\test\apitest.cpp:6
<cs.result SUCCESS>
report(file, endbox, flags, ri)

Report a warning associated with a file instance, providing retraction information.

Parameters:
Return type:

result

Returns:

A result , as follows:

  • result.SUCCESS if the warning was successfully queued for submission to the hub.
  • result.FILTERED_OUT if the warning was not submitted to the hub because it matched a WARNING_FILTER discard rule in the configuration file.
  • result.TIMEOUT if the time limit specified by configuration file option TIME_LIMIT_RENDER expired.
  • result.NO_SOURCE_CORRESPONDENCE if the warning was not submitted to the hub because no source location for the warning could be determined.
  • result.ELEMENT_ALREADY_PRESENT if the warning was not submitted to the hub because configuration file option REPORT_SIMILAR_WARNINGS is set to No and a similar warning was previously submitted.

Raises:

The warning will be automatically retracted in a subsequent incremental analysis if and only if one or more of the conditions expressed in ri is satisfied.

There are multiple methods for reporting a warning associated with a file instance. See the table above for details.

>>> wc_undefcall = analysis.create_warningclass('File contains calls to undefined functions')
>>> cu = project.current().compunits_vector()[0]
>>> cu_callsites = [pt for proc in cu.procedures() for pt in proc.points()
...                 if pt.get_kind() == point_kind.CALL_SITE and pt.callee().get_kind() == procedure_kind.UNDEFINED]
>>> byproc = point_set(cu_callsites).categorize()[0][1]                           # a list of (procedure,point_set) pairs
>>> byproc = [(proc.file_line()[0],proc,callsites) for proc,callsites in byproc]  # a list of (sfileinst,procedure,point_set) triples
>>> for sfi in set([*zip(*byproc)][0]):                                           # the set of all sfileinst  represented in byproc
...     num_undef_calls = sum([len(callsites) for fi,proc,callsites in byproc if sfi==fi])
...     ret = warning_retraction_info([], [], [sfi.get_compunit()])
...     wc_undefcall.report(sfi, 'This file contains {0} calls to undefined functions'.format(str(num_undef_calls)), report_flags.NONE, ret)
...
Rendering `File contains calls to undefined functions' Warning... done
Reporting `File contains calls to undefined functions' Warning at C:\alex\test\apitest.cpp:1
<cs.result SUCCESS>
report(file, endbox[, flags =  report_flags.NONE])

Report a warning associated with a file instance.

Parameters:
Return type:

result

Returns:

A result , as follows:

  • result.SUCCESS if the warning was successfully queued for submission to the hub.
  • result.FILTERED_OUT if the warning was not submitted to the hub because it matched a WARNING_FILTER discard rule in the configuration file.
  • result.TIMEOUT if the time limit specified by configuration file option TIME_LIMIT_RENDER expired.
  • result.NO_SOURCE_CORRESPONDENCE if the warning was not submitted to the hub because no source location for the warning could be determined.
  • result.ELEMENT_ALREADY_PRESENT if the warning was not submitted to the hub because configuration file option REPORT_SIMILAR_WARNINGS is set to No and a similar warning was previously submitted.

Raises:

The warning will be automatically retracted in a subsequent incremental analysis if and only if the compunit containing file has been modified.

There are multiple methods for reporting a warning associated with a file instance. See the table above for details.

>>> wc_undefcall = analysis.create_warningclass('File contains calls to undefined functions')
>>> cu = project.current().compunits_vector()[0]
>>> cu_callsites = [pt for proc in cu.procedures() for pt in proc.points()
...                 if pt.get_kind() == point_kind.CALL_SITE and pt.callee().get_kind() == procedure_kind.UNDEFINED]
>>> byproc = point_set(cu_callsites).categorize()[0][1]                           # a list of (procedure,point_set) pairs
>>> byproc = [(proc.file_line()[0],proc,callsites) for proc,callsites in byproc]  # a list of (sfileinst,procedure,point_set) triples
>>> for sfi in set([*zip(*byproc)][0]):                                           # the set of all sfileinst  represented in byproc
...    num_undef_calls = sum([len(callsites) for fi,proc,callsites in byproc if sfi==fi])
...    wc_undefcall.report(sfi, 'This file contains {0} calls to undefined functions'.format(num_undef_calls), report_flags.NONE)
...
Rendering `File contains calls to undefined functions' Warning... done
Reporting `File contains calls to undefined functions' Warning at C:\alex\test\apitest.cpp:1
<cs.result SUCCESS>
>>> wc_undefcall = analysis.create_warningclass('File contains calls to undefined functions')
>>> cu = project.current().compunits_vector()[0]
>>> cu_callsites = [pt for proc in cu.procedures() for pt in proc.points()
...                 if pt.get_kind() == point_kind.CALL_SITE and pt.callee().get_kind() == procedure_kind.UNDEFINED]
>>> byproc = point_set(cu_callsites).categorize()[0][1]                           # a list of (procedure,point_set) pairs
>>> byproc = [(proc.file_line()[0],proc,callsites) for proc,callsites in byproc]  # a list of (sfileinst,procedure,point_set) triples
>>> for sfi in set([*zip(*byproc)][0]):                                           # the set of all sfileinst  represented in byproc
...    num_undef_calls = sum([len(callsites) for fi,proc,callsites in byproc if sfi==fi])
...    wc_undefcall.report(sfi, 'This file contains {0} calls to undefined functions'.format(str(num_undef_calls)))
...
Rendering `File contains calls to undefined functions' Warning... done
Reporting `File contains calls to undefined functions' Warning at C:\alex\test\apitest.cpp:1
<cs.result SUCCESS>
report(file, line, endbox, flags, ri)

Report a warning with a code location, providing retraction information.

Parameters:
  • file (sfileinst) – The file instance ( sfileinst ) containing the warning.
  • line (int) – The line in file on which the warning occurs.
  • endbox (str) – A short explanation of why the warning has been issued.
  • flags (report_flags) – report_flags that characterize the report.
  • ri (warning_retraction_info) – warning_retraction_info describing the circumstances in which the warning should be retracted for subsequent incremental analyses.
Return type:

result

Returns:

A result , as follows:

  • result.SUCCESS if the warning was successfully queued for submission to the hub.
  • result.FILTERED_OUT if the warning was not submitted to the hub because it matched a WARNING_FILTER discard rule in the configuration file.
  • result.TIMEOUT if the time limit specified by configuration file option TIME_LIMIT_RENDER expired.
  • result.NO_SOURCE_CORRESPONDENCE if the warning was not submitted to the hub because no source location for the warning could be determined.
  • result.ELEMENT_ALREADY_PRESENT if the warning was not submitted to the hub because configuration file option REPORT_SIMILAR_WARNINGS is set to No and a similar warning was previously submitted.

Raises:

This creates a single-event warning where the event is an end box.

The warning will be automatically retracted in a subsequent incremental analysis if and only if one or more of the conditions expressed in ri is satisfied.

There are multiple methods for reporting a warning with a code location. See the table above for details.

>>> whoknows_wc = analysis.create_warningclass('Occurrence of whoknows')
>>> q = xr_query()
>>> q.add_term_filter('whoknows')
>>> for t in project.current().token_search(q):
...    # retract if there is a change in any compilation unit containing an instance of the file containing this occurrence
...    ret = warning_retraction_info([], [], [fi.get_compunit() for fi in t.get_file().instances()])
...    whoknows_wc.report(t.get_file().arbitrary_instance(), t.get_line(), 'Token "whoknows" occurs here', report_flags.NONE, ret)
...
Rendering `Occurrence of whoknows' Warning... done
Reporting `Occurrence of whoknows' Warning at C:\alex\test\apitest.cpp:5
<cs.result SUCCESS>
Rendering `Occurrence of whoknows' Warning... done
Reporting `Occurrence of whoknows' Warning at C:\alex\test\apitest.cpp:6
<cs.result SUCCESS>
report(file, line, endbox[, flags =  report_flags.NONE])

Report a warning with a code location.

Parameters:
  • file (sfileinst) – The file instance ( sfileinst ) containing the warning.
  • line (int) – The line in file on which the warning occurs.
  • endbox (str) – A short explanation of why the warning has been issued.
  • flags (report_flags) – (optional) report_flags that characterize the report.
Return type:

result

Returns:

A result , as follows:

  • result.SUCCESS if the warning was successfully queued for submission to the hub.
  • result.FILTERED_OUT if the warning was not submitted to the hub because it matched a WARNING_FILTER discard rule in the configuration file.
  • result.TIMEOUT if the time limit specified by configuration file option TIME_LIMIT_RENDER expired.
  • result.NO_SOURCE_CORRESPONDENCE if the warning was not submitted to the hub because no source location for the warning could be determined.
  • result.ELEMENT_ALREADY_PRESENT if the warning was not submitted to the hub because configuration file option REPORT_SIMILAR_WARNINGS is set to No and a similar warning was previously submitted.

Raises:

This creates a single-event warning where the event is an end box.

The warning will be automatically retracted in a subsequent incremental analysis if and only if the compunit containing file has been modified.

There are multiple methods for reporting a warning with a code location. See the table above for details.

>>> whoknows_wc = analysis.create_warningclass('Occurrence of whoknows')
>>> q = xr_query()
>>> q.add_term_filter('whoknows')
>>> for t in project.current().token_search(q):
...    whoknows_wc.report(t.get_file().arbitrary_instance(), t.get_line(), 'Token "whoknows" occurs here', report_flags.ALREADY_XML_ENCODED)
...
Rendering `Occurrence of whoknows' Warning... done
Reporting `Occurrence of whoknows' Warning at C:\alex\test\apitest.cpp:5
<cs.result SUCCESS>
Rendering `Occurrence of whoknows' Warning... done
Reporting `Occurrence of whoknows' Warning at C:\alex\test\apitest.cpp:6
<cs.result SUCCESS>
>>> whoknows_wc = analysis.create_warningclass('Occurrence of whoknows')
>>> q = xr_query()
>>> q.add_term_filter('whoknows')
>>> for t in project.current().token_search(q):
...    whoknows_wc.report(t.get_file().arbitrary_instance(), t.get_line(), 'Token "whoknows" occurs here')
...
Rendering `Occurrence of whoknows' Warning... done
Reporting `Occurrence of whoknows' Warning at C:\alex\test\apitest.cpp:5
<cs.result SUCCESS>
Rendering `Occurrence of whoknows' Warning... done
Reporting `Occurrence of whoknows' Warning at C:\alex\test\apitest.cpp:6
<cs.result SUCCESS>
report(file, line, proc, endbox, flags, ri)

Report a warning at a line in a specified procedure, providing retraction information.

Parameters:
Return type:

result

Returns:

A result , as follows:

  • result.SUCCESS if the warning was successfully queued for submission to the hub.
  • result.FILTERED_OUT if the warning was not submitted to the hub because it matched a WARNING_FILTER discard rule in the configuration file.
  • result.TIMEOUT if the time limit specified by configuration file option TIME_LIMIT_RENDER expired.
  • result.NO_SOURCE_CORRESPONDENCE if the warning was not submitted to the hub because no source location for the warning could be determined.
  • result.ELEMENT_ALREADY_PRESENT if the warning was not submitted to the hub because configuration file option REPORT_SIMILAR_WARNINGS is set to No and a similar warning was previously submitted.

Raises:

The warning will be automatically retracted in a subsequent incremental analysis if and only if one or more of the conditions expressed in ri is satisfied.

There are multiple methods for reporting a warning at a line in a specified procedure. See the table above for details.

>>> wc = analysis.create_warningclass('Function named "foo"', '', 20, warningclass_flags.NONE, warning_significance.DIAGNOSTIC)
>>> foofn = project.current().find_procedure('foo')
>>> (sfi,ln)=foofn.file_line()
>>> retract = warning_retraction_info([],[],[foofn.get_compunit()])
>>> retract
<cs.warning_retraction_info {} {} {<cs.compunit C:\alex\test\apitest.cpp>}>
>>> wc.report(sfi, ln, foofn, 'This function is named "foo". Consider a more meaningful name.', report_flags.ALREADY_XML_ENCODED, retract)
Rendering `Function named "foo"' Warning... done
Reporting `Function named "foo"' Warning at C:\alex\test\apitest.cpp:32
<cs.result SUCCESS>
report(file, line, proc, endbox[, flags =  report_flags.NONE])

Report a warning at a line in a specified procedure.

Parameters:
  • file (sfileinst) – The file instance ( sfileinst ) containing the warning.
  • line (int) – The line in file on which the warning occurs.
  • proc (procedure) – The procedure in which the warning occurs.
  • endbox (str) – A short explanation of why the warning has been issued.
  • flags (report_flags) – (optional) report_flags that characterize the report.
Return type:

result

Returns:

A result , as follows:

  • result.SUCCESS if the warning was successfully queued for submission to the hub.
  • result.FILTERED_OUT if the warning was not submitted to the hub because it matched a WARNING_FILTER discard rule in the configuration file.
  • result.TIMEOUT if the time limit specified by configuration file option TIME_LIMIT_RENDER expired.
  • result.NO_SOURCE_CORRESPONDENCE if the warning was not submitted to the hub because no source location for the warning could be determined.
  • result.ELEMENT_ALREADY_PRESENT if the warning was not submitted to the hub because configuration file option REPORT_SIMILAR_WARNINGS is set to No and a similar warning was previously submitted.

Raises:

The warning will be automatically retracted in a subsequent incremental analysis if and only if the compunit containing file has been modified.

There are multiple methods for reporting a warning at a line in a specified procedure. See the table above for details.

>>> wc = analysis.create_warningclass('Function named "foo"', '', 20, warningclass_flags.NONE, warning_significance.DIAGNOSTIC)
>>> foofn = project.current().find_procedure('foo')
>>> (sfi,ln)=foofn.file_line()
>>> wc.report(sfi, ln, foofn, 'This function is named "foo". Consider a more meaningful name.', report_flags.ALREADY_XML_ENCODED )
Rendering `Function named "foo"' Warning... done
Reporting `Function named "foo"' Warning at C:\alex\test\apitest.cpp:32
<cs.result SUCCESS>
>>> wc = analysis.create_warningclass('Function named "foo"', '', 20, warningclass_flags.NONE, warning_significance.DIAGNOSTIC)
>>> foofn = project.current().find_procedure('foo')
>>> (sfi,ln)=foofn.file_line()
>>> wc.report(sfi, ln, foofn, 'This function is named "foo". Consider a more meaningful name.' )
Rendering `Function named "foo"' Warning... done
Reporting `Function named "foo"' Warning at C:\alex\test\apitest.cpp:32
<cs.result SUCCESS>
report(file, start_line, end_line, start_col, end_col, endbox, flags, ri)

Report a warning with a code span location, providing retraction information.

Parameters:
  • file (sfileinst) – The file instance ( sfileinst ) containing the warning.
  • start_line (int) – The line in file on which the warning starts.
  • end_line (int) – The line in file on which the warning ends.
  • start_col (int) – The column on start_line where the warning starts.
  • end_col (int) – The column on end_line where the warning ends.
  • endbox (str) – A short explanation of why the warning has been issued.
  • flags (report_flags) – report_flags that characterize the report.
  • ri (warning_retraction_info) – warning_retraction_info describing the circumstances in which the warning should be retracted for subsequent incremental analyses.
Return type:

result

Returns:

A result , as follows:

  • result.SUCCESS if the warning was successfully queued for submission to the hub.
  • result.FILTERED_OUT if the warning was not submitted to the hub because it matched a WARNING_FILTER discard rule in the configuration file.
  • result.TIMEOUT if the time limit specified by configuration file option TIME_LIMIT_RENDER expired.
  • result.NO_SOURCE_CORRESPONDENCE if the warning was not submitted to the hub because no source location for the warning could be determined.
  • result.ELEMENT_ALREADY_PRESENT if the warning was not submitted to the hub because configuration file option REPORT_SIMILAR_WARNINGS is set to No and a similar warning was previously submitted.

Raises:

This creates a single-event warning where the event is an end box.

The warning will be automatically retracted in a subsequent incremental analysis if and only if one or more of the conditions expressed in ri is satisfied.

There are multiple methods for reporting a warning with a code location. See the table above for details.

>>> # given an int_pair_set ips, return a pair of offsets
>>> # denoting the first and last offsets included in ips
>>> def ips_to_span_offsets(ips):
...     sorted_ips = sorted(list(ips), key = lambda pr:pr[0])
...     return (sorted_ips[0][0], sorted_ips[-1][0] + sorted_ips[-1][1])
...
>>> barfn = project.current().find_procedure('bar(int, void *, int)')
>>> bar_call_wc = analysis.create_warningclass('Call to bar', '', 5,
...                                            warningclass_flags.NONE)
>>> for pt in barfn.callers():
...     (sfi,ips) = pt.charpos()
...     (start_offset, end_offset) = ips_to_span_offsets(ips)
...     (sline,scol) = sfi.offset_to_line_column(start_offset)
...     (eline,ecol) = sfi.offset_to_line_column(end_offset)
...     bar_call_wc.report(sfi, sline, eline, scol, ecol,
...                        'bar called here',
...                        report_flags.NONE,
...                        warning_retraction_info([], [pt.get_procedure()], []))
...
Rendering `Call to bar' Warning... done
Reporting `Call to bar' Warning at C:\alex\test\apitest.cpp:35
<cs.result SUCCESS>
Rendering `Call to bar' Warning... done
Reporting `Call to bar' Warning at C:\alex\test\apitest.cpp:36
<cs.result SUCCESS>
Rendering `Call to bar' Warning... done
Reporting `Call to bar' Warning at C:\alex\test\apitest.cpp:40
<cs.result SUCCESS>
Rendering `Call to bar' Warning... done
Reporting `Call to bar' Warning at C:\alex\test\apitest.cpp:14
<cs.result SUCCESS>
report(file, start_line, end_line, start_col, end_col, endbox[, flags =  report_flags.NONE])

Report a warning with a code span location.

Parameters:
  • file (sfileinst) – The file instance ( sfileinst ) containing the warning.
  • start_line (int) – The line in file on which the warning starts.
  • end_line (int) – The line in file on which the warning ends.
  • start_col (int) – The column on start_line where the warning starts.
  • end_col (int) – The column on end_line where the warning ends.
  • endbox (str) – A short explanation of why the warning has been issued.
  • flags (report_flags) – (optional) report_flags that characterize the report.
Return type:

result

Returns:

A result , as follows:

  • result.SUCCESS if the warning was successfully queued for submission to the hub.
  • result.FILTERED_OUT if the warning was not submitted to the hub because it matched a WARNING_FILTER discard rule in the configuration file.
  • result.TIMEOUT if the time limit specified by configuration file option TIME_LIMIT_RENDER expired.
  • result.NO_SOURCE_CORRESPONDENCE if the warning was not submitted to the hub because no source location for the warning could be determined.
  • result.ELEMENT_ALREADY_PRESENT if the warning was not submitted to the hub because configuration file option REPORT_SIMILAR_WARNINGS is set to No and a similar warning was previously submitted.

Raises:

This creates a single-event warning where the event is an end box.

The warning will be automatically retracted in a subsequent incremental analysis if and only if the compunit containing file has been modified.

There are multiple methods for reporting a warning with a code location. See the table above for details.

>>> # given an int_pair_set ips, return a pair of offsets
>>> # denoting the first and last offsets included in ips
>>> def ips_to_span_offsets(ips):
...     sorted_ips = sorted(list(ips), key = lambda pr:pr[0])
...     return (sorted_ips[0][0], sorted_ips[-1][0] + sorted_ips[-1][1])
...
>>> barfn = project.current().find_procedure('bar(int, void *, int)')
>>> bar_call_wc = analysis.create_warningclass('Call to bar', '', 5,
...                                            warningclass_flags.NONE)
>>> for pt in barfn.callers():
...     (sfi,ips) = pt.charpos()
...     (start_offset, end_offset) = ips_to_span_offsets(ips)
...     (sline,scol) = sfi.offset_to_line_column(start_offset)
...     (eline,ecol) = sfi.offset_to_line_column(end_offset)
...     bar_call_wc.report(sfi, sline, eline, scol, ecol,
...                        'bar called here',
...                         report_flags.NONE)
...
Rendering `Call to bar' Warning... done
Reporting `Call to bar' Warning at C:\alex\test\apitest.cpp:35
<cs.result SUCCESS>
Rendering `Call to bar' Warning... done
Reporting `Call to bar' Warning at C:\alex\test\apitest.cpp:36
<cs.result SUCCESS>
Rendering `Call to bar' Warning... done
Reporting `Call to bar' Warning at C:\alex\test\apitest.cpp:40
<cs.result SUCCESS>
Rendering `Call to bar' Warning... done
Reporting `Call to bar' Warning at C:\alex\test\apitest.cpp:14
<cs.result SUCCESS>
>>> # given an int_pair_set ips, return a pair of offsets
>>> # denoting the first and last offsets included in ips
>>> def ips_to_span_offsets(ips):
...     sorted_ips = sorted(list(ips), key = lambda pr:pr[0])
...     return (sorted_ips[0][0], sorted_ips[-1][0] + sorted_ips[-1][1])
...
>>> barfn = project.current().find_procedure('bar(int, void *, int)')
>>> bar_call_wc = analysis.create_warningclass('Call to bar', '', 5,
...                                            warningclass_flags.NONE)
>>> for pt in barfn.callers():
...     (sfi,ips) = pt.charpos()
...     (start_offset, end_offset) = ips_to_span_offsets(ips)
...     (sline,scol) = sfi.offset_to_line_column(start_offset)
...     (eline,ecol) = sfi.offset_to_line_column(end_offset)
...     bar_call_wc.report(sfi, sline, eline, scol, ecol,
...                        'bar called here')
...
Rendering `Call to bar' Warning... done
Reporting `Call to bar' Warning at C:\alex\test\apitest.cpp:35
<cs.result SUCCESS>
Rendering `Call to bar' Warning... done
Reporting `Call to bar' Warning at C:\alex\test\apitest.cpp:36
<cs.result SUCCESS>
Rendering `Call to bar' Warning... done
Reporting `Call to bar' Warning at C:\alex\test\apitest.cpp:40
<cs.result SUCCESS>
Rendering `Call to bar' Warning... done
Reporting `Call to bar' Warning at C:\alex\test\apitest.cpp:14
<cs.result SUCCESS>
report(file, start_line, end_line, start_col, end_col, proc, endbox, flags, ri)

Report a warning at a span in a specified procedure, providing retraction information.

Parameters:
  • file (sfileinst) – The file instance ( sfileinst ) containing the warning.
  • start_line (int) – The line in file on which the warning starts.
  • end_line (int) – The line in file on which the warning ends.
  • start_col (int) – The column on start_line on which the warning starts.
  • end_col (int) – The column on end_line on which the warning ends.
  • proc (procedure) – The procedure in which the warning occurs.
  • endbox (str) – A short explanation of why the warning has been issued.
  • flags (report_flags) – report_flags that characterize the report.
  • ri (warning_retraction_info) – warning_retraction_info describing the circumstances in which the warning should be retracted for subsequent incremental analyses.
Return type:

result

Raises:

The warning will be automatically retracted in a subsequent incremental analysis if and only if one or more of the conditions expressed in ri is satisfied.

There are multiple methods for reporting a warning at a line in a specified procedure. See the table above for details.

Always invoke report_return_warning() methods inside a try block.

>>> # given an int_pair_set ips, return a pair of offsets
>>> # denoting the first and last offsets included in ips
>>> def ips_to_span_offsets(ips):
...      sorted_ips = sorted(list(ips), key = lambda pr:pr[0])
...      return (sorted_ips[0][0], sorted_ips[-1][0] + sorted_ips[-1][1])
...
>>> barfn = project.current().find_procedure('bar(int, void *, int)')
>>> bar_call_wc = analysis.create_warningclass('Call to bar', '', 5,
...                                            warningclass_flags.NONE)
>>> for pt in barfn.callers():
...      (sfi,ips) = pt.charpos()
...      (start_offset, end_offset) = ips_to_span_offsets(ips)
...      (sline,scol) = sfi.offset_to_line_column(start_offset)
...      (eline,ecol) = sfi.offset_to_line_column(end_offset)
...      bar_call_wc.report(sfi, sline, eline, scol, ecol,
...                                pt.get_procedure(),
...                                'bar called here',
...                                report_flags.NONE,
...                                warning_retraction_info([],[pt.get_procedure()],[]))
...
Rendering `Call to bar' Warning... done
Reporting `Call to bar' Warning at C:\alex\test\apitest.cpp:35
<cs.result SUCCESS>
Rendering `Call to bar' Warning... done
Reporting `Call to bar' Warning at C:\alex\test\apitest.cpp:36
<cs.result SUCCESS>
Rendering `Call to bar' Warning... done
Reporting `Call to bar' Warning at C:\alex\test\apitest.cpp:40
<cs.result SUCCESS>
Rendering `Call to bar' Warning... done
Reporting `Call to bar' Warning at C:\alex\test\apitest.cpp:14
<cs.result SUCCESS>
report(file, start_line, end_line, start_col, end_col, proc, endbox[, flags =  report_flags.NONE])

Report a warning at a span in a specified procedure.

Parameters:
  • file (sfileinst) – The file instance ( sfileinst ) containing the warning.
  • start_line (int) – The line in file on which the warning starts.
  • end_line (int) – The line in file on which the warning ends.
  • start_col (int) – The column on start_line on which the warning starts.
  • end_col (int) – The column on end_line on which the warning ends.
  • proc (procedure) – The procedure in which the warning occurs.
  • endbox (str) – A short explanation of why the warning has been issued.
  • flags (report_flags) – (optional) report_flags that characterize the report.
Return type:

result

Returns:

A result , as follows:

  • result.SUCCESS if the warning was successfully queued for submission to the hub.
  • result.FILTERED_OUT if the warning was not submitted to the hub because it matched a WARNING_FILTER discard rule in the configuration file.
  • result.TIMEOUT if the time limit specified by configuration file option TIME_LIMIT_RENDER expired.
  • result.NO_SOURCE_CORRESPONDENCE if the warning was not submitted to the hub because no source location for the warning could be determined.
  • result.ELEMENT_ALREADY_PRESENT if the warning was not submitted to the hub because configuration file option REPORT_SIMILAR_WARNINGS is set to No and a similar warning was previously submitted.

Raises:

The warning will be automatically retracted in a subsequent incremental analysis if and only if the compunit containing file has been modified.

There are multiple methods for reporting a warning at a line in a specified procedure. See the table above for details.

>>> # given an int_pair_set ips, return a pair of offsets
>>> # denoting the first and last offsets included in ips
>>> def ips_to_span_offsets(ips):
...     sorted_ips = sorted(list(ips), key = lambda pr:pr[0])
...     return (sorted_ips[0][0], sorted_ips[-1][0] + sorted_ips[-1][1])
...
>>> barfn = project.current().find_procedure('bar(int, void *, int)')
>>> bar_call_wc = analysis.create_warningclass('Call to bar', '', 5,
...                                            warningclass_flags.NONE)
>>> for pt in barfn.callers():
...     (sfi,ips) = pt.charpos()
...     (start_offset, end_offset) = ips_to_span_offsets(ips)
...     (sline,scol) = sfi.offset_to_line_column(start_offset)
...     (eline,ecol) = sfi.offset_to_line_column(end_offset)
...     bar_call_wc.report(sfi, sline, eline, scol, ecol,
...                                pt.get_procedure(),
...                                'bar called here',
...                                report_flags.NONE)
...
Rendering `Call to bar' Warning... done
Reporting `Call to bar' Warning at C:\alex\test\apitest.cpp:35
<cs.result SUCCESS>
Rendering `Call to bar' Warning... done
Reporting `Call to bar' Warning at C:\alex\test\apitest.cpp:36
<cs.result SUCCESS>
Rendering `Call to bar' Warning... done
Reporting `Call to bar' Warning at C:\alex\test\apitest.cpp:40
<cs.result SUCCESS>
Rendering `Call to bar' Warning... done
Reporting `Call to bar' Warning at C:\alex\test\apitest.cpp:14
<cs.result SUCCESS>
>>> # given an int_pair_set ips, return a pair of offsets
>>> # denoting the first and last offsets included in ips
>>> def ips_to_span_offsets(ips):
...     sorted_ips = sorted(list(ips), key = lambda pr:pr[0])
...     return (sorted_ips[0][0], sorted_ips[-1][0] + sorted_ips[-1][1])
...
>>> barfn = project.current().find_procedure('bar(int, void *, int)')
>>> bar_call_wc = analysis.create_warningclass('Call to bar', '', 5,
...                                            warningclass_flags.NONE)
>>> for pt in barfn.callers():
...     (sfi,ips) = pt.charpos()
...     (start_offset, end_offset) = ips_to_span_offsets(ips)
...     (sline,scol) = sfi.offset_to_line_column(start_offset)
...     (eline,ecol) = sfi.offset_to_line_column(end_offset)
...     bar_call_wc.report(sfi, sline, eline, scol, ecol,
...                                pt.get_procedure(),
...                                'bar called here')
...
Rendering `Call to bar' Warning... done
Reporting `Call to bar' Warning at C:\alex\test\apitest.cpp:35
<cs.result SUCCESS>
Rendering `Call to bar' Warning... done
Reporting `Call to bar' Warning at C:\alex\test\apitest.cpp:36
<cs.result SUCCESS>
Rendering `Call to bar' Warning... done
Reporting `Call to bar' Warning at C:\alex\test\apitest.cpp:40
<cs.result SUCCESS>
Rendering `Call to bar' Warning... done
Reporting `Call to bar' Warning at C:\alex\test\apitest.cpp:14
<cs.result SUCCESS>
report(p)

Report a warning with a step path.

Parameters:p (step_path) – The step path ( step_path ) associated with the warning.
Return type:result
Returns:A result , as follows:
  • result.SUCCESS if the warning was successfully queued for submission to the hub.
  • result.FILTERED_OUT if the warning was not submitted to the hub because it matched a WARNING_FILTER discard rule in the configuration file.
  • result.TIMEOUT if the time limit specified by configuration file option TIME_LIMIT_RENDER expired.
  • result.NO_SOURCE_CORRESPONDENCE if the warning was not submitted to the hub because no source location for the warning could be determined.
  • result.ELEMENT_ALREADY_PRESENT if the warning was not submitted to the hub because configuration file option REPORT_SIMILAR_WARNINGS is set to No and a similar warning was previously submitted.
Raises:result.ERROR_INVALID_PHASE_FOR_OPERATION if called from a drop visitor, or your plug-in’s top-level scope.

The warning will be automatically retracted in a subsequent incremental analysis if and only if the compunit containing the first point in p has been modified.

There are multiple methods for reporting a warning with a step path. See the table above for details.

#      software is retained by CodeSecure, Inc.
#

# callbar_plugin.py
#
# A simple step visitor with examples of the different functions for
# reporting warnings with step paths. You can copy and install this
# as a CodeSonar plug-in if you want to see its results on the apitest
# project.

import cs

# These warning classes will all be reported under the same
# conditions, but have different names so you can distinguish them in
# the analysis results.
bar_wc = cs.analysis.create_warningclass('bar() called')  
bar_retr_wc = cs.analysis.create_warningclass('bar() called (with retraction info)')  
bar_retn_wc = cs.analysis.create_warningclass('bar() called (warning returned)')  
bar_retn_retr_wc = cs.analysis.create_warningclass('bar() called (with retraction info, warning returned)')  

class bar_called(cs.step_state):   
    def __init__(self):
        super(bar_called, self).__init__()
        
    def copy(self):
        return bar_called()

    def transition(self, srcpt, edgelabel, destpt, tosrc_xform, edge_xform, tosrc_path):
        try:
            if srcpt.get_kind()==cs.point_kind.CALL_SITE and srcpt.callee().name()=='bar':
               retr_info = cs.warning_retraction_info([], [srcpt.get_procedure()], [])
               bar_wc.report(tosrc_path)
               bar_retr_wc.report(tosrc_path, retr_info)
               w1 = bar_retn_wc.report_return_warning(tosrc_path)
               w2 = bar_retn_retr_wc.report_return_warning(tosrc_path, retr_info)
               # do something with w1 and w2
        except cs.result as r:
            pass

cs.analysis.add_step_bottom_up_visitor(bar_called())
report(p, ri)

Report a warning with a step path, providing retraction information.

Parameters:
Return type:

result

Returns:

A result , as follows:

  • result.SUCCESS if the warning was successfully queued for submission to the hub.
  • result.FILTERED_OUT if the warning was not submitted to the hub because it matched a WARNING_FILTER discard rule in the configuration file.
  • result.TIMEOUT if the time limit specified by configuration file option TIME_LIMIT_RENDER expired.
  • result.NO_SOURCE_CORRESPONDENCE if the warning was not submitted to the hub because no source location for the warning could be determined.
  • result.ELEMENT_ALREADY_PRESENT if the warning was not submitted to the hub because configuration file option REPORT_SIMILAR_WARNINGS is set to No and a similar warning was previously submitted.

Raises:

result.ERROR_INVALID_PHASE_FOR_OPERATION if called from a drop visitor, or your plug-in’s top-level scope.

The warning will be automatically retracted in a subsequent incremental analysis if and only if one or more of the conditions expressed in ri is satisfied.

There are multiple methods for reporting a warning with a step path. See the table above for details.

#      software is retained by CodeSecure, Inc.
#

# callbar_plugin.py
#
# A simple step visitor with examples of the different functions for
# reporting warnings with step paths. You can copy and install this
# as a CodeSonar plug-in if you want to see its results on the apitest
# project.

import cs

# These warning classes will all be reported under the same
# conditions, but have different names so you can distinguish them in
# the analysis results.
bar_wc = cs.analysis.create_warningclass('bar() called')  
bar_retr_wc = cs.analysis.create_warningclass('bar() called (with retraction info)')  
bar_retn_wc = cs.analysis.create_warningclass('bar() called (warning returned)')  
bar_retn_retr_wc = cs.analysis.create_warningclass('bar() called (with retraction info, warning returned)')  

class bar_called(cs.step_state):   
    def __init__(self):
        super(bar_called, self).__init__()
        
    def copy(self):
        return bar_called()

    def transition(self, srcpt, edgelabel, destpt, tosrc_xform, edge_xform, tosrc_path):
        try:
            if srcpt.get_kind()==cs.point_kind.CALL_SITE and srcpt.callee().name()=='bar':
               retr_info = cs.warning_retraction_info([], [srcpt.get_procedure()], [])
               bar_wc.report(tosrc_path)
               bar_retr_wc.report(tosrc_path, retr_info)
               w1 = bar_retn_wc.report_return_warning(tosrc_path)
               w2 = bar_retn_retr_wc.report_return_warning(tosrc_path, retr_info)
               # do something with w1 and w2
        except cs.result as r:
            pass

cs.analysis.add_step_bottom_up_visitor(bar_called())
report_return_warning(endbox[, flags =  report_flags.NONE])

Report a warning with no association to a file or procedure and return the reported warning object.

Parameters:
  • endbox (str) – A short explanation of why the warning has been issued.
  • flags (report_flags) – (optional) report_flags that characterize the report.
Return type:

warning

Returns:

The warning object corresponding to the reported warning.

Raises:
  • result.ERROR_INVALID_ARGUMENT if warnings of this class have associated paths (and should therefore be reported with those paths).
  • result.FILTERED_OUT if the warning was not submitted to the hub because it matched a WARNING_FILTER discard rule in the configuration file.
  • result.TIMEOUT if the time limit specified by configuration file option TIME_LIMIT_RENDER expired.
  • result.ELEMENT_ALREADY_PRESENT if the warning was not submitted to the hub because configuration file option REPORT_SIMILAR_WARNINGS is set to No and a similar warning was previously submitted.
  • result.ERROR_INVALID_PHASE_FOR_OPERATION if called from a drop visitor, or your plug-in’s top-level scope.

The warning will be always be automatically retracted during an incremental build, since the warning is against the entire analysis.

There are multiple methods for reporting a warning with no association to a file or procedure. See the table above for details.

Always invoke report_return_warning() methods inside a try block.

>>> reported_warnings=[]
>>> wc_projname = analysis.create_warningclass('Project is called "apitest"')
>>> if project.current().name().lower() == 'apitest':
...     try:
...         w = wc_projname.report_return_warning('''The project's (case-insensitive) name is "apitest".
...           This isn't a problem, just an example of a warning with no association to a file or procedure.''',
...           report_flags.NONE)
...     except result as r:
...         w = None
...         print('Problem reporting warning', r)
...     if w is not None:
...         reported_warnings.append(w)
...
Rendering `Project is called "apitest"' Warning... done
Reporting `Project is called "apitest"' Warning for analysis
>>> reported_warnings
[<cs.warning ...>]
>>> reported_warnings=[]
>>> wc_projname = analysis.create_warningclass('Project is called "apitest"')
>>> if project.current().name().lower() == 'apitest':
...     try:
...         w = wc_projname.report_return_warning('''The project's (case-insensitive) name is "apitest".
...           This isn't a problem, just an example of a warning with no association to a file or procedure.''')
...     except result as r:
...         w = None
...         print('Problem reporting warning', r)
...     if w is not None:
...         reported_warnings.append(w)
...
Rendering `Project is called "apitest"' Warning... done
Reporting `Project is called "apitest"' Warning for analysis
>>> reported_warnings
[<cs.warning ...>]
report_return_warning(p)

Report a warning with a path and return the reported warning object.

Parameters:

p (iterable of cfg_path_node) – The path associated with the warning, with each point on the path described by a cfg_path_node .

Return type:

warning

Returns:

The warning object corresponding to the reported warning.

Raises:

The warning will be automatically retracted in a subsequent incremental analysis if and only if the compunit containing the first point in p has been modified.

There are multiple methods for reporting a warning with a path. See the table above for details.

Always invoke report_return_warning() methods inside a try block.

>>> wc = analysis.create_warningclass('mymalloc() called after bar()')
>>> def paths_to_pts(currpt, endpts):
...     if currpt.get_kind()==point_kind.EXIT:
...        return []
...     return [[cfg_path_node(targ[0],targ[1],'',cfg_path_node_flags.NONE)] + path                     # intermediate point
...               for targ in currpt.cfg_targets() if targ[0] not in endpts
...               for path in paths_to_pts(targ[0], endpts)]\
...            + [[cfg_path_node(targ[0], targ[1], 'Call to mymalloc()', cfg_path_node_flags.ENDBOX)]   # end point
...               for targ in currpt.cfg_targets() if targ[0] in endpts ]
...
>>> def find_bar_mm_paths(proc):
...     callsites = list(proc.call_sites())
...     bar_calls = [c for c in callsites if c.callee().name()=='bar']
...     mymalloc_calls = [c for c in callsites if c.callee().name()=='mymalloc']
...     if not (callsites and bar_calls and mymalloc_calls):
...        return []
...     return [[cfg_path_node(targ[0], targ[1], 'Call to bar()', cfg_path_node_flags.PRIMARY)] + cfgpath  # start point
...              for s in bar_calls
...              for targ in s.cfg_targets()
...          for cfgpath in paths_to_pts(targ[0], mymalloc_calls)]
...
>>> foofn = project.current().find_procedure('foo')
>>> reported_warnings=[]
>>> for cfgpath in find_bar_mm_paths(foofn):
...    try:
...       w = wc.report_return_warning(cfgpath)
...    except result as r:
...       print('Problem reporting warning', r)
...       w = None
...    if w is not None:
...       reported_warnings.append(w)
...
Rendering `mymalloc() called after bar()' Warning... done
Reporting `mymalloc() called after bar()' Warning at C:\alex\test\apitest.cpp:37
Rendering `mymalloc() called after bar()' Warning... done
Reporting `mymalloc() called after bar()' Warning at C:\alex\test\apitest.cpp:37
>>> reported_warnings
[<cs.warning ...>, <cs.warning ...>]
report_return_warning(p, ri)

Report a warning with a path, providing retraction information, and return the reported warning object.

Parameters:
Return type:

warning

Returns:

The warning object corresponding to the reported warning.

Raises:

The warning will be automatically retracted in a subsequent incremental analysis if and only if one or more of the conditions expressed in ri is satisfied.

There are multiple methods for reporting a warning with a path. See the table above for details.

Always invoke report_return_warning() methods inside a try block.

>>> wc = analysis.create_warningclass('mymalloc() called after bar()')
>>> def paths_to_pts(currpt, endpts):
...     if currpt.get_kind()==point_kind.EXIT:
...        return []
...     return [[cfg_path_node(targ[0],targ[1],'',cfg_path_node_flags.NONE)] + path                     # intermediate point
...               for targ in currpt.cfg_targets() if targ[0] not in endpts
...               for path in paths_to_pts(targ[0], endpts)]\
...            + [[cfg_path_node(targ[0], targ[1], 'Call to mymalloc()', cfg_path_node_flags.ENDBOX)]   # end point
...               for targ in currpt.cfg_targets() if targ[0] in endpts ]
...
>>> def find_bar_mm_paths(proc):
...     callsites = list(proc.call_sites())
...     bar_calls = [c for c in callsites if c.callee().name()=='bar']
...     mymalloc_calls = [c for c in callsites if c.callee().name()=='mymalloc']
...     if not (callsites and bar_calls and mymalloc_calls):
...        return []
...     return [[cfg_path_node(targ[0], targ[1], 'Call to bar()', cfg_path_node_flags.PRIMARY)] + cfgpath  # start point
...              for s in bar_calls
...              for targ in s.cfg_targets()
...          for cfgpath in paths_to_pts(targ[0], mymalloc_calls)]
...
>>> foofn = project.current().find_procedure('foo')
>>> reported_warnings=[]
>>> for cfgpath in find_bar_mm_paths(foofn):
...    try:
...       w = wc.report_return_warning(cfgpath, warning_retraction_info([],[foofn],[]))
...    except result as r:
...       print('Problem reporting warning', r)
...       w = None
...    if w is not None:
...       reported_warnings.append(w)
...
Rendering `mymalloc() called after bar()' Warning... done
Reporting `mymalloc() called after bar()' Warning at C:\alex\test\apitest.cpp:37
Rendering `mymalloc() called after bar()' Warning... done
Reporting `mymalloc() called after bar()' Warning at C:\alex\test\apitest.cpp:37
>>> reported_warnings
[<cs.warning ...>, <cs.warning ...>]
report_return_warning(p)

Report a warning with a list of code locations and return the reported warning object.

Parameters:

p (iterable of locations_node) – The list of code locations ( locations_node ) associated with the warning.

Return type:

warning

Returns:

The warning object corresponding to the reported warning.

Raises:
  • result.FILTERED_OUT if the warning was not submitted to the hub because it matched a WARNING_FILTER discard rule in the configuration file.
  • result.TIMEOUT if the time limit specified by configuration file option TIME_LIMIT_RENDER expired.
  • result.NO_SOURCE_CORRESPONDENCE if the warning was not submitted to the hub because no source location for the warning could be determined.
  • result.ELEMENT_ALREADY_PRESENT if the warning was not submitted to the hub because configuration file option REPORT_SIMILAR_WARNINGS is set to No and a similar warning was previously submitted.
  • result.ERROR_INVALID_ARGUMENT if warnings of this class have associated paths (and should therefore be reported with those paths), or if p is empty.
  • result.ERROR_INVALID_PHASE_FOR_OPERATION if called from a drop visitor, or your plug-in’s top-level scope.

The warning will be automatically retracted in a subsequent incremental analysis if and only if the compunit containing the first location in p has been modified.

There are multiple methods for reporting a warning with a list of code locations. See the table above for details.

Always invoke report_return_warning() methods inside a try block.

>>> # The built in 'Recursion' warning class provides more complete checking than this example.
>>> reported_warnings = []
>>> wc = analysis.create_warningclass('One or more calls to recursive function "bar"')
>>> barfn = project.current().find_procedure('bar(int, void *, int)')
>>> if barfn.callers_count() > 0:
...     warning_locations = [locations_node(entry_loc[0], entry_loc[1], '"bar" entry point.', locations_node_flags.ENDBOX)]
...     for c in barfn.callers():
...         call_loc = c.file_line()
...         warning_locations.append(locations_node(call_loc[0], call_loc[1], 'Call to "bar"', locations_node_flags.PRIMARY))
...     try:
...         w = wc.report_return_warning(warning_locations)
...     except result as r:
...         w = None
...         print('Problem reporting warning', r)
...     if w is not None:
...         reported_warnings.append(w)
...
Rendering `One or more calls to recursive function "bar"' Warning... done
Reporting `One or more calls to recursive function "bar"' Warning at C:\alex\test\apitest.cpp:9
>>> reported_warnings
[<cs.warning ...>]
report_return_warning(p, ri)

Report a warning with a list of code locations, providing retraction information, and return the reported warning object.

Parameters:
Return type:

warning

Returns:

The warning object corresponding to the reported warning.

Raises:
  • result.FILTERED_OUT if the warning was not submitted to the hub because it matched a WARNING_FILTER discard rule in the configuration file.
  • result.TIMEOUT if the time limit specified by configuration file option TIME_LIMIT_RENDER expired.
  • result.NO_SOURCE_CORRESPONDENCE if the warning was not submitted to the hub because no source location for the warning could be determined.
  • result.ELEMENT_ALREADY_PRESENT if the warning was not submitted to the hub because configuration file option REPORT_SIMILAR_WARNINGS is set to No and a similar warning was previously submitted.
  • result.ERROR_INVALID_ARGUMENT if warnings of this class have associated paths (and should therefore be reported with those paths), or if p is empty.
  • result.ERROR_INVALID_PHASE_FOR_OPERATION if called from a drop visitor, or your plug-in’s top-level scope.

The warning will be automatically retracted in a subsequent incremental analysis if and only if one or more of the conditions expressed in ri is satisfied.

There are multiple methods for reporting a warning with a list of code locations. See the table above for details.

Always invoke report_return_warning() methods inside a try block.

>>> # The built in 'Recursion' warning class provides more complete checking than this example.
>>> reported_warnings = []
>>> wc = analysis.create_warningclass('One or more calls to recursive function "bar"')
>>> barfn = project.current().find_procedure('bar(int, void *, int)')
>>> if barfn.callers_count() > 0:
...     caller_set = set([])
...     warning_locations = [locations_node(entry_loc[0], entry_loc[1], '"bar" entry point.', locations_node_flags.ENDBOX)]
...     for c in barfn.callers():
...         caller_set.add(c.get_procedure())
...         call_loc = c.file_line()
...         warning_locations.append(locations_node(call_loc[0], call_loc[1], 'Call to "bar"', locations_node_flags.PRIMARY))
...     try:
...         w = wc.report_return_warning(warning_locations, warning_retraction_info([], list(caller_set), []))
...     except result as r:
...         w = None
...         print('Problem reporting warning', r)
...     if w is not None:
...         reported_warnings.append(w)
...
Rendering `One or more calls to recursive function "bar"' Warning... done
Reporting `One or more calls to recursive function "bar"' Warning at C:\alex\test\apitest.cpp:9
>>> reported_warnings
[<cs.warning ...>]
report_return_warning(p, proc)

Report a warning with a list of code locations in a specified procedure and return the reported warning object.

Parameters:
Return type:

warning

Returns:

The warning object corresponding to the reported warning.

Raises:
  • result.FILTERED_OUT if the warning was not submitted to the hub because it matched a WARNING_FILTER discard rule in the configuration file.
  • result.TIMEOUT if the time limit specified by configuration file option TIME_LIMIT_RENDER expired.
  • result.NO_SOURCE_CORRESPONDENCE if the warning was not submitted to the hub because no source location for the warning could be determined.
  • result.ELEMENT_ALREADY_PRESENT if the warning was not submitted to the hub because configuration file option REPORT_SIMILAR_WARNINGS is set to No and a similar warning was previously submitted.
  • result.ERROR_INVALID_ARGUMENT if warnings of this class have associated paths (and should therefore be reported with those paths), or if p is empty.
  • result.ERROR_INVALID_PHASE_FOR_OPERATION if called from a drop visitor, or your plug-in’s top-level scope.

The warning will be automatically retracted in a subsequent incremental analysis if and only if the compunit containing the first location in p has been modified.

There are multiple methods for reporting a warning with a list of code locations in a specified procedure. See the table above for details.

Always invoke report_return_warning() methods inside a try block.

>>> # The built in 'Recursion' warning class provides more complete checking than this example.
>>> warnings_reported=[]
>>> wc = analysis.create_warningclass('Function "bar" calls itself')
>>> barfn = project.current().find_procedure('bar(int, void *, int)')
>>> self_calls = [pt for pt in barfn.call_sites_vector() if pt.callee()==barfn]
>>> if self_calls:
...     entry_loc = barfn.entry_point().file_line()
...     warning_locations = [locations_node(entry_loc[0], entry_loc[1], '"bar" entry point.', locations_node_flags.ENDBOX)]
...     for c in self_calls:
...         call_loc = c.file_line()
...         warning_locations.append(locations_node(call_loc[0], call_loc[1], 'Call to "bar"', locations_node_flags.PRIMARY))
...     try:
...         w = wc.report_return_warning(warning_locations, barfn)
...     except result as r:
...         w = None
...         print('Problems reporting warning', r)
...     if w is not None:
...         warnings_reported.append(w)
...
Rendering `Function "bar" calls itself' Warning... done
Reporting `Function "bar" calls itself' Warning at C:\alex\test\apitest.cpp:9
>>> warnings_reported
[<cs.warning ...>]
report_return_warning(p, proc, ri)

Report a warning with a list of code locations in a specified procedure, providing retraction information, and return the reported warning object.

Parameters:
Return type:

warning

Returns:

The warning object corresponding to the reported warning.

Raises:
  • result.FILTERED_OUT if the warning was not submitted to the hub because it matched a WARNING_FILTER discard rule in the configuration file.
  • result.TIMEOUT if the time limit specified by configuration file option TIME_LIMIT_RENDER expired.
  • result.NO_SOURCE_CORRESPONDENCE if the warning was not submitted to the hub because no source location for the warning could be determined.
  • result.ELEMENT_ALREADY_PRESENT if the warning was not submitted to the hub because configuration file option REPORT_SIMILAR_WARNINGS is set to No and a similar warning was previously submitted.
  • result.ERROR_INVALID_ARGUMENT if warnings of this class have associated paths (and should therefore be reported with those paths), or if p is empty.
  • result.ERROR_INVALID_PHASE_FOR_OPERATION if called from a drop visitor, or your plug-in’s top-level scope.

The warning will be automatically retracted in a subsequent incremental analysis if and only if one or more of the conditions expressed in ri is satisfied.

There are multiple methods for reporting a warning with a list of code locations in a specified procedure. See the table above for details.

Always invoke report_return_warning() methods inside a try block.

>>> # The built in 'Recursion' warning class provides more complete checking than this example.
>>> warnings_reported=[]
>>> wc = analysis.create_warningclass('Function "bar" calls itself')
>>> barfn = project.current().find_procedure('bar(int, void *, int)')
>>> self_calls = [pt for pt in barfn.call_sites_vector() if pt.callee()==barfn]
>>> if self_calls:
...     entry_loc = barfn.entry_point().file_line()
...     warning_locations = [locations_node(entry_loc[0], entry_loc[1], '"bar" entry point.', locations_node_flags.ENDBOX)]
...     for c in self_calls:
...         call_loc = c.file_line()
...         warning_locations.append(locations_node(call_loc[0], call_loc[1], 'Call to "bar"', locations_node_flags.PRIMARY))
...     try:
...         w = wc.report_return_warning(warning_locations, barfn, warning_retraction_info([], [barfn],[]))
...     except result as r:
...         w = None
...         print('Problems reporting warning', r)
...     if w is not None:
...         warnings_reported.append(w)
...
Rendering `Function "bar" calls itself' Warning... done
Reporting `Function "bar" calls itself' Warning at C:\alex\test\apitest.cpp:9
>>> warnings_reported
[<cs.warning ...>]
report_return_warning(p, endbox, flags, ri)

Report a warning at a point , providing retraction information, and return the reported warning object.

Parameters:
Return type:

warning

Returns:

The warning object corresponding to the reported warning.

Raises:
  • result.FILTERED_OUT if the warning was not submitted to the hub because it matched a WARNING_FILTER discard rule in the configuration file.
  • result.TIMEOUT if the time limit specified by configuration file option TIME_LIMIT_RENDER expired.
  • result.NO_SOURCE_CORRESPONDENCE if the warning was not submitted to the hub because no source location for the warning could be determined.
  • result.ELEMENT_ALREADY_PRESENT if the warning was not submitted to the hub because configuration file option REPORT_SIMILAR_WARNINGS is set to No and a similar warning was previously submitted.
  • result.ERROR_INVALID_PHASE_FOR_OPERATION if called from a drop visitor, or your plug-in’s top-level scope.

This creates a single-event warning where the event is an end box.

The warning will be automatically retracted in a subsequent incremental analysis if and only if one or more of the conditions expressed in ri is satisfied.

There are multiple methods for reporting a warning at a point. See the table above for details.

Always invoke report_return_warning() methods inside a try block.

>>> reported_warnings=[]
>>> wc_undeffunc = analysis.create_warningclass('Call to undefined function', '', 10, warningclass_flags.PADDING, warning_significance.RELIABILITY)
>>> mmfunc = project.current().find_procedure('mymalloc(int)')
>>> csite = mmfunc.call_sites_vector()[0]
>>> if csite.callee().get_kind() == procedure_kind.UNDEFINED:
...     # if mymalloc() changes, it may no longer contain the call site
...     # if csite.callee() changes, it may mean that it is now defined
...     retract_undef = warning_retraction_info([], [mmfunc, csite.callee()], [])
...     try:
...        w = wc_undeffunc.report_return_warning(csite, 'Call to undefined function "{0}"'.format(csite.callee().name()), report_flags.NONE, retract_undef)
...     except result as r:
...        w = None
...        print('Exception encountered while reporting warning:', r)
...     if w is not None:
...        reported_warnings.append(w)
...
Rendering `Call to undefined function' Warning... done
Reporting `Call to undefined function' Warning at C:\alex\test\apitest.cpp:6
>>> reported_warnings
[<cs.warning ...>]
report_return_warning(p, endbox[, flags =  report_flags.NONE])

Report a warning at a point and return the reported warning object.

Parameters:
  • p (point) – The point where the warning occurs.
  • endbox (str) – A short explanation of why the warning has been issued.
  • flags (report_flags) – (optional) report_flags that characterize the report.
Return type:

warning

Returns:

The warning object corresponding to the reported warning.

Raises:
  • result.FILTERED_OUT if the warning was not submitted to the hub because it matched a WARNING_FILTER discard rule in the configuration file.
  • result.TIMEOUT if the time limit specified by configuration file option TIME_LIMIT_RENDER expired.
  • result.NO_SOURCE_CORRESPONDENCE if the warning was not submitted to the hub because no source location for the warning could be determined.
  • result.ELEMENT_ALREADY_PRESENT if the warning was not submitted to the hub because configuration file option REPORT_SIMILAR_WARNINGS is set to No and a similar warning was previously submitted.
  • result.ERROR_INVALID_PHASE_FOR_OPERATION if called from a drop visitor, or your plug-in’s top-level scope.

This creates a single-event warning where the event is an end box.

The warning will be automatically retracted in a subsequent incremental analysis if and only if the compunit containing p has been modified.

There are multiple methods for reporting a warning at a point. See the table above for details.

Always invoke report_return_warning() methods inside a try block.

>>> reported_warnings=[]
>>> wc_undeffunc = analysis.create_warningclass('Call to undefined function', '', 10, warningclass_flags.PADDING, warning_significance.RELIABILITY)
>>> mmfunc = project.current().find_procedure('mymalloc(int)')
>>> csite = mmfunc.call_sites_vector()[0]
>>> if csite.callee().get_kind() == procedure_kind.UNDEFINED:
...     try:
...        w = wc_undeffunc.report_return_warning(csite, 'Call to undefined function "{0}"'.format(csite.callee().name()), report_flags.ALREADY_XML_ENCODED)
...     except result as r:
...        w = None
...        print('Exception encountered while reporting warning:', r)
...     if w is not None:
...        reported_warnings.append(w)
...
Rendering `Call to undefined function' Warning... done
Reporting `Call to undefined function' Warning at C:\alex\test\apitest.cpp:6
>>> reported_warnings
[<cs.warning ...>]
>>> reported_warnings=[]
>>> wc_undeffunc = analysis.create_warningclass('Call to undefined function', '', 10, warningclass_flags.PADDING, warning_significance.RELIABILITY)
>>> mmfunc = project.current().find_procedure('mymalloc(int)')
>>> csite = mmfunc.call_sites_vector()[0]
>>> if csite.callee().get_kind() == procedure_kind.UNDEFINED:
...     try:
...        w = wc_undeffunc.report_return_warning(csite, 'Call to undefined function "{0}"'.format(csite.callee().name()))
...     except result as r:
...        w = None
...        print('Exception encountered while reporting warning:', r)
...     if w is not None:
...        reported_warnings.append(w)
...
Rendering `Call to undefined function' Warning... done
Reporting `Call to undefined function' Warning at C:\alex\test\apitest.cpp:6
>>> reported_warnings
[<cs.warning ...>]
report_return_warning(file, endbox, flags, ri)

Report a warning associated with a file instance, providing retraction information, and return the reported warning object.

Parameters:
Return type:

warning

Returns:

The warning object corresponding to the reported warning.

Raises:

The warning will be automatically retracted in a subsequent incremental analysis if and only if one or more of the conditions expressed in ri is satisfied.

There are multiple methods for reporting a warning associated with a file instance. See the table above for details.

Always invoke report_return_warning() methods inside a try block.

>>> wc_undefcall = analysis.create_warningclass('File contains calls to undefined functions')
>>> cu = project.current().compunits_vector()[0]
>>> cu_callsites = [pt for proc in cu.procedures() for pt in proc.points()
...                 if pt.get_kind() == point_kind.CALL_SITE and pt.callee().get_kind() == procedure_kind.UNDEFINED]
>>> byproc = point_set(cu_callsites).categorize()[0][1]                           # a list of (procedure,point_set) pairs
>>> byproc = [(proc.file_line()[0],proc,callsites) for proc,callsites in byproc]  # a list of (sfileinst,procedure,point_set) triples
>>> reported_warnings=[]
>>> for sfi in set([*zip(*byproc)][0]):                             # the set of all sfileinst  represented in byproc
...     num_undef_calls = sum([len(callsites) for fi,proc,callsites in byproc if sfi==fi])
...     ret = warning_retraction_info([], [], [sfi.get_compunit()])
...     try:
...        w = wc_undefcall.report_return_warning(sfi, 'This file contains {0} calls to undefined functions'.format(str(num_undef_calls)), report_flags.NONE, ret)
...     except result as r:
...        w = None
...        print('Could not report warning', r)
...     if w is not None:
...        reported_warnings.append(w)
...
Rendering `File contains calls to undefined functions' Warning... done
Reporting `File contains calls to undefined functions' Warning at C:\alex\test\apitest.cpp:1
>>> reported_warnings
[<cs.warning ...>]
report_return_warning(file, endbox[, flags =  report_flags.NONE])

Report a warning associated with a file instance and return the reported warning object.

Parameters:
Return type:

warning

Returns:

The warning object corresponding to the reported warning.

Raises:

The warning will be automatically retracted in a subsequent incremental analysis if and only if the compunit containing file has been modified.

There are multiple methods for reporting a warning associated with a file instance. See the table above for details.

Always invoke report_return_warning() methods inside a try block.

>>> wc_undefcall = analysis.create_warningclass('File contains calls to undefined functions')
>>> cu = project.current().compunits_vector()[0]
>>> cu_callsites = [pt for proc in cu.procedures() for pt in proc.points()
...                 if pt.get_kind() == point_kind.CALL_SITE and pt.callee().get_kind() == procedure_kind.UNDEFINED]
>>> byproc = point_set(cu_callsites).categorize()[0][1]                           # a list of (procedure,point_set) pairs
>>> byproc = [(proc.file_line()[0],proc,callsites) for proc,callsites in byproc]  # a list of (sfileinst,procedure,point_set) triples
>>> reported_warnings=[]
>>> for sfi in set([*zip(*byproc)][0]):                             # the set of all sfileinst  represented in byproc
...     num_undef_calls = sum([len(callsites) for fi,proc,callsites in byproc if sfi==fi])
...     try:
...        w = wc_undefcall.report_return_warning(sfi, 'This file contains {0} calls to undefined functions'.format(str(num_undef_calls)), report_flags.NONE)
...     except result as r:
...        w = None
...        print('Could not report warning', r)
...     if w is not None:
...        reported_warnings.append(w)
...
Rendering `File contains calls to undefined functions' Warning... done
Reporting `File contains calls to undefined functions' Warning at C:\alex\test\apitest.cpp:1
>>> reported_warnings
[<cs.warning ...>]
>>> wc_undefcall = analysis.create_warningclass('File contains calls to undefined functions')
>>> cu = project.current().compunits_vector()[0]
>>> cu_callsites = [pt for proc in cu.procedures() for pt in proc.points()
...                 if pt.get_kind() == point_kind.CALL_SITE and pt.callee().get_kind() == procedure_kind.UNDEFINED]
>>> byproc = point_set(cu_callsites).categorize()[0][1]                           # a list of (procedure,point_set) pairs
>>> byproc = [(proc.file_line()[0],proc,callsites) for proc,callsites in byproc]  # a list of (sfileinst,procedure,point_set) triples
>>> reported_warnings=[]
>>> for sfi in set([*zip(*byproc)][0]):                             # the set of all sfileinst  represented in byproc
...     num_undef_calls = sum([len(callsites) for fi,proc,callsites in byproc if sfi==fi])
...     try:
...        w = wc_undefcall.report_return_warning(sfi, 'This file contains {0} calls to undefined functions'.format(str(num_undef_calls)))
...     except result as r:
...        w = None
...        print('Could not report warning', r)
...     if w is not None:
...        reported_warnings.append(w)
...
Rendering `File contains calls to undefined functions' Warning... done
Reporting `File contains calls to undefined functions' Warning at C:\alex\test\apitest.cpp:1
>>> reported_warnings
[<cs.warning ...>]
report_return_warning(file, line, endbox, flags, ri)

Report a warning with a code location, providing retraction information, and return the reported warning object.

Parameters:
  • file (sfileinst) – The file instance ( sfileinst ) containing the warning.
  • line (int) – The line in file on which the warning occurs.
  • endbox (str) – A short explanation of why the warning has been issued.
  • flags (report_flags) – report_flags that characterize the report.
  • ri (warning_retraction_info) – warning_retraction_info describing the circumstances in which the warning should be retracted for subsequent incremental analyses.
Return type:

warning

Returns:

The warning object corresponding to the reported warning.

Raises:

This creates a single-event warning where the event is an end box.

The warning will be automatically retracted in a subsequent incremental analysis if and only if one or more of the conditions expressed in ri is satisfied.

There are multiple methods for reporting a warning with a code location. See the table above for details.

Always invoke report_return_warning() methods inside a try block.

>>> reported_warnings=[]
>>> whoknows_wc = analysis.create_warningclass('Occurrence of whoknows')
>>> q = xr_query()
>>> q.add_term_filter('whoknows')
>>> for t in project.current().token_search(q):
...     # retract if there is a change in any compilation unit containing an instance of the file containing this occurrence
...     ret = warning_retraction_info([], [], [fi.get_compunit() for fi in t.get_file().instances()])
...     try:
...         w = whoknows_wc.report_return_warning(t.get_file().arbitrary_instance(), t.get_line(), 'Token "whoknows" occurs here')
...     except result as r:
...         w = None
...         print('Exception when reporting warning:', r)
...     if w is not None:
...        reported_warnings.append(w)
...
Rendering `Occurrence of whoknows' Warning... done
Reporting `Occurrence of whoknows' Warning at C:\alex\test\apitest.cpp:5
Rendering `Occurrence of whoknows' Warning... done
Reporting `Occurrence of whoknows' Warning at C:\alex\test\apitest.cpp:6
>>> reported_warnings
[<cs.warning ...>, <cs.warning ...>]
report_return_warning(file, line, endbox[, flags =  report_flags.NONE])

Report a warning with a code location and return the reported warning object.

Parameters:
  • file (sfileinst) – The file instance ( sfileinst ) containing the warning.
  • line (int) – The line in file on which the warning occurs.
  • endbox (str) – A short explanation of why the warning has been issued.
  • flags (report_flags) – (optional) report_flags that characterize the report.
Return type:

warning

Returns:

The warning object corresponding to the reported warning.

Raises:

This creates a single-event warning where the event is an end box.

The warning will be automatically retracted in a subsequent incremental analysis if and only if the compunit containing file has been modified.

There are multiple methods for reporting a warning with a code location. See the table above for details.

Always invoke report_return_warning() methods inside a try block.

>>> for t in project.current().token_search(q):
...     try:
...         w = whoknows_wc.report_return_warning(t.get_file().arbitrary_instance(), t.get_line(), 'Token "whoknows" occurs here', report_flags.ALREADY_XML_ENCODED)
...     except result as r:
...         w = None
...         print('Exception when reporting warning:', r)
...     if w is not None:
...        reported_warnings.append(w)
...
Rendering `Occurrence of whoknows' Warning... done
Reporting `Occurrence of whoknows' Warning at C:\alex\test\apitest.cpp:5
Rendering `Occurrence of whoknows' Warning... done
Reporting `Occurrence of whoknows' Warning at C:\alex\test\apitest.cpp:6
>>> reported_warnings
[<cs.warning ...>, <cs.warning ...>]
>>> reported_warnings=[]
>>> whoknows_wc = analysis.create_warningclass('Occurrence of whoknows')
>>> q = xr_query()
>>> q.add_term_filter('whoknows')
>>> for t in project.current().token_search(q):
...     try:
...         w = whoknows_wc.report_return_warning(t.get_file().arbitrary_instance(), t.get_line(), 'Token "whoknows" occurs here')
...     except result as r:
...         w = None
...         print('Exception when reporting warning:', r)
...     if w is not None:
...        reported_warnings.append(w)
...
Rendering `Occurrence of whoknows' Warning... done
Reporting `Occurrence of whoknows' Warning at C:\alex\test\apitest.cpp:5
Rendering `Occurrence of whoknows' Warning... done
Reporting `Occurrence of whoknows' Warning at C:\alex\test\apitest.cpp:6
>>> reported_warnings
[<cs.warning ...>, <cs.warning ...>]
report_return_warning(file, line, proc, endbox, flags, ri)

Report a warning at a span in a specified procedure, providing retraction information, and return the reported warning object.

Parameters:
Return type:

warning

Returns:

The warning object corresponding to the reported warning.

Raises:

The warning will be automatically retracted in a subsequent incremental analysis if and only if one or more of the conditions expressed in ri is satisfied.

There are multiple methods for reporting a warning at a line in a specified procedure. See the table above for details.

Always invoke report_return_warning() methods inside a try block.

>>> reported_warnings=[]
>>> wc = analysis.create_warningclass('Function named "foo"', '', 20, warningclass_flags.NONE, warning_significance.DIAGNOSTIC)
>>> foofn = project.current().find_procedure('foo')
>>> (sfi,ln)=foofn.file_line()
>>> retract = warning_retraction_info([],[],[foofn.get_compunit()])
>>> try:
...     w = wc.report_return_warning(sfi, ln, foofn, 'This function is named "foo". Consider a more meaningful name.', report_flags.NONE, retract)
... except result as r:
...     w = None
...     print('Exception when reporting warning:', r)
...
Rendering `Function named "foo"' Warning... done
Reporting `Function named "foo"' Warning at C:\alex\test\apitest.cpp:32
>>> if w is not None:
...     reported_warnings.append(w)
...
>>> reported_warnings
[<cs.warning ...>]
report_return_warning(file, line, proc, endbox[, flags =  report_flags.NONE])

Report a warning at a span in a specified procedure and return the reported warning object.

Parameters:
  • file (sfileinst) – The file instance ( sfileinst ) containing the warning.
  • line (int) – The line in file on which the warning occurs.
  • proc (procedure) – The procedure in which the warning occurs.
  • endbox (str) – A short explanation of why the warning has been issued.
  • flags (report_flags) – (optional) report_flags that characterize the report.
Return type:

warning

Returns:

The warning object corresponding to the reported warning.

Raises:

The warning will be automatically retracted in a subsequent incremental analysis if and only if the compunit containing file has been modified.

There are multiple methods for reporting a warning at a line in a specified procedure. See the table above for details.

Always invoke report_return_warning() methods inside a try block.

>>> reported_warnings=[]
>>> wc = analysis.create_warningclass('Function named "foo"', '', 20, warningclass_flags.NONE, warning_significance.DIAGNOSTIC)
>>> foofn = project.current().find_procedure('foo')
>>> (sfi,ln)=foofn.file_line()
>>> try:
...     w = wc.report_return_warning(sfi, ln, foofn, 'This function is named "foo". Consider a more meaningful name.', report_flags.ALREADY_XML_ENCODED)
... except result as r:
...     w = None
...     print('Exception when reporting warning:', r)
...
Rendering `Function named "foo"' Warning... done
Reporting `Function named "foo"' Warning at C:\alex\test\apitest.cpp:32
>>> if w is not None:
...     reported_warnings.append(w)
...
>>> reported_warnings
[<cs.warning ...>]
report_return_warning(file, start_line, end_line, start_col, end_col, endbox, flags, ri)

Report a warning with a code location, providing retraction information, and return the reported warning object.

Parameters:
  • file (sfileinst) – The file instance ( sfileinst ) containing the warning.
  • start_line (int) – The line in file on which the warning starts.
  • end_line (int) – The line in file on which the warning ends.
  • start_col (int) – The column on start_line where the warning starts.
  • end_col (int) – The column on end_line where the warning ends.
  • endbox (str) – A short explanation of why the warning has been issued.
  • flags (report_flags) – report_flags that characterize the report.
  • ri (warning_retraction_info) – warning_retraction_info describing the circumstances in which the warning should be retracted for subsequent incremental analyses.
Return type:

warning

Returns:

The warning object corresponding to the reported warning.

Raises:

This creates a single-event warning where the event is an end box.

The warning will be automatically retracted in a subsequent incremental analysis if and only if one or more of the conditions expressed in ri is satisfied.

There are multiple methods for reporting a warning with a code location. See the table above for details.

Always invoke report_return_warning() methods inside a try block.

>>> reported_warnings=[]
>>> proj = project.current()
>>> # given an int_pair_set ips, return a pair of offsets
>>> # denoting the first and last offsets included in ips
>>> def ips_to_span_offsets(ips):
...     sorted_ips = sorted(list(ips), key = lambda pr:pr[0])
...     return (sorted_ips[0][0], sorted_ips[-1][0] + sorted_ips[-1][1])
...
>>> barfn = proj.find_procedure('bar(int, void *, int)')
>>> bar_wc = analysis.create_warningclass('Call to bar', '', 5,
...                                       warningclass_flags.NONE)
>>> for pt in barfn.callers():
...     (sfi,ips) = pt.charpos()
...     (start_offset, end_offset) = ips_to_span_offsets(ips)
...     (sline,scol) = sfi.offset_to_line_column(start_offset)
...     (eline,ecol) = sfi.offset_to_line_column(end_offset)
...     try:
...         w = bar_wc.report_return_warning(sfi, sline, eline, scol, ecol,
...                                          'bar called here',
...                                          report_flags.NONE,
...                                          warning_retraction_info([],[pt.get_procedure()],[]))
...     except result as r:
...         w = None
...         print('Exception when reporting warning:', r)
...     if w is not None:
...         reported_warnings.append(w)
...
Rendering `Call to bar' Warning... done
Reporting `Call to bar' Warning at C:\alex\test\apitest.cpp:35
Rendering `Call to bar' Warning... done
Reporting `Call to bar' Warning at C:\alex\test\apitest.cpp:36
Rendering `Call to bar' Warning... done
Reporting `Call to bar' Warning at C:\alex\test\apitest.cpp:40
Rendering `Call to bar' Warning... done
Reporting `Call to bar' Warning at C:\alex\test\apitest.cpp:14
>>> reported_warnings
[<cs.warning ...>, <cs.warning ...>, <cs.warning ...>, <cs.warning ...>]
report_return_warning(file, start_line, end_line, start_col, end_col, endbox[, flags =  report_flags.NONE])

Report a warning with a code span location and return the reported warning object.

Parameters:
  • file (sfileinst) – The file instance ( sfileinst ) containing the warning.
  • start_line (int) – The line in file on which the warning starts.
  • end_line (int) – The line in file on which the warning ends.
  • start_col (int) – The column on start_line on which the warning starts.
  • end_col (int) – The column on end_line on which the warning ends.
  • endbox (str) – A short explanation of why the warning has been issued.
  • flags (report_flags) – (optional) report_flags that characterize the report.
Return type:

warning

Returns:

The warning object corresponding to the reported warning.

Raises:

This creates a single-event warning where the event is an end box.

The warning will be automatically retracted in a subsequent incremental analysis if and only if the compunit containing file has been modified.

There are multiple methods for reporting a warning with a code span location. See the table above for details.

Always invoke report_return_warning() methods inside a try block.

>>> reported_warnings=[]
>>> proj = project.current()
>>> # given an int_pair_set ips, return a pair of offsets
>>> # denoting the first and last offsets included in ips
>>> def ips_to_span_offsets(ips):
...     sorted_ips = sorted(list(ips), key = lambda pr:pr[0])
...     return (sorted_ips[0][0], sorted_ips[-1][0] + sorted_ips[-1][1])
...
>>> barfn = proj.find_procedure('bar(int, void *, int)')
>>> bar_wc = analysis.create_warningclass('Call to bar', '', 5,
...                                       warningclass_flags.NONE)
>>> for pt in barfn.callers():
...     (sfi,ips) = pt.charpos()
...     (start_offset, end_offset) = ips_to_span_offsets(ips)
...     (sline,scol) = sfi.offset_to_line_column(start_offset)
...     (eline,ecol) = sfi.offset_to_line_column(end_offset)
...     try:
...         w = bar_wc.report_return_warning(sfi, sline, eline, scol, ecol,
...                                          'bar called here',
...                                          report_flags.NONE)
...     except result as r:
...         w = None
...         print('Exception when reporting warning:', r)
...     if w is not None:
...         reported_warnings.append(w)
...
Rendering `Call to bar' Warning... done
Reporting `Call to bar' Warning at C:\alex\test\apitest.cpp:35
Rendering `Call to bar' Warning... done
Reporting `Call to bar' Warning at C:\alex\test\apitest.cpp:36
Rendering `Call to bar' Warning... done
Reporting `Call to bar' Warning at C:\alex\test\apitest.cpp:40
Rendering `Call to bar' Warning... done
Reporting `Call to bar' Warning at C:\alex\test\apitest.cpp:14
>>> reported_warnings
[<cs.warning ...>, <cs.warning ...>, <cs.warning ...>, <cs.warning ...>]
>>> reported_warnings=[]
>>> proj = project.current()
>>> # given an int_pair_set ips, return a pair of offsets
>>> # denoting the first and last offsets included in ips
>>> def ips_to_span_offsets(ips):
...     sorted_ips = sorted(list(ips), key = lambda pr:pr[0])
...     return (sorted_ips[0][0], sorted_ips[-1][0] + sorted_ips[-1][1])
...
>>> barfn = proj.find_procedure('bar(int, void *, int)')
>>> bar_wc = analysis.create_warningclass('Call to bar', '', 5,
...                                       warningclass_flags.NONE)
>>> for pt in barfn.callers():
...     (sfi,ips) = pt.charpos()
...     (start_offset, end_offset) = ips_to_span_offsets(ips)
...     (sline,scol) = sfi.offset_to_line_column(start_offset)
...     (eline,ecol) = sfi.offset_to_line_column(end_offset)
...     try:
...         w = bar_wc.report_return_warning(sfi,sline,eline,scol,ecol,
...                                          'bar called here')
...     except result as r:
...         w = None
...         print('Exception when reporting warning:', r)
...     if w is not None:
...         reported_warnings.append(w)
...
Rendering `Call to bar' Warning... done
Reporting `Call to bar' Warning at C:\alex\test\apitest.cpp:35
Rendering `Call to bar' Warning... done
Reporting `Call to bar' Warning at C:\alex\test\apitest.cpp:36
Rendering `Call to bar' Warning... done
Reporting `Call to bar' Warning at C:\alex\test\apitest.cpp:40
Rendering `Call to bar' Warning... done
Reporting `Call to bar' Warning at C:\alex\test\apitest.cpp:14
>>> reported_warnings
[<cs.warning ...>, <cs.warning ...>, <cs.warning ...>, <cs.warning ...>]
report_return_warning(file, start_line, end_line, start_col, end_col, proc, endbox, flags, ri)

Report a warning at a span in a specified procedure, providing retraction information, and return the reported warning object.

Parameters:
  • file (sfileinst) – The file instance ( sfileinst ) containing the warning.
  • start_line (int) – The line in file on which the warning starts.
  • end_line (int) – The line in file on which the warning ends.
  • start_col (int) – The column on start_line on which the warning starts.
  • end_col (int) – The column on end_line on which the warning ends.
  • proc (procedure) – The procedure in which the warning occurs.
  • endbox (str) – A short explanation of why the warning has been issued.
  • flags (report_flags) – report_flags that characterize the report.
  • ri (warning_retraction_info) – warning_retraction_info describing the circumstances in which the warning should be retracted for subsequent incremental analyses.
Return type:

warning

Returns:

The warning object corresponding to the reported warning.

Raises:
  • result.ERROR_INVALID_ARGUMENT if warnings of this class have associated paths (and should therefore be reported with those paths).
  • OverflowError
  • result.FILTERED_OUT if the warning was not submitted to the hub because it matched a WARNING_FILTER discard rule in the configuration file.
  • result.NO_SOURCE_CORRESPONDENCE if the warning was not submitted to the hub because no source location for the warning could be determined.
  • result.ERROR_INVALID_PHASE_FOR_OPERATION if called from a drop visitor, or your plug-in’s top-level scope.
  • result.TIMEOUT if the time limit specified by configuration file option TIME_LIMIT_RENDER expired.
  • result.ELEMENT_ALREADY_PRESENT if the warning was not submitted to the hub because configuration file option REPORT_SIMILAR_WARNINGS is set to No and a similar warning was previously submitted.

The warning will be automatically retracted in a subsequent incremental analysis if and only if one or more of the conditions expressed in ri is satisfied.

There are multiple methods for reporting a warning at a line in a specified procedure. See the table above for details.

Always invoke report_return_warning() methods inside a try block.

>>> reported_warnings=[]
>>> proj = project.current()
>>> # given an int_pair_set ips, return a pair of offsets
>>> # denoting the first and last offsets included in ips
>>> def ips_to_span_offsets(ips):
...     sorted_ips = sorted(list(ips), key = lambda pr:pr[0])
...     return (sorted_ips[0][0], sorted_ips[-1][0] + sorted_ips[-1][1])
...
>>> barfn = proj.find_procedure('bar(int, void *, int)')
>>> bar_wc = analysis.create_warningclass('Call to bar', '', 5,
...                                       warningclass_flags.NONE)
>>> for pt in barfn.callers():
...     (sfi,ips) = pt.charpos()
...     (start_offset, end_offset) = ips_to_span_offsets(ips)
...     (sline,scol) = sfi.offset_to_line_column(start_offset)
...     (eline,ecol) = sfi.offset_to_line_column(end_offset)
...     try:
...         w = bar_wc.report_return_warning(sfi, sline, eline, scol, ecol,
...                                          pt.get_procedure(),
...                                          'bar called here',
...                                          report_flags.NONE,
...                                          warning_retraction_info([],[pt.get_procedure()],[]))
...     except result as r:
...         w = None
...         print('Exception when reporting warning:', r)
...     if w is not None:
...         reported_warnings.append(w)
...
Rendering `Call to bar' Warning... done
Reporting `Call to bar' Warning at C:\alex\test\apitest.cpp:35
Rendering `Call to bar' Warning... done
Reporting `Call to bar' Warning at C:\alex\test\apitest.cpp:36
Rendering `Call to bar' Warning... done
Reporting `Call to bar' Warning at C:\alex\test\apitest.cpp:40
Rendering `Call to bar' Warning... done
Reporting `Call to bar' Warning at C:\alex\test\apitest.cpp:14
>>> reported_warnings
[<cs.warning ...>, <cs.warning ...>, <cs.warning ...>, <cs.warning ...>]
report_return_warning(file, start_line, end_line, start_col, end_col, proc, endbox[, flags =  report_flags.NONE])

Report a warning at a span in a specified procedure and return the reported warning object.

Parameters:
  • file (sfileinst) – The file instance ( sfileinst ) containing the warning.
  • start_line (int) – The line in file on which the warning starts.
  • end_line (int) – The line in file on which the warning ends.
  • start_col (int) – The column on start_line on which the warning starts.
  • end_col (int) – The column on end_line on which the warning ends.
  • proc (procedure) – The procedure in which the warning occurs.
  • endbox (str) – A short explanation of why the warning has been issued.
  • flags (report_flags) – (optional) report_flags that characterize the report.
Return type:

warning

Returns:

The warning object corresponding to the reported warning.

Raises:

The warning will be automatically retracted in a subsequent incremental analysis if and only if the compunit containing file has been modified.

There are multiple methods for reporting a warning at a line in a specified procedure. See the table above for details.

Always invoke report_return_warning() methods inside a try block.

>>> reported_warnings=[]
>>> proj = project.current()
>>> # given an int_pair_set ips, return a pair of offsets
>>> # denoting the first and last offsets included in ips
>>> def ips_to_span_offsets(ips):
...      sorted_ips = sorted(list(ips), key = lambda pr:pr[0])
...      return (sorted_ips[0][0], sorted_ips[-1][0] + sorted_ips[-1][1])
...
>>> barfn = proj.find_procedure('bar(int, void *, int)')
>>> bar_wc = analysis.create_warningclass('Call to bar', '', 5,
...                                        warningclass_flags.NONE)
>>> for pt in barfn.callers():
...      (sfi,ips) = pt.charpos()
...      (start_offset, end_offset) = ips_to_span_offsets(ips)
...      (sline,scol) = sfi.offset_to_line_column(start_offset)
...      (eline,ecol) = sfi.offset_to_line_column(end_offset)
...      try:
...          w = bar_wc.report_return_warning(sfi, sline, eline, scol, ecol,
...                                           pt.get_procedure(),
...                                           'bar called here',
...                                           report_flags.NONE)
...      except result as r:
...          w = None
...          print('Exception when reporting warning:', r)
...      if w is not None:
...          reported_warnings.append(w)
...
Rendering `Call to bar' Warning... done
Reporting `Call to bar' Warning at C:\alex\test\apitest.cpp:35
Rendering `Call to bar' Warning... done
Reporting `Call to bar' Warning at C:\alex\test\apitest.cpp:36
Rendering `Call to bar' Warning... done
Reporting `Call to bar' Warning at C:\alex\test\apitest.cpp:40
Rendering `Call to bar' Warning... done
Reporting `Call to bar' Warning at C:\alex\test\apitest.cpp:14
>>> reported_warnings
[<cs.warning ...>, <cs.warning ...>, <cs.warning ...>, <cs.warning ...>]
>>> reported_warnings=[]
>>> proj = project.current()
>>> # given an int_pair_set ips, return a pair of offsets
>>> # denoting the first and last offsets included in ips
>>> def ips_to_span_offsets(ips):
...      sorted_ips = sorted(list(ips), key = lambda pr:pr[0])
...      return (sorted_ips[0][0], sorted_ips[-1][0] + sorted_ips[-1][1])
...
>>> barfn = proj.find_procedure('bar(int, void *, int)')
>>> bar_wc = analysis.create_warningclass('Call to bar', '', 5,
...                                        warningclass_flags.NONE)
>>> for pt in barfn.callers():
...      (sfi,ips) = pt.charpos()
...      (start_offset, end_offset) = ips_to_span_offsets(ips)
...      (sline,scol) = sfi.offset_to_line_column(start_offset)
...      (eline,ecol) = sfi.offset_to_line_column(end_offset)
...      try:
...          w = bar_wc.report_return_warning(sfi, sline, eline, scol, ecol,
...                                           pt.get_procedure(),
...                                           'bar called here')
...      except result as r:
...          w = None
...          print('Exception when reporting warning:', r)
...      if w is not None:
...          reported_warnings.append(w)
...
Rendering `Call to bar' Warning... done
Reporting `Call to bar' Warning at C:\alex\test\apitest.cpp:35
Rendering `Call to bar' Warning... done
Reporting `Call to bar' Warning at C:\alex\test\apitest.cpp:36
Rendering `Call to bar' Warning... done
Reporting `Call to bar' Warning at C:\alex\test\apitest.cpp:40
Rendering `Call to bar' Warning... done
Reporting `Call to bar' Warning at C:\alex\test\apitest.cpp:14
>>> reported_warnings
[<cs.warning ...>, <cs.warning ...>, <cs.warning ...>, <cs.warning ...>]
report_return_warning(p)

Report a warning with a step path and return the reported warning object.

Parameters:

p (step_path) – The step path ( step_path ) associated with the warning.

Return type:

warning

Returns:

The warning object corresponding to the reported warning.

Raises:
  • result.FILTERED_OUT if the warning was not submitted to the hub because it matched a WARNING_FILTER discard rule in the configuration file.
  • result.TIMEOUT if the time limit specified by configuration file option TIME_LIMIT_RENDER expired.
  • result.NO_SOURCE_CORRESPONDENCE if the warning was not submitted to the hub because no source location for the warning could be determined.
  • result.ELEMENT_ALREADY_PRESENT if the warning was not submitted to the hub because configuration file option REPORT_SIMILAR_WARNINGS is set to No and a similar warning was previously submitted.
  • result.ERROR_INVALID_PHASE_FOR_OPERATION if called from a drop visitor, or your plug-in’s top-level scope.

The warning will be automatically retracted in a subsequent incremental analysis if and only if the compunit containing the first point in p has been modified.

There are multiple methods for reporting a warning with a step path. See the table above for details.

Always invoke report_return_warning() methods inside a try block.

#      software is retained by CodeSecure, Inc.
#

# callbar_plugin.py
#
# A simple step visitor with examples of the different functions for
# reporting warnings with step paths. You can copy and install this
# as a CodeSonar plug-in if you want to see its results on the apitest
# project.

import cs

# These warning classes will all be reported under the same
# conditions, but have different names so you can distinguish them in
# the analysis results.
bar_wc = cs.analysis.create_warningclass('bar() called')  
bar_retr_wc = cs.analysis.create_warningclass('bar() called (with retraction info)')  
bar_retn_wc = cs.analysis.create_warningclass('bar() called (warning returned)')  
bar_retn_retr_wc = cs.analysis.create_warningclass('bar() called (with retraction info, warning returned)')  

class bar_called(cs.step_state):   
    def __init__(self):
        super(bar_called, self).__init__()
        
    def copy(self):
        return bar_called()

    def transition(self, srcpt, edgelabel, destpt, tosrc_xform, edge_xform, tosrc_path):
        try:
            if srcpt.get_kind()==cs.point_kind.CALL_SITE and srcpt.callee().name()=='bar':
               retr_info = cs.warning_retraction_info([], [srcpt.get_procedure()], [])
               bar_wc.report(tosrc_path)
               bar_retr_wc.report(tosrc_path, retr_info)
               w1 = bar_retn_wc.report_return_warning(tosrc_path)
               w2 = bar_retn_retr_wc.report_return_warning(tosrc_path, retr_info)
               # do something with w1 and w2
        except cs.result as r:
            pass

cs.analysis.add_step_bottom_up_visitor(bar_called())
report_return_warning(p, ri)

Report a warning with a step path, providing retraction information, and return the reported warning object.

Parameters:
Return type:

warning

Returns:

The warning object corresponding to the reported warning.

Raises:
  • result.FILTERED_OUT if the warning was not submitted to the hub because it matched a WARNING_FILTER discard rule in the configuration file.
  • result.TIMEOUT if the time limit specified by configuration file option TIME_LIMIT_RENDER expired.
  • result.NO_SOURCE_CORRESPONDENCE if the warning was not submitted to the hub because no source location for the warning could be determined.
  • result.ELEMENT_ALREADY_PRESENT if the warning was not submitted to the hub because configuration file option REPORT_SIMILAR_WARNINGS is set to No and a similar warning was previously submitted.
  • result.ERROR_INVALID_PHASE_FOR_OPERATION if called from a drop visitor, or your plug-in’s top-level scope.

The warning will be automatically retracted in a subsequent incremental analysis if and only if one or more of the conditions expressed in ri is satisfied.

There are multiple methods for reporting a warning with a step path. See the table above for details.

Always invoke report_return_warning() methods inside a try block.

#      software is retained by CodeSecure, Inc.
#

# callbar_plugin.py
#
# A simple step visitor with examples of the different functions for
# reporting warnings with step paths. You can copy and install this
# as a CodeSonar plug-in if you want to see its results on the apitest
# project.

import cs

# These warning classes will all be reported under the same
# conditions, but have different names so you can distinguish them in
# the analysis results.
bar_wc = cs.analysis.create_warningclass('bar() called')  
bar_retr_wc = cs.analysis.create_warningclass('bar() called (with retraction info)')  
bar_retn_wc = cs.analysis.create_warningclass('bar() called (warning returned)')  
bar_retn_retr_wc = cs.analysis.create_warningclass('bar() called (with retraction info, warning returned)')  

class bar_called(cs.step_state):   
    def __init__(self):
        super(bar_called, self).__init__()
        
    def copy(self):
        return bar_called()

    def transition(self, srcpt, edgelabel, destpt, tosrc_xform, edge_xform, tosrc_path):
        try:
            if srcpt.get_kind()==cs.point_kind.CALL_SITE and srcpt.callee().name()=='bar':
               retr_info = cs.warning_retraction_info([], [srcpt.get_procedure()], [])
               bar_wc.report(tosrc_path)
               bar_retr_wc.report(tosrc_path, retr_info)
               w1 = bar_retn_wc.report_return_warning(tosrc_path)
               w2 = bar_retn_retr_wc.report_return_warning(tosrc_path, retr_info)
               # do something with w1 and w2
        except cs.result as r:
            pass

cs.analysis.add_step_bottom_up_visitor(bar_called())