spasm-ng
spasm-ng copied to clipboard
_strdup(NULL) in SetLastSPASMProblem when coming from write_labels
On the latest source as of this date, calling spasm with -L
crashes with a segfault on:
lpErr->lpszFileName = _strdup(curr_input_file);
. That's on errors.cpp:326
I've tried tracing the problem a bit, and it looks like curr_input_file
is freed and set to NULL in write_file
(export.cpp:192-193), and nothing else after that.
So, when/if SetLastSPASMProblem
is called later, it crashes.
Backtrace if you're interested:
* thread #1: tid = 0x8c5e2f, 0x00007fff8cd82152 libsystem_c.dylib`strlen + 18, queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=1, address=0x0)
frame #0: 0x00007fff8cd82152 libsystem_c.dylib`strlen + 18
frame #1: 0x00007fff8cddcb79 libsystem_c.dylib`strdup + 18
* frame #2: 0x000000010000c6b4 spasm`SetLastSPASMProblem(dwErrorCode=261, fIsWarning=false, valist=0x00007fff5fbfef20) + 132 at errors.cpp:326
frame #3: 0x000000010000ca7a spasm`SetLastSPASMError(dwErrorCode=261) + 362 at errors.cpp:382
frame #4: 0x00000001000066e7 spasm`parse_single_num(expr=".end", value=0x00007fff5fbff2ec) + 3447 at parser.cpp:450
frame #5: 0x0000000100004f9f spasm`parse_num_full(expr=".end", value=0x00007fff5fbff37c, depth=0) + 447 at parser.cpp:548
frame #6: 0x0000000100004d9f spasm`parse_num(expr=" .end", value=0x00007fff5fbff37c) + 63 at parser.cpp:120
frame #7: 0x0000000100015339 spasm`write_defines_callback(define=0x0000000100600280, label_list=0x00007fff5fbff5a0) + 73 at storage.cpp:109
frame #8: 0x0000000100002129 spasm`hash_enum(ht=0x0000000100102d10, enum_callback=(spasm`write_defines_callback(define*, _list*) at storage.cpp:101), arg=0x00007fff5fbff5a0)(void*, void*), void*) + 681 at hash.cpp:64
frame #9: 0x000000010001517f spasm`write_labels(filename="/Users/adriweb/Downloads/TI/z80_ez80/helloworld.lab") + 175 at storage.cpp:62
frame #10: 0x000000010000b0d4 spasm`run_assembly() + 1524 at main.cpp:187
frame #11: 0x000000010000ba9b spasm`main(argc=5, argv=0x00007fff5fbff8c0) + 2171 at main.cpp:436
frame #12: 0x00007fff911155ad libdyld.dylib`start + 1