Skip to content

Commit

Permalink
use ast.literal_eval instead of eval (#73)
Browse files Browse the repository at this point in the history
* Make syntax check for bool constant stricter

* Use ast.literal_eval()

* Use ternary expression to return True/False
  • Loading branch information
akio authored and dirk-thomas committed Mar 21, 2018
1 parent cb02cec commit 3cea1fe
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/genmsg/msg_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
possible layouts.
"""

import ast
import os
import sys

Expand Down Expand Up @@ -181,8 +182,7 @@ def convert_constant_value(field_type, val):
raise InvalidMsgSpec("cannot coerce [%s] to %s (out of bounds)"%(val, field_type))
return val
elif field_type == 'bool':
# TODO: need to nail down constant spec for bool
return True if eval(val) else False
return True if ast.literal_eval(val) else False
raise InvalidMsgSpec("invalid constant type: [%s]"%field_type)

def _load_constant_line(orig_line):
Expand Down

0 comments on commit 3cea1fe

Please sign in to comment.