mirror of
https://git.tartarus.org/simon/putty.git
synced 2025-07-02 12:02:47 -05:00
Generalise strbuf_catf() into put_fmt().
marshal.h now provides a macro put_fmt() which allows you to write arbitrary printf-formatted data to an arbitrary BinarySink. We already had this facility for strbufs in particular, in the form of strbuf_catf(). That was able to take advantage of knowing the inner structure of a strbuf to minimise memory allocation (it would snprintf directly into the strbuf's existing buffer if possible). For a general black-box BinarySink we can't do that, so instead we dupvprintf into a temporary buffer. For consistency, I've removed strbuf_catf, and converted all uses of it into the new put_fmt - and I've also added an extra vtable method in the BinarySink API, so that put_fmt can still use strbuf_catf's more efficient memory management when talking to a strbuf, and fall back to the simpler strategy when that's not available.
This commit is contained in:
@ -410,10 +410,10 @@ strbuf *pockle_mpu(Pockle *pockle, mp_int *p)
|
||||
memset(needed, 0, pockle->nlist * sizeof(bool));
|
||||
needed[pr->index] = true;
|
||||
|
||||
strbuf_catf(sb, "[MPU - Primality Certificate]\nVersion 1.0\nBase 10\n\n"
|
||||
"Proof for:\nN ");
|
||||
put_fmt(sb, "[MPU - Primality Certificate]\nVersion 1.0\nBase 10\n\n"
|
||||
"Proof for:\nN ");
|
||||
mp_write_decimal(sb, p);
|
||||
strbuf_catf(sb, "\n");
|
||||
put_fmt(sb, "\n");
|
||||
|
||||
for (size_t index = pockle->nlist; index-- > 0 ;) {
|
||||
if (!needed[index])
|
||||
@ -421,27 +421,27 @@ strbuf *pockle_mpu(Pockle *pockle, mp_int *p)
|
||||
pr = pockle->list[index];
|
||||
|
||||
if (mp_get_nbits(pr->prime) <= 64) {
|
||||
strbuf_catf(sb, "\nType Small\nN ");
|
||||
put_fmt(sb, "\nType Small\nN ");
|
||||
mp_write_decimal(sb, pr->prime);
|
||||
strbuf_catf(sb, "\n");
|
||||
put_fmt(sb, "\n");
|
||||
} else {
|
||||
assert(pr->witness);
|
||||
strbuf_catf(sb, "\nType BLS5\nN ");
|
||||
put_fmt(sb, "\nType BLS5\nN ");
|
||||
mp_write_decimal(sb, pr->prime);
|
||||
strbuf_catf(sb, "\n");
|
||||
put_fmt(sb, "\n");
|
||||
for (size_t i = 0; i < pr->nfactors; i++) {
|
||||
strbuf_catf(sb, "Q[%"SIZEu"] ", i+1);
|
||||
put_fmt(sb, "Q[%"SIZEu"] ", i+1);
|
||||
mp_write_decimal(sb, pr->factors[i]->prime);
|
||||
assert(pr->factors[i]->index < index);
|
||||
needed[pr->factors[i]->index] = true;
|
||||
strbuf_catf(sb, "\n");
|
||||
put_fmt(sb, "\n");
|
||||
}
|
||||
for (size_t i = 0; i < pr->nfactors + 1; i++) {
|
||||
strbuf_catf(sb, "A[%"SIZEu"] ", i);
|
||||
put_fmt(sb, "A[%"SIZEu"] ", i);
|
||||
mp_write_decimal(sb, pr->witness);
|
||||
strbuf_catf(sb, "\n");
|
||||
put_fmt(sb, "\n");
|
||||
}
|
||||
strbuf_catf(sb, "----\n");
|
||||
put_fmt(sb, "----\n");
|
||||
}
|
||||
}
|
||||
sfree(needed);
|
||||
|
Reference in New Issue
Block a user