mirror of
https://github.com/netwide-assembler/nasm
synced 2026-08-26 16:23:04 -04:00
parser.c: Fix issue #182 - no warning when size is omitted with labels
In cases such as "mov [es:bx], a_label" the operation defaults to a BYTE size which copies only part of the label value. Implement a check that warns the user of this issue when no size specifier is used. Signed-off-by: Maciej Wieczor-Retman <maciej.wieczor-retman@intel.com>
This commit is contained in:
parent
0058d91bec
commit
bbff2d7ec6
1 changed files with 22 additions and 0 deletions
22
asm/parser.c
22
asm/parser.c
|
|
@ -1255,6 +1255,7 @@ restart_parse:
|
|||
|
||||
if (!(eclass & ~(EC_RELOC | EC_UNKNOWN))) {
|
||||
/* It is an immediate */
|
||||
bool size_was_specified = false;
|
||||
op->offset = reloc_value(value);
|
||||
op->segment = reloc_seg(value);
|
||||
op->wrt = reloc_wrt(value);
|
||||
|
|
@ -1268,6 +1269,27 @@ restart_parse:
|
|||
op->type |= IMM_NORMAL;
|
||||
set_imm_flags(op, result->opt);
|
||||
|
||||
/*
|
||||
* Catch a missing size specifier when dealing with a label -
|
||||
* which might result in non-intentional handling of only part
|
||||
* of the label's address instead of the whole value.
|
||||
*/
|
||||
for(int j = 0 ; j <= opnum ; j++)
|
||||
size_was_specified |= !!(result->oprs[j].xsize & SIZE_MASK);
|
||||
|
||||
/*
|
||||
* Raise a 'label operation missing size specifier' error when:
|
||||
* 1. No size specifier was mentioned up to this point.
|
||||
* 2. One of the operands is a memory reference.
|
||||
* 3. The current operand is a label and not a simple immediate.
|
||||
*/
|
||||
if (!size_was_specified && (op->opflags & OPFLAG_FORWARD)) {
|
||||
for(int j = 0 ; j <= opnum ; j++) {
|
||||
if ((result->oprs[j].type & OPTYPE_MASK) == MEMORY)
|
||||
nasm_fatal("size wasn't specified, some data may be omitted");
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Special hack: if the previous operand was a colon
|
||||
* immediate operand with an explicit size, and this
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue