[hackers] [scc] [cc2-qbe] Improve cc2/arch/qbe/code.c:/^binary/ || Roberto E. Vargas Caballero

From: <git_AT_suckless.org>
Date: Wed, 20 Apr 2016 22:57:26 +0200 (CEST)

commit 599f8df9655f84d78e6383f546caf23c7dccae98
Author: Roberto E. Vargas Caballero <Roberto E. Vargas Caballero>
AuthorDate: Wed Apr 20 04:31:40 2016 +0200
Commit: Roberto E. Vargas Caballero <Roberto E. Vargas Caballero>
CommitDate: Wed Apr 20 04:31:40 2016 +0200

    [cc2-qbe] Improve cc2/arch/qbe/code.c:/^binary/
    
    It is better to have an unique format string, even if we have to
    do a double copy to an internal buffer instead of using the buffer
    supplied by addr2txt().

diff --git a/cc2/arch/qbe/code.c b/cc2/arch/qbe/code.c
index 7db856f..fe9c762 100644
--- a/cc2/arch/qbe/code.c
+++ b/cc2/arch/qbe/code.c
_AT_@ -1,11 +1,14 @@
 
 #include <stdio.h>
 #include <stdlib.h>
+#include <string.h>
 
 #include "arch.h"
 #include "../../cc2.h"
 #include "../../../inc/sizes.h"
 
+#define ADDR_LEN (IDENTSIZ+2)
+
 static void binary(void), load(void), store(void);
 
 static struct opdata {
_AT_@ -229,8 +232,6 @@ writeout(void)
 static char *
 addr2txt(Addr *a)
 {
- static char buff[40];
-
         switch (a->kind) {
         case SAUTO:
         case SLABEL:
_AT_@ -245,13 +246,12 @@ static void
 binary(void)
 {
         struct opdata *p = &optbl[pc->op];
+ char to[ADDR_LEN], from1[ADDR_LEN], from2[ADDR_LEN];
 
- printf("\t%s %c=\t%s\t",
- addr2txt(&pc->to), p->letter, p->txt);
- fputs(addr2txt(&pc->from1), stdout);
- putchar(',');
- fputs(addr2txt(&pc->from2), stdout);
- putchar('\n');
+ strcpy(to, addr2txt(&pc->to));
+ strcpy(from1, addr2txt(&pc->from1));
+ strcpy(from2, addr2txt(&pc->from2));
+ printf("\t%s %c=\t%s\t%s,%s\n", to, p->letter, p->txt, from1, from2);
 }
 
 static void
Received on Wed Apr 20 2016 - 22:57:26 CEST

This archive was generated by hypermail 2.3.0 : Wed Apr 20 2016 - 23:00:25 CEST