domato
domato copied to clipboard
fix: fix context shallow copy
Classic python object shallow-copy problem.
context = {
'lastvar': last_var,
'lines': [],
'variables': {},
'interesting_lines': [],
'force_var_reuse': False
}
...
while len(context['lines']) < num_lines:
tmp_context = context.copy()
try:
if (random.random() < self._interesting_line_prob) and (len(tmp_context['interesting_lines']) > 0):
tmp_context['force_var_reuse'] = True
lineno = random.choice(tmp_context['interesting_lines'])
else:
lineno = random.choice(self._all_nonhelper_lines)
creator = self._creators['line'][lineno]
self._expand_rule('line', creator, tmp_context, 0, False)
context = tmp_context
except RecursionError as e:
print('Warning: ' + str(e))
When RecursionError
is triggered, some of the generated lines are retained in the original context.
This can lead to some unintended behavior, such as variable redefinition.