From 2b8c7cc840f4d9910c2a19a45cf631312b3bad1d Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Tue, 10 Jan 2017 15:20:20 +1030 Subject: [PATCH] tools/generate-wire.py: don't allocate on unknown names. This introduces a potential leak; use a static buffer. Signed-off-by: Rusty Russell --- tools/generate-wire.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/tools/generate-wire.py b/tools/generate-wire.py index 2e12fcbb5..ea0812168 100755 --- a/tools/generate-wire.py +++ b/tools/generate-wire.py @@ -345,6 +345,7 @@ else: print('#include <{}>\n' '#include \n' '#include \n' + '#include \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' '')