{"action":"created","issue":{"url":"https://api.github.com/repos/rust-lang/libc/issues/4","labels_url":"https://api.github.com/repos/rust-lang/libc/issues/4/labels{/name}","comments_url":"https://api.github.com/repos/rust-lang/libc/issues/4/comments","events_url":"https://api.github.com/repos/rust-lang/libc/issues/4/events","html_url":"https://github.com/rust-lang/libc/issues/4","id":66179974,"number":4,"title":"Passing c_chars to C/C++ results in random gibberish","user":{"login":"boghison","id":7976283,"avatar_url":"https://avatars.githubusercontent.com/u/7976283?v=3","gravatar_id":"","url":"https://api.github.com/users/boghison","html_url":"https://github.com/boghison","followers_url":"https://api.github.com/users/boghison/followers","following_url":"https://api.github.com/users/boghison/following{/other_user}","gists_url":"https://api.github.com/users/boghison/gists{/gist_id}","starred_url":"https://api.github.com/users/boghison/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/boghison/subscriptions","organizations_url":"https://api.github.com/users/boghison/orgs","repos_url":"https://api.github.com/users/boghison/repos","events_url":"https://api.github.com/users/boghison/events{/privacy}","received_events_url":"https://api.github.com/users/boghison/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":12,"created_at":"2015-04-03T16:27:45Z","updated_at":"2015-04-08T17:44:19Z","closed_at":"2015-04-08T17:40:19Z","body":"Using CString, I am passing c_chars to a function in C++ (defined with extern \"C\" of course). I tried debugging and on the Rust side, the strings get printed correctly, while on the C++ side it results in \r\n`^X0�;�^? @��D�^?`. Sometimes only one argument gets corrupted, sometimes two (like here). The weirdest thing is that after this, the arguments get passed correctly, but not to the right place. So if I have 4 arguments in C and the first 2 get corrupted, the third one will actually be the value of the fist one in Rust. \r\nIs this a nul terminator issue? Quoting the CString documentation:\r\n > An instance of this type is a static guarantee that the underlying bytes contain no interior 0 bytes and the final byte is 0."},"comment":{"url":"https://api.github.com/repos/rust-lang/libc/issues/comments/90985653","html_url":"https://github.com/rust-lang/libc/issues/4#issuecomment-90985653","issue_url":"https://api.github.com/repos/rust-lang/libc/issues/4","id":90985653,"user":{"login":"alexcrichton","id":64996,"avatar_url":"https://avatars.githubusercontent.com/u/64996?v=3","gravatar_id":"","url":"https://api.github.com/users/alexcrichton","html_url":"https://github.com/alexcrichton","followers_url":"https://api.github.com/users/alexcrichton/followers","following_url":"https://api.github.com/users/alexcrichton/following{/other_user}","gists_url":"https://api.github.com/users/alexcrichton/gists{/gist_id}","starred_url":"https://api.github.com/users/alexcrichton/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/alexcrichton/subscriptions","organizations_url":"https://api.github.com/users/alexcrichton/orgs","repos_url":"https://api.github.com/users/alexcrichton/repos","events_url":"https://api.github.com/users/alexcrichton/events{/privacy}","received_events_url":"https://api.github.com/users/alexcrichton/received_events","type":"User","site_admin":false},"created_at":"2015-04-08T17:44:19Z","updated_at":"2015-04-08T17:44:19Z","body":"You probably want to change the signature in Rust to:\r\n\r\n```rust\r\nextern {\r\n    fn c_call(rust_struct: *mut VoidStruct,\r\n              char1: *const c_char,\r\n              char2: *const c_char,\r\n              char3: *const c_char,\r\n              char4: *const c_char,\r\n              char5: *const c_char,\r\n              char6: *const c_char);\r\n}\r\n```\r\n\r\n(note the `*mut` on the first argument)"}}