Mercurial > dropbear
comparison 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 |
comparison
equal
deleted
inserted
replaced
237:961f6a74c5f4 | 238:e923801a7678 |
---|---|
207 | 207 |
208 | 208 |
209 /* Output a comma separated list of algorithms to a buffer */ | 209 /* Output a comma separated list of algorithms to a buffer */ |
210 void buf_put_algolist(buffer * buf, algo_type localalgos[]) { | 210 void buf_put_algolist(buffer * buf, algo_type localalgos[]) { |
211 | 211 |
212 unsigned int pos = 0, i, len; | 212 unsigned int i, len; |
213 char str[50]; /* enough for local algo storage */ | 213 unsigned int donefirst = 0; |
214 | 214 buffer *algolist = NULL; |
215 | |
216 algolist = buf_new(100); | |
215 for (i = 0; localalgos[i].name != NULL; i++) { | 217 for (i = 0; localalgos[i].name != NULL; i++) { |
216 if (localalgos[i].usable) { | 218 if (localalgos[i].usable) { |
217 /* Avoid generating a trailing comma */ | 219 if (donefirst) |
218 if (pos) | 220 buf_putbyte(algolist, ','); |
219 str[pos++] = ','; | 221 donefirst = 1; |
220 len = strlen(localalgos[i].name); | 222 len = strlen(localalgos[i].name); |
221 memcpy(&str[pos], localalgos[i].name, len); | 223 buf_putbytes(algolist, localalgos[i].name, len); |
222 pos += len; | 224 } |
223 } | 225 } |
224 } | 226 buf_putstring(buf, algolist->data, algolist->len); |
225 str[pos]=0; | 227 buf_free(algolist); |
226 /* Debug this */ | |
227 TRACE(("buf_put_algolist: %s", str)) | |
228 buf_putstring(buf, str, pos); | |
229 } | 228 } |