bugZ80 assembler - Bugs: bug #60151, Regression: "trap" not...

 
 

bug #60151: Regression: "trap" not usable as macro argument

Submitter:  Paul Flo Williams <hisdeedsaredust>
Submitted:  Mon 01 Mar 2021 01:19:35 PM UTC
   
 
Category:  None Severity:  3 - Normal
Item Group:  None Status:  Works For Me
Privacy:  Public Assigned to:  hisdeedsaredust
Open/Closed:  Open
* Mandatory Fields

Add a New Comment Rich Markup
   

Tue 16 Mar 2021 04:05:27 PM UTC, comment #4: 

Reopening for reasons in comment #1, i.e. minlen is always initialised by reading off the end of the tokens array.

However, tokens[] is on the stack, so this may only segfault if the wind is from the north or you had pancakes for breakfast.

Forcing a segfault is easier if you change the macro argument name from "trap" to "trap1234567890..." (make it about 90 characters long), or if you add:

memset(tokens, 0xff, sizeof(tokens));

after the declaration of last_arg (about line 1560), in order to adversely initialise the tokens array.

valgrind will also pick up this problem with the memcheck tool, and I expect it'd be easier with sgcheck.

I've assigned it to me to look at in slower time, but please feel free to take it if you understand that tokenisation routine.

Paul Flo Williams <hisdeedsaredust>
Group Member
Sat 13 Mar 2021 03:59:20 PM UTC, comment #3: 

Seems to work now. Added a test case for the bug.

Peter Kollner <asgalon>
Group Member
Tue 02 Mar 2021 10:39:03 PM UTC, comment #2: 

Noted... I will take a deeper look at the state of the code this weekend to see how it could be put back on track.

Peter Kollner <asgalon>
Group Member
Mon 01 Mar 2021 06:07:37 PM UTC, comment #1: 

I've now had a chance to diagnose this one. It turns out that the exact argument name didn't matter, but the length did. I confirmed that an argument name of 3 or 5 characters always works for me, but 4 always fails. I don't know why this is the case, but there is definitely a buggy line here:

In z80asm.c, in the assemble() function, after the "half-tokenized search routine", this line:


minlen = tokens[i][1];


always reads off the end of the tokens array, because "i" is the character index in the line, not the current number of tokens found, which is in tc. I'm not completely sure what "minlen" is trying to do, but setting minlen to 0 at this point allows the code to always work.

Paul Flo Williams <hisdeedsaredust>
Group Member
Mon 01 Mar 2021 01:19:35 PM UTC, original submission:  

I have this source:


emt: macro trap
 rst 30h
 defb trap
 endm

org 0
emt 1
end


This works with z80asm 1.8 but fails with 1.9 (current git head) with the error message "unable to resolve reference: trap".

Changing the argument name to "trapn" makes it work, but I can't see any reason why "trap" no longer works as the name of a macro argument.

Paul Flo Williams <hisdeedsaredust>
Group Member

 

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attach Files:
   
   
Comment:
   

No files currently attached

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by asgalon (Posted a comment)
  • -email is unavailable- added by hisdeedsaredust (Submitted the item)
  •  

    There are 0 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.

    Only logged-in users can vote.

     

    Follow 4 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2021-03-16 hisdeedsaredust Assigned toNone hisdeedsaredust
        Open/ClosedClosed Open
    2021-03-13 asgalon StatusNone Works For Me
        Open/ClosedOpen Closed

    Back to the top

    Powered by Savane 3.13-4448.
    Corresponding source code