Skip to content

Commit ec206d6

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 ec206d6

File tree

2 files changed

+23
-2
lines changed

2 files changed

+23
-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: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import os
99
import re
1010
import argparse
11+
import textwrap
1112

1213
from six import StringIO
1314

@@ -209,6 +210,10 @@ def main(args=None):
209210
parser.error('Option --append-binary needs either --tap or --tzx')
210211
return 5
211212

213+
if options.asm and options.memory_map:
214+
parser.error('Option --asm and --mmap cannot be used together')
215+
return 6
216+
212217
OPTIONS.use_loader.value = options.basic
213218
OPTIONS.autorun.value = options.autorun
214219

@@ -345,8 +350,9 @@ def main(args=None):
345350
return 5 # Error in assembly
346351

347352
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)
353+
if asmparse.MEMORY is not None:
354+
with open_file(OPTIONS.memory_map.value, 'wt', 'utf-8') as f:
355+
f.write(asmparse.MEMORY.memory_map)
350356

351357
return gl.has_errors # Exit success
352358

0 commit comments

Comments
 (0)