openbsd-ports/devel/gputils/patches/patch-libgputils_gpdis_c
naddy cfb6182a3f Import gputils 0.11.7.
Submitted by Andrew Dalgleish <openbsd@ajd.net.au>.

GPUTILS is a collection of tools for the Microchip (TM) PIC
microcontrollers. It includes gpasm, gplink, and gplib.
2003-11-03 01:02:34 +00:00

96 lines
3.5 KiB
Plaintext

$OpenBSD: patch-libgputils_gpdis_c,v 1.1.1.1 2003/11/03 01:02:36 naddy Exp $
--- libgputils/gpdis.c.orig 2003-03-14 17:44:51.000000000 +1100
+++ libgputils/gpdis.c 2003-10-14 23:01:13.000000000 +1000
@@ -22,30 +22,30 @@ Boston, MA 02111-1307, USA. */
#include "stdhdr.h"
#include "libgputils.h"
-#define DECODE_ARG0 sprintf(buffer, "%s", instruction->name)
+#define DECODE_ARG0 snprintf(buffer, sizeof_buffer, "%s", instruction->name)
-#define DECODE_ARG1(ARG1) sprintf(buffer, "%s\t%#lx", \
+#define DECODE_ARG1(ARG1) snprintf(buffer, sizeof_buffer, "%s\t%#lx", \
instruction->name,\
ARG1)
-#define DECODE_ARG1WF(ARG1, ARG2) sprintf(buffer, "%s\t%#lx, %s", \
+#define DECODE_ARG1WF(ARG1, ARG2) snprintf(buffer, sizeof_buffer, "%s\t%#lx, %s", \
instruction->name,\
ARG1, \
(ARG2 ? "f" : "w"))
-#define DECODE_ARG2(ARG1, ARG2) sprintf(buffer, "%s\t%#lx, %#lx", \
+#define DECODE_ARG2(ARG1, ARG2) snprintf(buffer, sizeof_buffer, "%s\t%#lx, %#lx", \
instruction->name,\
ARG1, \
ARG2)
-#define DECODE_ARG3(ARG1, ARG2, ARG3) sprintf(buffer, "%s\t%#lx, %#lx, %#lx", \
+#define DECODE_ARG3(ARG1, ARG2, ARG3) snprintf(buffer, sizeof_buffer, "%s\t%#lx, %#lx, %#lx", \
instruction->name,\
ARG1, \
ARG2, \
ARG3)
void
-gp_disassemble(MemBlock *m, int *org, enum proc_class class, char *buffer)
+gp_disassemble(MemBlock *m, int *org, enum proc_class class, char *buffer, size_t sizeof_buffer)
{
int i;
long int opcode;
@@ -56,7 +56,7 @@ gp_disassemble(MemBlock *m, int *org, en
switch (class) {
case PROC_CLASS_EEPROM8:
case PROC_CLASS_GENERIC:
- sprintf(buffer, "unsupported processor class");
+ snprintf(buffer, sizeof_buffer, "unsupported processor class");
return;
case PROC_CLASS_PIC12:
for(i = 0; i < num_op_12c5xx; i++)
@@ -88,7 +88,7 @@ gp_disassemble(MemBlock *m, int *org, en
}
if (instruction == NULL) {
- sprintf(buffer, "dw\t%#lx ;unknown opcode", opcode);
+ snprintf(buffer, sizeof_buffer, "dw\t%#lx ;unknown opcode", opcode);
return;
}
@@ -146,7 +146,7 @@ gp_disassemble(MemBlock *m, int *org, en
*org += 1;
dest = (i_memory_get(m, *org) & 0xfff) << 8;
dest |= opcode & 0xff;
- sprintf(buffer, "%s\t%#lx, %#lx",
+ snprintf(buffer, sizeof_buffer, "%s\t%#lx, %#lx",
instruction->name,
dest * 2,
(opcode >> 8) & 1);
@@ -227,22 +227,22 @@ gp_disassemble(MemBlock *m, int *org, en
switch(opcode & 0x3)
{
case 0:
- strcpy(operator, "*");
+ strlcpy(operator, "*", sizeof(operator));
break;
case 1:
- strcpy(operator, "*+");
+ strlcpy(operator, "*+", sizeof(operator));
break;
case 2:
- strcpy(operator, "*-");
+ strlcpy(operator, "*-", sizeof(operator));
break;
case 3:
- strcpy(operator, "+*");
+ strlcpy(operator, "+*", sizeof(operator));
break;
default:
assert(0);
}
- sprintf(buffer, "%s\t%s", instruction->name, operator);
+ snprintf(buffer, sizeof_buffer, "%s\t%s", instruction->name, operator);
}
break;
case INSN_CLASS_TBL2: