From: Pasi Kallinen Date: Fri, 20 Nov 2015 10:27:46 +0000 (+0200) Subject: Fix segfault if lev_comp could not alloc memory for opcode X-Git-Tag: NetHack-3.6.0_RC01~41 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=9518e74c93e08f9c7dcc4512ddeb3f3329bb01c0;p=nethack Fix segfault if lev_comp could not alloc memory for opcode --- diff --git a/util/lev_main.c b/util/lev_main.c index f17d9c416..aefe18ae4 100644 --- a/util/lev_main.c +++ b/util/lev_main.c @@ -1294,11 +1294,13 @@ genericptr_t dat; lc_error("Unknown opcode '%d'", opc); tmp = (_opcode *) alloc(sizeof(_opcode) * (nop + 1)); - if (sp->opcodes && nop) { + if (sp->opcodes && nop && tmp) { (void) memcpy(tmp, sp->opcodes, sizeof(_opcode) * nop); free(sp->opcodes); - } else if (!tmp) + } else if (!tmp) { lc_error("Could not alloc opcode space"); + return; + } sp->opcodes = tmp;