Skip to content

Commit efbb166

Browse files
authored
Add SAFETY markers to code that could panic
1 parent eb417b0 commit efbb166

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

src/encoding.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,8 @@ pub fn decode_into(bytes: &[u8], encoding: &'static Encoding, buf: &mut String)
123123
buf.reserve(
124124
decoder
125125
.max_utf8_buffer_length_without_replacement(bytes.len())
126+
// SAFETY: None can be returned only if required size will overflow usize,
127+
// but in that case String::reserve also panics
126128
.unwrap(),
127129
);
128130
let (result, read) = decoder.decode_to_string_without_replacement(bytes, buf, true);
@@ -132,6 +134,7 @@ pub fn decode_into(bytes: &[u8], encoding: &'static Encoding, buf: &mut String)
132134
Ok(())
133135
}
134136
DecoderResult::Malformed(_, _) => Err(Error::NonDecodable(None)),
137+
// SAFETY: We allocate enough space above
135138
DecoderResult::OutputFull => unreachable!(),
136139
}
137140
}

0 commit comments

Comments
 (0)