blkmk_init_generation*: Correct output newcb value even in error conditions

This commit is contained in:
Luke Dashjr 2018-02-17 17:45:24 +00:00
parent 366b8bc358
commit b2dda538c8

View File

@ -56,20 +56,19 @@ bool _blkmk_dblsha256(void *hash, const void *data, size_t datasz) {
#define dblsha256 _blkmk_dblsha256
uint64_t blkmk_init_generation3(blktemplate_t * const tmpl, const void * const script, const size_t scriptsz, bool * const inout_newcb) {
if (tmpl->cbtxn && !(*inout_newcb && (tmpl->mutations & BMM_GENERATE)))
const bool replace_existing = *inout_newcb;
*inout_newcb = false;
if (tmpl->cbtxn && !(replace_existing && (tmpl->mutations & BMM_GENERATE)))
{
*inout_newcb = false;
return 0;
}
if (!tmpl->cbvalue) {
// TODO: Figure it out from the existing cbtxn
*inout_newcb = false;
return 0;
}
*inout_newcb = true;
if (scriptsz >= 0xfd)
return 0;
@ -133,6 +132,7 @@ uint64_t blkmk_init_generation3(blktemplate_t * const tmpl, const void * const s
tmpl->mutations |= BMM_CBAPPEND | BMM_CBSET | BMM_GENERATE;
*inout_newcb = true;
return tmpl->cbvalue;
}