summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--simplex86.c20
1 files changed, 17 insertions, 3 deletions
diff --git a/simplex86.c b/simplex86.c
index 966b6b5..6e81314 100644
--- a/simplex86.c
+++ b/simplex86.c
@@ -1,3 +1,4 @@
+#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
@@ -949,7 +950,7 @@ struct annotation_t
annotation_type_t type;
ssize_t offset;
size_t size;
- const char * name;
+ char name[32];
annotation_t * label;
const uint8_t * fragment;
uint32_t opcode;
@@ -1721,6 +1722,19 @@ emit_address_byte (uint8_t *code,
return code;
}
+static void
+copy_string (char *dst, const char *src, int size)
+{
+ if (strlen (src) >= size)
+ {
+ assert (0);
+ return;
+ }
+
+ strncpy (dst, src, size);
+ dst[size - 1] = '\0';
+}
+
static uint8_t *
emit_reg_regm (uint8_t *c, op_t reg, op_t regm,
uint8_t *r, uint8_t *x, uint8_t *b,
@@ -1741,7 +1755,7 @@ emit_reg_regm (uint8_t *c, op_t reg, op_t regm,
ann->type = RIP_REF;
ann->offset = (size_t)c;
- ann->name = GET_LABEL (regm);
+ copy_string (ann->name, GET_LABEL (regm), sizeof (ann->name));
}
else if (is_reg (regm))
{
@@ -2014,7 +2028,7 @@ emit (fragment_t *frag, const variant_t *variant, const op_t ops[4])
ann.offset = (size_t)c;
if (variant->ops[0] == A_LABEL)
- ann.name = GET_LABEL (ops[0]);
+ copy_string (ann.name, GET_LABEL (ops[0]), sizeof ann.name);
if (ann.type == ALIGN)
{
ann.align_mask = 1;