if (k > K || p_K[K] == 0.0) return 0.0;
double p_T_is_k_when_S_is_K = p_hypergeometric(N, K, n, k);
+ if (p_T_is_k_when_S_is_K == 0.0) return 0.0;
+
double p_S_is_K = p_K[K];
double p_T_is_k = 0;
for (uint16_t i = 0; i <= 256; i++) {
if (p_K[i] != 0.0) {
- double tmp = p_hypergeometric(N, i, n, k);
- if (tmp != 0.0)
- p_T_is_k += p_K[i] * tmp;
+ p_T_is_k += p_K[i] * p_hypergeometric(N, i, n, k);
}
}
+ if (p_T_is_k == 0.0) return 0.0;
return(p_T_is_k_when_S_is_K * p_S_is_K / p_T_is_k);
}
for (uint32_t *p1 = partial_statelist[part_sum_a0].states[odd_even]; *p1 != END_OF_LIST_MARKER; p1++) {
uint32_t search_mask = 0x000ffff0;
uint32_t *p2 = find_first_state((*p1 << 4), search_mask, &partial_statelist[part_sum_a8], odd_even);
- if (p2 != NULL) {
+ if (p1 != NULL && p2 != NULL) {
while (((*p1 << 4) & search_mask) == (*p2 & search_mask) && *p2 != END_OF_LIST_MARKER) {
if ((nonces[best_first_bytes[0]].BitFlip[odd_even] && find_first_state((*p1 << 4) | *p2, 0x000fffff, &statelist_bitflip, 0))
|| !nonces[best_first_bytes[0]].BitFlip[odd_even]) {
} else {
new_candidates = current_candidates->next = (statelist_t *)malloc(sizeof(statelist_t));
}
+ if (!new_candidates) return NULL;
+
new_candidates->next = NULL;
new_candidates->len[ODD_STATE] = 0;
new_candidates->len[EVEN_STATE] = 0;
for (uint16_t s = 0; s <= 16; s += 2) {
if (r*(16-s) + (16-r)*s == sum_a8) {
current_candidates = add_more_candidates(current_candidates);
- if (current_candidates) {
+ if (current_candidates != NULL) {
// check for the smallest partial statelist. Try this first - it might give 0 candidates
// and eliminate the need to calculate the other part
if (MIN(partial_statelist[p].len[ODD_STATE], partial_statelist[r].len[ODD_STATE])