$OpenBSD: patch-gpasm_macro_c,v 1.2 2004/01/30 01:01:11 naddy Exp $ --- gpasm/macro.c.orig 2004-01-21 17:17:52.000000000 +1100 +++ gpasm/macro.c 2004-01-25 20:43:22.000000000 +1100 @@ -150,9 +150,9 @@ node_to_string(struct pnode *p) switch(p->tag) { case constant: if (p->value.constant < 0) { - sprintf(constant_buffer, "-%#x", -p->value.constant); + snprintf(constant_buffer, sizeof(constant_buffer), "-%#x", -p->value.constant); } else { - sprintf(constant_buffer, "%#x", p->value.constant); + snprintf(constant_buffer, sizeof(constant_buffer), "%#x", p->value.constant); } cat_string(constant_buffer); break; @@ -230,12 +230,12 @@ void setup_macro(struct macro_head *h, i /* Copy the macro body to a buffer. */ -void copy_macro_body(struct macro_body *b, char *buffer) +void copy_macro_body(struct macro_body *b, char *buffer, size_t sizeof_buffer) { while (b) { if (b->src_line != NULL) { - strcat(buffer, b->src_line); - strcat(buffer, "\n"); + strlcat(buffer, b->src_line, sizeof_buffer); + strlcat(buffer, "\n", sizeof_buffer); } b = b->next; } @@ -265,10 +265,10 @@ make_macro_buffer(struct macro_head *h) /* Allocate memory for the new buffer. yy_delete_buffer frees it */ macro_src = (char *)calloc(sizeof(char), macro_src_size); - macro_src[0] = '\0'; - - /* build the string to be scanned */ - copy_macro_body(h->body, macro_src); + if (macro_src) { + /* build the string to be scanned */ + copy_macro_body(h->body, macro_src, macro_src_size); + } return macro_src; }