Skip to content

Corrupted memory after updated to 1.12 #36936

Closed

Description

Hello!
I see some garbage in memory:

    use super::yaml_rust::{YamlLoader, Yaml};
    use std::collections::HashMap;

    #[test]
    fn test_yaml() {
        let test_data = r#"
Property1:
  data: Value1

Property2:
  data: Value2

Property3:
  data: Value3

"#;
        let mut check_data = HashMap::new();
        check_data.insert("Property1","Value1");
        check_data.insert("Property2","Value2");
        check_data.insert("Property3","Value3");

        let scheme = &(YamlLoader::load_from_str(test_data).unwrap() as Vec<Yaml>)[0];
        for (key, value) in {
            if let Yaml::Hash(ref x) = *scheme {
                x // if write here "x.clone()", OK
            } else {
                panic!("Bad format")
            }
        } {

            println!("{:?}: {:?};", key, value);
            if check_data[key.as_str().unwrap()] != value["data"].as_str().unwrap() {
                panic!("\nkey: {:?} ,data: {:?} ≠ {:?}\n",
                       key.as_str().unwrap(),
                       check_data[key.as_str().unwrap()],
                       value["data"].as_str().unwrap()
                );

            }
        }
    }

I expect correct return (like with rust 1.11), but I have panic:

Rust 1.12

$ rustup run stable cargo test test_yaml
   Compiling yaml-rust v0.3.3 (https://github.com/chyh1990/yaml-rust.git#f7d2897b)
   Compiling …
    Finished debug [unoptimized + debuginfo] target(s) in 6.13 secs
     Running target/debug/…

running 1 test
test test_yaml ... FAILED

failures:

---- test_yaml stdout ----
        String("Property1"): Hash({String("data"): String("Value1")});
String("Property2"): Hash({String("data"): String("Value2")});
String("String(\"3"): Hash({String("data"): String("datang")});
thread 'test_yaml' panicked at 'no entry found for key', ../src/libcore/option.rs:700
note: Run with `RUST_BACKTRACE=1` for a backtrace.

failures:
    scheme::test::test_yaml

test result: FAILED. 0 passed; 1 failed; 0 ignored; 0 measured

error: test failed

Rust 1.11

$ rustup run 1.11.0 cargo test test_yaml
   Compiling yaml-rust v0.3.3 (https://github.com/chyh1990/yaml-rust.git#f7d2897b)
   Compiling …
     Running target/debug/…

running 1 test
test test_yaml ... ok

test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured

Data corrupted always in last record.
Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

Labels

T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.regression-from-stable-to-stablePerformance or correctness regression from one stable version to another.Performance or correctness regression from one stable version to another.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions