tools/generate-wire.py: don't allocate on unknown names.

This introduces a potential leak; use a static buffer.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
Rusty Russell 2017-01-10 15:20:20 +10:30
parent 1ba7f59d31
commit 2b8c7cc840
1 changed files with 6 additions and 1 deletions

View File

@ -345,6 +345,7 @@ else:
print('#include <{}>\n'
'#include <ccan/mem/mem.h>\n'
'#include <ccan/tal/str/str.h>\n'
'#include <stdio.h>\n'
''.format(options.headerfilename))
# Maps message names to messages
@ -403,11 +404,15 @@ if options.header:
else:
print('const char *{}_name(int e)'.format(options.enumname))
print('{{\n'
'\tstatic char invalidbuf[sizeof("INVALID ") + STR_MAX_CHARS(e)];\n'
'\n'
'\tswitch ((enum {})e) {{'.format(options.enumname));
for m in messages:
print('\tcase {0}: return "{0}";'.format(m.enum.name))
print('\t}\n'
'\treturn tal_fmt(NULL, "**INVALID** %i", e);\n'
'\n'
'\tsprintf(invalidbuf, "INVALID %i", e);\n'
'\treturn invalidbuf;\n'
'}\n'
'')