diff common-algo.c @ 238:e923801a7678

use a buffer rather than raw char array for creating the comma-seperated algorithm lists
author Matt Johnston <matt@ucc.asn.au>
date Fri, 02 Sep 2005 15:35:18 +0000
parents 961f6a74c5f4
children 29afa62b5450 89ace56293f6
line wrap: on
line diff
--- a/common-algo.c	Fri Sep 02 15:33:45 2005 +0000
+++ b/common-algo.c	Fri Sep 02 15:35:18 2005 +0000
@@ -209,21 +209,20 @@
 /* Output a comma separated list of algorithms to a buffer */
 void buf_put_algolist(buffer * buf, algo_type localalgos[]) {
 
-	unsigned int pos = 0, i, len;
-	char str[50]; /* enough for local algo storage */
+	unsigned int i, len;
+	unsigned int donefirst = 0;
+	buffer *algolist = NULL;
 
+	algolist = buf_new(100);
 	for (i = 0; localalgos[i].name != NULL; i++) {
 		if (localalgos[i].usable) {
-			/* Avoid generating a trailing comma */
-			if (pos)
-			    str[pos++] = ',';
+			if (donefirst)
+				buf_putbyte(algolist, ',');
+			donefirst = 1;
 			len = strlen(localalgos[i].name);
-			memcpy(&str[pos], localalgos[i].name, len);
-			pos += len;
+			buf_putbytes(algolist, localalgos[i].name, len);
 		}
 	}
-	str[pos]=0;
-	/* Debug this */
-	TRACE(("buf_put_algolist: %s", str))
-	buf_putstring(buf, str, pos);
+	buf_putstring(buf, algolist->data, algolist->len);
+	buf_free(algolist);
 }