[comp.sys.amiga.tech] Manx V5.0d strnicmp problems

johnv@DIALix.oz.au (johnv) (11/06/90)

G'Day,
    Is their anybody from Manx listening, or could somebody
please pass this on to Manx for me, I would be grateful.

    Their is a problem with the 'strnicmp' function as supplied
with V5.0d of the Aztec C Compiler.  This is supposed to do a
case-insensitive string comparison of two strings, upto the
given lenght.

    Function is called with strnicmp(s1,s2,len).  On entry to
the function, the stack look like this -:
        	sp+12	lenght
        	sp+8    s2
        	sp+4	s1
        	sp->	return address

    D2 is the pushed on to the stack to preserve it's value.
The stack now looks like this -:
            sp+16   lenght
            sp+12   s2
            sp+8    s1
            sp+4    return address
            sp->    d2

    Values for s1,s2 are moved in a0/a1 with a movem.l
4(sp),a0/a1 instruction.  A0 should contain s1 and A1 should
contain s2.  However owing to the pushing of D2, A0 gets the
return address, A1 gets s1.

    The lenght is then picked up using a move.l 12(sp),d1
instruction.  However the value that gets picked up for the
lenght is s2.

    The rest of the code for doing the comparison looks OK,
however D2 is not restored prior to exit, and so the address we
return to is the value of D2 we saved on the stack...

    Net result, this is not likely to work correctly very often
at all, and will result in a visit to the GURU when used <sigh>.
The saving of D2 must have been added as an afterthought.

    John Verhoeven