Skip to content

Commit af51985

Browse files
committed
Fix crash when specifiying -M and -A at once
Flags --asm and --mmap are incompatible. The compiler should exit gracefully.
1 parent 59ef613 commit af51985

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

tests/functional/test_cmdline.txt

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
>>> from test_ import process_file
2+
>>> import os
3+
>>> os.environ['COLUMNS'] = '80'
4+
5+
>>> process_file('arrbase1.bas', ['-q', '-S', '-O --asm', '-O --mmap arrbase1.map'])
6+
usage: zxb [-h] [-d] [-O OPTIMIZE] [-o OUTPUT_FILE] [-T] [-t] [-B] [-a] [-A]
7+
[-S ORG] [-e STDERR] [--array-base ARRAY_BASE]
8+
[--string-base STRING_BASE] [-Z] [-H HEAP_SIZE] [--debug-memory]
9+
[--debug-array] [--strict-bool] [--enable-break] [-E] [--explicit]
10+
[-D DEFINES] [-M MEMORY_MAP] [-i] [-I INCLUDE_PATH] [--strict]
11+
[--headerless] [--version] [--parse-only]
12+
[--append-binary APPEND_BINARY]
13+
[--append-headless-binary APPEND_HEADLESS_BINARY]
14+
PROGRAM
15+
zxb: error: Option --asm and --mmap cannot be used together

zxb.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,10 @@ def main(args=None):
209209
parser.error('Option --append-binary needs either --tap or --tzx')
210210
return 5
211211

212+
if options.asm and options.memory_map:
213+
parser.error('Option --asm and --mmap cannot be used together')
214+
return 6
215+
212216
OPTIONS.use_loader.value = options.basic
213217
OPTIONS.autorun.value = options.autorun
214218

@@ -345,8 +349,9 @@ def main(args=None):
345349
return 5 # Error in assembly
346350

347351
if OPTIONS.memory_map.value:
348-
with open_file(OPTIONS.memory_map.value, 'wt', 'utf-8') as f:
349-
f.write(asmparse.MEMORY.memory_map)
352+
if asmparse.MEMORY is not None:
353+
with open_file(OPTIONS.memory_map.value, 'wt', 'utf-8') as f:
354+
f.write(asmparse.MEMORY.memory_map)
350355

351356
return gl.has_errors # Exit success
352357

0 commit comments

Comments
 (0)