Coverage Report

Created: 2026-05-16 06:51

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/dovecot/src/lib/primes.c
Line
Count
Source
1
/* Copyright (c) 2013-2018 Dovecot authors, see the included COPYING file */
2
3
#include "lib.h"
4
#include "primes.h"
5
6
static const unsigned int primes[] = {
7
0
#define PRIME_SKIP_COUNT 3
8
  17,
9
  37,
10
  67,
11
  131,
12
  257, /* next from 2^8 */
13
  521,
14
  1031,
15
  2053,
16
  4099,
17
  8209,
18
  16411,
19
  32771,
20
  65537, /* next from 2^16 */
21
  131101,
22
  262147,
23
  524309,
24
  1048583,
25
  2097169,
26
  4194319,
27
  8388617,
28
  16777259, /* next from 2^24 */
29
  33554467,
30
  67108879,
31
  134217757,
32
  268435459,
33
  536870923,
34
  1073741827,
35
  2147483659U,
36
  4294967291U /* previous from 2^32 */
37
};
38
39
unsigned int primes_closest(unsigned int num)
40
0
{
41
0
  unsigned int i;
42
43
0
  for (i = 31; i > PRIME_SKIP_COUNT; i--) {
44
0
    if ((num & (1U << i)) != 0)
45
0
      return primes[i - PRIME_SKIP_COUNT];
46
0
  }
47
0
  return primes[0];
48
0
}