Skip to content

Commit

Permalink
qapi: Reject blank 'if' conditions in addition to empty ones
Browse files Browse the repository at this point in the history
"'if': 'COND'" generates "#if COND".  We reject empty COND because it
won't compile.  Blank COND won't compile any better, so reject that,
too.

Signed-off-by: Markus Armbruster <armbru@redhat.com>
Message-Id: <20190914153506.2151-12-armbru@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
  • Loading branch information
Markus Armbruster committed Sep 24, 2019
1 parent 887a206 commit c2c7065
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 4 deletions.
5 changes: 3 additions & 2 deletions scripts/qapi/common.py
Expand Up @@ -742,8 +742,9 @@ def check_if_str(ifcond, info):
if not isinstance(ifcond, str):
raise QAPISemError(
info, "'if' condition must be a string or a list of strings")
if ifcond == '':
raise QAPISemError(info, "'if' condition '' makes no sense")
if ifcond.strip() == '':
raise QAPISemError(info, "'if' condition '%s' makes no sense"
% ifcond)

ifcond = expr.get('if')
if ifcond is None:
Expand Down
2 changes: 1 addition & 1 deletion tests/qapi-schema/bad-if-list.err
@@ -1 +1 @@
tests/qapi-schema/bad-if-list.json:2: 'if' condition '' makes no sense
tests/qapi-schema/bad-if-list.json:2: 'if' condition ' ' makes no sense
2 changes: 1 addition & 1 deletion tests/qapi-schema/bad-if-list.json
@@ -1,3 +1,3 @@
# check invalid 'if' content
{ 'struct': 'TestIfStruct', 'data': { 'foo': 'int' },
'if': ['foo', ''] }
'if': ['foo', ' '] }

0 comments on commit c2c7065

Please sign in to comment.