Jeff Johnson <[email protected]> writes:
> I believe I have found a bug in the msp-gcc compiler. The simple
> program attached should illustrate the problem.
The error is in the assembler, not the compiler. It is a buffer that
is too small and overflows because of a common strncpy error[*].
I'm not too familiar with this code but the patch below (relative to
binutils 2.14) fixes the problem for me.
Regards,
Daniel
[*] This is exactly why strlcpy was invented:
http://www.courtesan.com/todd/papers/strlcpy.html
--- gas/config/tc-msp430.c.orig Tue Sep 16 10:36:14 2003
+++ gas/config/tc-msp430.c Tue Sep 16 10:28:58 2003
@@ -541,15 +541,14 @@ msp430_operands (opcode, line)
}
break;
case 2:
{
- char l2[16];
-
/* Shift instruction. */
line = extract_operand (line, l1, sizeof (l1));
- strncpy (l2, l1, 16);
+ strncpy (l2, l1, sizeof l2 - 1);
+ l2[sizeof l2 - 1] = '\0';
res = msp430_srcoperand (&op1, l1, opcode->bin_opcode, &imm_op);
res += msp430_dstoperand (&op2, l2, opcode->bin_opcode);
if (res)
break; /* An error occured. All warnings were done before. */