#51 %macro with 16 parameters

closed-fixed
1
2008-10-07
2002-10-14
Ilya
No

NASM: win32, "NASM version 0.98.34 compiled on Jun 13
2002" and "NASM version 0.98.35 compiled on Sep 25
2002"

A.ASM:
%macro abc 0-*
%rep %0
%error %1
%rotate 1
%endrep
%endm ; abc
abc 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6

command line: nasw a.asm

output: crash: "nasmw.exe - Application Error" dialog: The
instruction at ... referenced memory at ...

If number of parameters is different from 16, everything
works. A wonderful error!

Discussion

  • Logged In: YES
    user_id=806493

    This was a bug at preproc.c in function expand_mmacro().

    It counted tokens returned by is_mmacro() by scanning for
    terminating null-pointer. is_mmacro(), in other way returned
    pointer vector without terminating null. It appeared as the
    result of realloc(), called for each 16 parameters. And if it was
    exactly 16 (or 32, 48, etc...) parameters, no terminating null
    added and program crashes.

    I fixed this bug. This is diff file for preproc.c (version 0.98.36):

    3764c3764
    < is_mmacro(Token * tline, Token *** params_array)
    ---
    > is_mmacro(Token * tline, int *params_count, Token ***
    params_array)
    3788a3789
    > *params_count = nparam;
    3886c3887
    < m = is_mmacro(t, &params);
    ---
    > m = is_mmacro(t, &nparam, &params);
    3907c3908
    < if (!tok_type_(t, TOK_ID) || (m = is_mmacro(t,
    params)) == NULL)
    ---
    > if (!tok_type_(t, TOK_ID) || (m = is_mmacro(t,
    &nparam, &params)) == NULL)
    3918,3919d3918
    < for (nparam = 0; params[nparam]; nparam++)
    < ;
    3922c3921
    < for (i = 0; params[i]; i++)
    ---
    > for (i = 0; i < nparam; i++)

    This should be submitted into cvs.

     
    • labels: --> Preprocessor Bugs
    • assigned_to: nobody --> unv
     
    • priority: 5 --> 1
    • status: open --> open-works-for-me
     
  • Logged In: YES
    user_id=804543

    I've got working code in my local forked version.

     
  • H. Peter Anvin
    H. Peter Anvin
    2008-10-07

    • status: open-works-for-me --> closed-fixed
     
  • H. Peter Anvin
    H. Peter Anvin
    2008-10-07

    The current version doesn't appear to have this problem. You may want to try the latest release version and/or the latest snapshot from ftp://ftp.zytor.com/pub/nasm/snapshots/