ArrayString::push_str: Write capacity check in safer style

Use an arithmetic overflow safe conditional.
This commit is contained in:
bluss
2015-12-22 08:07:36 +01:00
parent 440bcbf66b
commit d991c17a25
+1 -1
View File
@@ -99,7 +99,7 @@ impl<A: Array<Item=u8>> ArrayString<A> {
pub fn push_str<'a>(&mut self, s: &'a str) -> Result<(), CapacityError<&'a str>> {
use std::io::Write;
if self.len() + s.len() > self.capacity() {
if s.len() > self.capacity() - self.len() {
return Err(CapacityError::new(s));
}
unsafe {