Commit 5c402339 authored by Maxime Perrotin's avatar Maxime Perrotin
Browse files

Check timer parameters (range check)

parent 927a5b69
......@@ -135,6 +135,9 @@ The background pattern was downloaded from www.subtlepatterns.com
Changelog
=========
2.0.14 (06/2018)
- fix numerical checks when setting timer parameters
2.0.13 (06/2018)
- Add taste-compatible cache mechanism when calling asn1scc
......
......@@ -86,6 +86,9 @@ TMPVAR = 0 # type: int
INTEGER = type('IntegerType', (object,), {'kind': 'IntegerType',
'Min': str(-(2 ** 63)),
'Max': str(2 ** 63 - 1)})
UNSIGNED = type('IntegerType', (object,), {'kind': 'IntegerType',
'Min': "0",
'Max': str(2 ** 64 - 1)})
INT32 = type('Integer32Type', (object,), {'kind': 'Integer32Type',
'Min': '-2147483648',
'Max': '2147483647'})
......@@ -122,7 +125,7 @@ SPECIAL_OPERATORS = {
'reset_timer': [{'type': TIMER, 'direction': 'in'}],
'round': [{'type': REAL, 'direction': 'in'}],
'set_timer': [
{'type': INTEGER, 'direction': 'in'},
{'type': UNSIGNED, 'direction': 'in'},
{'type': TIMER, 'direction': 'in'}
],
'sin': [{'type': REAL, 'direction': 'in'}],
......@@ -528,13 +531,17 @@ def check_call(name, params, context):
expr.right = param
try:
basic_left = find_basic_type(expr.left.exprType)
basic_right = find_basic_type(expr.right.exprType)
#print getattr(basic_left, "Min", 0), getattr(basic_right, "Min", 0)
warnings.extend(fix_expression_types(expr, context))
params[idx] = expr.right
except TypeError:
except TypeError as err:
expected = type_name(sign[idx]['type'])
received = type_name(expr.right.exprType)
raise TypeError('Expected type {} in call to {} ({} received)'.
format(expected, name, received))
raise TypeError('In call to {}: Type of parameter {} is incorrect'
' ({}) - {}'
.format(name, idx+1, received, str(err)))
if (warnings):
expected = type_name(sign[idx]['type'])
received = type_name(expr.right.exprType)
......@@ -912,7 +919,6 @@ def compare_types(type_a, type_b): # type -> [warnings]
return warnings
# Check if both types have basic compatibility
if type_a.kind == type_b.kind:
if type_a.kind == 'SequenceOfType':
if mismatch:
......@@ -935,12 +941,13 @@ def compare_types(type_a, type_b): # type -> [warnings]
# TODO: Check that OctetString types have compatible range
elif type_a.kind == 'SequenceType' and mismatch:
raise TypeError(mismatch)
elif type_a.kind == 'IntegerType' and mismatch:
elif type_a.kind == 'IntegerType':
# Detect Signed/Unsigned type mismatch
min_a, min_b = float(type_a.Min), float(type_b.Min)
if (min_a >= 0) != (min_b >= 0):
raise TypeError(mismatch + "(signed vs unsigned type)")
else:
raise TypeError("Signed vs Unsigned type mismatch " +
mismatch)
elif mismatch:
warnings.append(mismatch)
elif mismatch:
warnings.append(mismatch)
......
......@@ -141,7 +141,7 @@ except ImportError:
__all__ = ['opengeode', 'SDL_Scene', 'SDL_View', 'parse']
__version__ = '2.0.13'
__version__ = '2.0.14'
if hasattr(sys, 'frozen'):
# Detect if we are running on Windows (py2exe-generated)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment