#5 Undefined C code in assemble.c

closed-fixed
None
5
2002-05-13
2002-05-10
Anonymous
No

Version 0.98.30 has some C code that can give
undefined results in it.

Lines 1393-1395 which is in function process_ea.

if (b==-1 && i!=-1) b ^= i ^= b ^= i; /* swap them
round */
if ((b==R_SI || b==R_DI) && i!=-1)
b ^= i ^= b ^= i; /* have BX/BP as
base, SI/DI index */

"b ^= i ^=b ^= i" is undefined according to the C
basically because the same variable is being assigned
multiple times on the same statement. GCC 3.1 and
above will warn about it (see -Wsequence-point).
Previous versions of GCC would silently generate code
that might not give the expected answer.

The plus side is that in this case, current versions
of GCC generate your expected answer. Nevertheless
that is not guaranteed to always be the case.

The solution is simple, change it to "{b ^= i; i ^= b;
b ^= i;}" which is legal C.

Discussion

  • H. Peter Anvin

    H. Peter Anvin - 2002-05-11

    Logged In: YES
    user_id=58697

    Let's do it the traditional way, {int tmp = b; b = i; i =
    tmp;}...

     
  • H. Peter Anvin

    H. Peter Anvin - 2002-05-11
    • assigned_to: nobody --> hpa
    • status: open --> pending
     
  • H. Peter Anvin

    H. Peter Anvin - 2002-05-13
    • status: pending --> closed-fixed
     
  • H. Peter Anvin

    H. Peter Anvin - 2002-05-13

    Logged In: YES
    user_id=58697

    Fixed in the current CVS tree.

     

Log in to post a comment.

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:





No, thanks