$OpenBSD: patch-gpasm_directive_c,v 1.2 2004/01/30 01:01:11 naddy Exp $
--- gpasm/directive.c.orig	2004-01-07 17:35:53.000000000 +1100
+++ gpasm/directive.c	2004-01-25 20:40:03.000000000 +1100
@@ -323,7 +323,7 @@ static int list_symbol_member(struct pno
     return 0;
   } else if (STRCMP(M->value.symbol, HEAD(L)->value.symbol) == 0) {
     char buf[BUFSIZ];
-    sprintf(buf, "Duplicate macro parameter (%s).", HEAD(L)->value.symbol);
+    snprintf(buf, sizeof(buf), "Duplicate macro parameter (%s).", HEAD(L)->value.symbol);
     gperror(GPE_UNKNOWN, buf);
     return 1;
   } else {
@@ -524,14 +524,14 @@ static gpasmVal do_code(gpasmVal r,
     switch (arity) {
     case 0:
       /* new relocatable section */
-      strcpy(state.obj.new_sec_name, ".code");
+      strlcpy(state.obj.new_sec_name, ".code", sizeof(state.obj.new_sec_name));
       state.obj.new_sec_addr = 0;
       state.obj.new_sec_flags = STYP_TEXT;
       break;
     case 1:
       /* new absolute section */
       p = HEAD(parms);
-      strcpy(state.obj.new_sec_name, ".code");
+      strlcpy(state.obj.new_sec_name, ".code", sizeof(state.obj.new_sec_name));
       state.obj.new_sec_addr = maybe_evaluate(p) >> _16bit_core;
       state.obj.new_sec_flags = STYP_TEXT | STYP_ABS;
       break;
@@ -1109,12 +1109,12 @@ static gpasmVal do_global(gpasmVal r,
       if (p->tag == symbol) {
         s = get_symbol(state.stTop, p->value.symbol);
         if (s == NULL) {
-          sprintf(buf, "Symbol not previously defined (%s).", p->value.symbol);
+          snprintf(buf, sizeof(buf), "Symbol not previously defined (%s).", p->value.symbol);
           gperror(GPE_NOSYM, buf);    
 	} else {
           var = get_symbol_annotation(s);
           if (var == NULL) {
-            sprintf(buf, "Symbol not assigned a value (%s).", p->value.symbol);
+            snprintf(buf, sizeof(buf), "Symbol not assigned a value (%s).", p->value.symbol);
             gpwarning(GPW_UNKNOWN, buf);    
           } else {
             if ((var->previous_type == gvt_address) || 
@@ -1125,7 +1125,7 @@ static gpasmVal do_global(gpasmVal r,
             } else if (var->previous_type == gvt_extern) { 
               gperror(GPE_DUPLAB, NULL);    
             } else {
-              sprintf(buf, "Operand must be an address label (%s).", 
+              snprintf(buf, sizeof(buf), "Operand must be an address label (%s).", 
                       p->value.symbol);
               gperror(GPE_MUST_BE_LABEL, buf);    
             } 
@@ -1156,14 +1156,14 @@ static gpasmVal do_idata(gpasmVal r,
     switch (arity) {
     case 0:
       /* new relocatable section */
-      strcpy(state.obj.new_sec_name, ".idata");
+      strlcpy(state.obj.new_sec_name, ".idata", sizeof(state.obj.new_sec_name));
       state.obj.new_sec_addr = 0;
       state.obj.new_sec_flags = STYP_DATA;
       break;
     case 1:
       /* new absolute section */
       p = HEAD(parms);
-      strcpy(state.obj.new_sec_name, ".idata");
+      strlcpy(state.obj.new_sec_name, ".idata", sizeof(state.obj.new_sec_name));
       state.obj.new_sec_addr = maybe_evaluate(p) >> _16bit_core;
       state.obj.new_sec_flags = STYP_DATA | STYP_ABS;
       break;
@@ -1615,7 +1615,7 @@ static gpasmVal do_org(gpasmVal r,
       }	else {
         /* Default section name, this will be overwritten if a label is 
            present. */
-        sprintf(state.obj.new_sec_name, ".org_%d", state.obj.org_num++);
+        snprintf(state.obj.new_sec_name, sizeof(state.obj.new_sec_name), ".org_%d", state.obj.org_num++);
         state.obj.new_sec_addr = r;
         state.obj.new_sec_flags = STYP_TEXT | STYP_ABS;
         state.lst.line.linetype = sec;
@@ -1838,14 +1838,14 @@ static gpasmVal do_udata(gpasmVal r,
     switch (arity) {
     case 0:
       /* new relocatable section */
-      strcpy(state.obj.new_sec_name, ".udata");
+      strlcpy(state.obj.new_sec_name, ".udata", sizeof(state.obj.new_sec_name));
       state.obj.new_sec_addr = 0;
       state.obj.new_sec_flags = STYP_BSS;
       break;
     case 1:
       /* new absolute section */
       p = HEAD(parms);
-      strcpy(state.obj.new_sec_name, ".udata");
+      strlcpy(state.obj.new_sec_name, ".udata", sizeof(state.obj.new_sec_name));
       state.obj.new_sec_addr = maybe_evaluate(p);
       state.obj.new_sec_flags = STYP_BSS | STYP_ABS;
       break;
@@ -1873,14 +1873,14 @@ static gpasmVal do_udata_acs(gpasmVal r,
     switch (arity) {
     case 0:
       /* new relocatable section */
-      strcpy(state.obj.new_sec_name, ".udata_acs");
+      strlcpy(state.obj.new_sec_name, ".udata_acs", sizeof(state.obj.new_sec_name));
       state.obj.new_sec_addr = 0;
       state.obj.new_sec_flags = STYP_BSS | STYP_ACCESS;
       break;
     case 1:
       /* new absolute section */
       p = HEAD(parms);
-      strcpy(state.obj.new_sec_name, ".udata_acs");
+      strlcpy(state.obj.new_sec_name, ".udata_acs", sizeof(state.obj.new_sec_name));
       state.obj.new_sec_addr = maybe_evaluate(p);
       state.obj.new_sec_flags = STYP_BSS | STYP_ABS | STYP_ACCESS;
       break;
@@ -1908,14 +1908,14 @@ static gpasmVal do_udata_ovr(gpasmVal r,
     switch (arity) {
     case 0:
       /* new relocatable section */
-      strcpy(state.obj.new_sec_name, ".udata_ovr");
+      strlcpy(state.obj.new_sec_name, ".udata_ovr", sizeof(state.obj.new_sec_name));
       state.obj.new_sec_addr = 0;
       state.obj.new_sec_flags = STYP_BSS | STYP_OVERLAY;
       break;
     case 1:
       /* new absolute section */
       p = HEAD(parms);
-      strcpy(state.obj.new_sec_name, ".udata_ovr");
+      strlcpy(state.obj.new_sec_name, ".udata_ovr", sizeof(state.obj.new_sec_name));
       state.obj.new_sec_addr = maybe_evaluate(p);
       state.obj.new_sec_flags = STYP_BSS | STYP_ABS | STYP_OVERLAY;
       break;
@@ -1943,14 +1943,14 @@ static gpasmVal do_udata_shr(gpasmVal r,
     switch (arity) {
     case 0:
       /* new relocatable section */
-      strcpy(state.obj.new_sec_name, ".udata_shr");
+      strlcpy(state.obj.new_sec_name, ".udata_shr", sizeof(state.obj.new_sec_name));
       state.obj.new_sec_addr = 0;
       state.obj.new_sec_flags = STYP_BSS | STYP_SHARED;
       break;
     case 1:
       /* new absolute section */
       p = HEAD(parms);
-      strcpy(state.obj.new_sec_name, ".udata_shr");
+      strlcpy(state.obj.new_sec_name, ".udata_shr", sizeof(state.obj.new_sec_name));
       state.obj.new_sec_addr = maybe_evaluate(p);
       state.obj.new_sec_flags = STYP_BSS | STYP_ABS | STYP_SHARED;
       break;
@@ -2128,7 +2128,7 @@ static void emit_check_relative(int insn
 
   /* If the branch is too far then issue an error */
   if ((argument > range) || (argument < -(range+1))) {
-    sprintf(full_message,"Argument out of range (%d not between %d and %d)\n",
+    snprintf(full_message, sizeof(full_message), "Argument out of range (%d not between %d and %d)\n",
 	    argument,
 	    -(range+1),
 	    range);
@@ -2888,7 +2888,7 @@ gpasmVal do_insn(char *name, struct pnod
           gperror(GPE_UNDEF_PROC, NULL);
         } else {
           char mesg[80];
-          sprintf(mesg, "Unknown opcode \"%.40s\"", name);
+          snprintf(mesg, sizeof(mesg), "Unknown opcode \"%.40s\"", name);
           gperror(GPE_UNKNOWN, mesg);
         }
       }
