From db3c67727ea1dc2a6d182b5e622e94795b2b8f3b Mon Sep 17 00:00:00 2001 From: Tony Garnock-Jones Date: Tue, 20 Apr 2010 18:20:28 +1200 Subject: Only allocate and check if we would ask for more than zero bytes --- librabbitmq/codegen.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/librabbitmq/codegen.py b/librabbitmq/codegen.py index 7683783..7aea9f4 100644 --- a/librabbitmq/codegen.py +++ b/librabbitmq/codegen.py @@ -167,9 +167,12 @@ def genErl(spec): def genDecodeMethodFields(m): print " case %s: {" % (m.defName(),) - print " %s *m = (%s *) amqp_pool_alloc(pool, sizeof(%s));" % \ - (m.structName(), m.structName(), m.structName()) - print " if (m == NULL) { return -ENOMEM; }" + if m.arguments: + print " %s *m = (%s *) amqp_pool_alloc(pool, sizeof(%s));" % \ + (m.structName(), m.structName(), m.structName()) + print " if (m == NULL) { return -ENOMEM; }" + else: + print " %s *m = NULL; /* no fields */" % (m.structName(),) bitindex = None for f in m.arguments: if spec.resolveDomain(f.domain) == 'bit': -- cgit v1.2.1