shithub: riscv

Download patch

ref: 3f87ffea44150d233b11a38b1ca3673207fe206e
parent: 3a79916c9be2d524b392c1a87a4685ceca603831
author: cinap_lenrek <[email protected]>
date: Sun Apr 19 16:44:19 EDT 2020

cc: get rid of sprint() and temporary buffer for type conversion fuction

slookup() copies to symb, so use the symb[NSYMB] buffer directly
to declare type conversion functions and get rid of the arbitrary
sized local buffer. replace sprint() with snprint().

--- a/sys/src/cmd/cc/funct.c
+++ b/sys/src/cmd/cc/funct.c
@@ -217,7 +217,6 @@
 	Node *n;
 	Type *f1, *f2, *f3, *f4;
 	int o, i, c;
-	char str[100];
 
 	if(t->funct)
 		return;
@@ -262,9 +261,9 @@
 		o = ftabinit[i].op;
 		if(o == OXXX)
 			break;
-		sprint(str, "%s_%s_", t->tag->name, ftabinit[i].name);
+		snprint(symb, NSYMB, "%s_%s_", t->tag->name, ftabinit[i].name);
 		n = new(ONAME, Z, Z);
-		n->sym = slookup(str);
+		n->sym = lookup();
 		f->sym[o] = n->sym;
 		switch(ftabinit[i].typ) {
 		default:
@@ -296,9 +295,9 @@
 		/*
 		 * OCAST types T1 _T2_T1_(T2)
 		 */
-		sprint(str, "_%s%s_", gtabinit[i].name, t->tag->name);
+		snprint(symb, NSYMB, "_%s%s_", gtabinit[i].name, t->tag->name);
 		n = new(ONAME, Z, Z);
-		n->sym = slookup(str);
+		n->sym = lookup();
 		f->castto[o] = n->sym;
 
 		f1 = typ(TFUNC, t);
@@ -305,9 +304,9 @@
 		f1->down = types[o];
 		dodecl(xdecl, CEXTERN, f1, n);
 
-		sprint(str, "%s_%s_", t->tag->name, gtabinit[i].name);
+		snprint(symb, NSYMB, "%s_%s_", t->tag->name, gtabinit[i].name);
 		n = new(ONAME, Z, Z);
-		n->sym = slookup(str);
+		n->sym = lookup();
 		f->castfr[o] = n->sym;
 
 		f1 = typ(TFUNC, types[o]);