• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

chrjabs / rustsat / 15965899636

30 Jun 2025 06:48AM UTC coverage: 60.514% (+0.004%) from 60.51%
15965899636

Pull #418

github

web-flow
Merge 757c1a17b into 435c78799
Pull Request #418: Handle null pointers in empty ranges from solvers

8 of 16 new or added lines in 8 files covered. (50.0%)

23 existing lines in 2 files now uncovered.

14153 of 23388 relevant lines covered (60.51%)

47638.46 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

94.55
/src/utils.rs
1
//! # Library-Internal Utilities
2

3
/// Computes the number of digits needed to represent a number in a given base
4
///
5
/// # Panics
6
///
7
/// If `basis` is `1` and `number` is larger than `u32`.
8
#[cfg_attr(feature = "internals", visibility::make(pub))]
862✔
9
#[cfg_attr(docsrs, doc(cfg(feature = "internals")))]
862✔
10
#[must_use]
862✔
11
pub(crate) fn digits(mut number: usize, mut basis: u8) -> u32 {
862✔
12
    debug_assert_ne!(basis, 0);
862✔
13
    if number == 0 {
862✔
14
        return 1;
1✔
15
    }
861✔
16
    if basis == 1 {
861✔
17
        return u32::try_from(std::cmp::max(number, 1))
×
18
            .expect("number of digits does not fit in u32");
×
19
    }
861✔
20
    let mut digits = 0;
861✔
21
    if basis.is_power_of_two() {
861✔
22
        // optimized version using shift operations
23
        let mut pow: u8 = 0;
859✔
24
        basis >>= 1;
859✔
25
        while basis > 0 {
1,724✔
26
            pow += 1;
865✔
27
            basis >>= 1;
865✔
28
        }
865✔
29
        while number > 0 {
2,977✔
30
            digits += 1;
2,118✔
31
            number >>= pow;
2,118✔
32
        }
2,118✔
33
    } else {
34
        while number > 0 {
9✔
35
            digits += 1;
7✔
36
            number /= basis as usize;
7✔
37
        }
7✔
38
    }
39
    digits
861✔
40
}
862✔
41

42
/// Helper function to create an int slice from a pointer and size
43
/// which special cases when cnt is 0 (in which case c_int may be null)
44
/// UNSAFE: The slice returned has 'static' lifetime, as the lifespan is based
45
/// on the input pointer and size.
46
pub unsafe fn from_raw_parts_maybe_null<T>(ptr: *const T, cnt: usize) -> &'static [T] {
56✔
47
    if cnt == 0 {
56✔
NEW
48
        &[]
×
49
    } else {
50
        std::slice::from_raw_parts(ptr, cnt)
56✔
51
    }
52
}
56✔
53

54
/// A wrapper around an iterator to only yield a limited number of elements and then stop
55
///
56
/// As opposed to [`std::iter::Take`] this does not take ownership of the original iterator
57
#[derive(Debug)]
58
pub struct LimitedIter<'iter, I> {
59
    iter: &'iter mut I,
60
    remaining: usize,
61
}
62

63
impl<'iter, I> LimitedIter<'iter, I> {
64
    /// Creates a new iterator that yields at most `remaining` elements
65
    pub fn new(iter: &'iter mut I, remaining: usize) -> Self {
29✔
66
        Self { iter, remaining }
29✔
67
    }
29✔
68
}
69

70
impl<I> Iterator for LimitedIter<'_, I>
71
where
72
    I: Iterator,
73
{
74
    type Item = <I as Iterator>::Item;
75

76
    fn next(&mut self) -> Option<Self::Item> {
89✔
77
        if self.remaining == 0 {
89✔
78
            return None;
14✔
79
        }
75✔
80
        self.remaining -= 1;
75✔
81
        self.iter.next()
75✔
82
    }
89✔
83
}
84

85
macro_rules! unreachable_none {
86
    ($opt:expr) => {{
87
        if let Some(val) = $opt {
88
            val
89
        } else {
90
            unreachable!()
91
        }
92
    }};
93
}
94
pub(crate) use unreachable_none;
95

96
macro_rules! unreachable_err {
97
    ($res:expr) => {{
98
        if let Ok(val) = $res {
99
            val
100
        } else {
101
            unreachable!()
102
        }
103
    }};
104
}
105
pub(crate) use unreachable_err;
106

107
#[cfg(test)]
108
mod tests {
109
    #[test]
110
    fn digits_pow_2() {
1✔
111
        assert_eq!(super::digits(0b1111_1101, 2), 8);
1✔
112
        assert_eq!(super::digits(0b1111_1101, 4), 4);
1✔
113
        assert_eq!(super::digits(0b1111_1101, 8), 3);
1✔
114
        assert_eq!(super::digits(0b1111_1101, 16), 2);
1✔
115
    }
1✔
116

117
    #[test]
118
    fn digits_base_10() {
1✔
119
        assert_eq!(super::digits(3158, 10), 4);
1✔
120
        assert_eq!(super::digits(123, 10), 3);
1✔
121
    }
1✔
122
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc