Permalink
Browse files

Avoid walking off array if given a negative value for array size.

Obviously, a negative size is bogus, but we want apitrace to be robust
enough to capture even bogus usage of the API, (so that the user can
investigate and fix the bogosity in the application).

In this case, if the user specifies a negative size for an array,
simply don't write anything out for the array content.

Signed-off-by: José Fonseca <jose.r.fonseca@gmail.com>
  • Loading branch information...
cworth-gh authored and jrfonseca committed Jun 4, 2012
1 parent 8ac8b6b commit 614174444ce27a22f25e08a50cca3af5d3d07bae
Showing with 1 addition and 1 deletion.
  1. +1 −1 wrappers/trace.py
View
@@ -187,7 +187,7 @@ def visitArray(self, array, instance):
length = '_c' + array.type.tag
index = '_i' + array.type.tag
print ' if (%s) {' % instance
- print ' size_t %s = %s;' % (length, array.length)
+ print ' size_t %s = %s > 0 ? %s : 0;' % (length, array.length, array.length)
print ' trace::localWriter.beginArray(%s);' % length
print ' for (size_t %s = 0; %s < %s; ++%s) {' % (index, index, length, index)
print ' trace::localWriter.beginElement();'

0 comments on commit 6141744

Please sign in to comment.