On 04/29/2014 03:44 AM, Fam Zheng wrote: > This allows giving decimal constants in the schema as expr. > > Signed-off-by: Fam Zheng <f...@redhat.com> > --- > scripts/qapi.py | 15 +++++++++++++-- > 1 file changed, 13 insertions(+), 2 deletions(-) > > diff --git a/scripts/qapi.py b/scripts/qapi.py > index b474c39..6022de5 100644 > --- a/scripts/qapi.py > +++ b/scripts/qapi.py > @@ -108,6 +108,14 @@ class QAPISchema: > return > else: > string += ch > + elif self.tok in "123456789": > + self.val = int(self.tok) > + while True: > + ch = self.src[self.cursor] > + if ch not in "1234567890": > + return > + self.val = self.val * 10 + int(ch) > + self.cursor += 1
What does this do on integer overflow? Should you validate that the result fits in [u]int64_t? Should you allow for a leading '-' sign for a default of a negative number? You have forbidden '0' as a valid number (although you correctly forbid '00' and any non-zero number with a leading 0, which matches JSON restrictions). > - if not self.tok in [ '{', '[', "'" ]: > - raise QAPISchemaError(self, 'Expected "{", "[", "]" or string') > + if not self.tok in "{['123456789": > + raise QAPISchemaError(self, 'Expected "{", "[", "]", string or > number') Again, this forbids the use of '0' as a default. -- Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
signature.asc
Description: OpenPGP digital signature