1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
// ---------------- [ File: bitcoin-compat/src/strnlen.rs ]
//! Safe replacement for the C `strnlen` routine.
//!
//! The C++ reference implementation relied on `memchr`
//! to locate the first `NUL` byte or to stop after
//! `max_len` bytes.
//! In Rust we can achieve the same behaviour with
//! `slice::from_raw_parts` while adding *robust*
//! tracing so that potential UB is detectable in
//! production.
//
//! # Safety
//! This function takes a raw pointer because it must
//! operate on arbitrary buffers originating from FFI.
//! The caller must uphold the usual guarantees:
//!
//! * `start` must be valid for reads of at least
//! `max_len` bytes.
//! * The buffer must not be mutated for the lifetime
//! of the call (no concurrent writes).
//!
//! If either condition is violated the behaviour is
//! undefined – identical to the original C contract.
crateix!;
//-------------------------------------------[.cpp/bitcoin/src/compat/strnlen.cpp]
use ;
/// Return the length of the C‑string starting at `start`
/// but never examine more than `max_len` bytes.
///
/// When no `NUL` byte is found within `max_len`, the
/// function returns `max_len`.
pub unsafe