Merge pull request #182 from alanhdu/master

Fix some fuzzing bugs
This commit is contained in:
Alex Crichton 2017-05-30 19:35:42 -05:00 committed by GitHub
commit b0b9196d43
4 changed files with 8 additions and 6 deletions

View file

@ -55,7 +55,7 @@ struct Time {
hour: u8, hour: u8,
minute: u8, minute: u8,
second: u8, second: u8,
secfract: Option<f64>, secfract: f64,
} }
#[derive(PartialEq, Clone)] #[derive(PartialEq, Clone)]
@ -97,8 +97,8 @@ impl fmt::Display for Date {
impl fmt::Display for Time { impl fmt::Display for Time {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{:02}:{:02}:{:02}", self.hour, self.minute, self.second)?; write!(f, "{:02}:{:02}:{:02}", self.hour, self.minute, self.second)?;
if let Some(i) = self.secfract { if self.secfract != 0.0 {
let s = format!("{}", i); let s = format!("{}", self.secfract);
write!(f, "{}", s.trim_left_matches("0"))?; write!(f, "{}", s.trim_left_matches("0"))?;
} }
Ok(()) Ok(())
@ -219,11 +219,11 @@ impl FromStr for Datetime {
} }
chars = whole[end..].chars(); chars = whole[end..].chars();
match format!("0.{}", &whole[..end]).parse() { match format!("0.{}", &whole[..end]).parse() {
Ok(f) => Some(f), Ok(f) => f,
Err(_) => return Err(DatetimeParseError { _private: () }), Err(_) => return Err(DatetimeParseError { _private: () }),
} }
} else { } else {
None 0.0
}; };
let time = Time { let time = Time {

View file

@ -290,7 +290,7 @@ impl<'a> Serializer<'a> {
'\u{22}' => drop(write!(self.dst, "\\\"")), '\u{22}' => drop(write!(self.dst, "\\\"")),
'\u{5c}' => drop(write!(self.dst, "\\\\")), '\u{5c}' => drop(write!(self.dst, "\\\\")),
c if c < '\u{1f}' => { c if c < '\u{1f}' => {
drop(write!(self.dst, "\\u{:04}", ch as u32)) drop(write!(self.dst, "\\u{:04X}", ch as u32))
} }
ch => drop(write!(self.dst, "{}", ch)), ch => drop(write!(self.dst, "{}", ch)),
} }

View file

@ -1,4 +1,5 @@
{ {
"answer1": {"type": "string", "value": "\u000B"},
"answer4": {"type": "string", "value": "\u03B4α"}, "answer4": {"type": "string", "value": "\u03B4α"},
"answer8": {"type": "string", "value": "\u03B4β"} "answer8": {"type": "string", "value": "\u03B4β"}
} }

View file

@ -1,2 +1,3 @@
answer1 = "\u000B"
answer4 = "\u03B4α" answer4 = "\u03B4α"
answer8 = "\U000003B4β" answer8 = "\U000003B4β"