rust


Jack audio client name longer than 4 characters breaks client


Trying to use the JACK-AUDIO-CONNECTION-KIT from Rust (documentation), I run into problems calling
jack_client_t* jack_client_open ( const char * client_name,
jack_options_t options,
jack_status_t * status,
... )
In Rust I use
#[link(name = "jack")]
extern "C" {
pub fn jack_client_open(name: *const libc::c_char,
options: JackOptions,
status: &JackStatus)
-> *mut JackClientT;
}
(complete code)
When I use a name with four characters it works, e.g.
let name = CString::new("yass").unwrap().as_ptr();
but if I use 5 or more characters it doesn't work. In the JACK docs linked to above, it says that the name can be at most int jack_client_name_size() characters long, which is 64 in my case. Why does this happen?
let name = CString::new("yass").unwrap().as_ptr(); allocates a string, gets a pointer to it... then throws away the string, so you get a use-after-free. Don't do this. Write let name = CString::new("yass").unwrap();, then use name.as_ptr(). See also CStr::as_ptr and this RFC proposal.
Any suggestions to improve the documentation would be welcome.

Related Links

How to handle errors in mio?
Why is it discouraged to accept a reference to a String (&String) or Vec (&Vec) as a function argument?
Is `iter().map().sum()` as fast as `iter().fold()`?
How to dump a complete list of compiler attributes in Rust?
Deriving a trait results in unexpected compiler error, but the manual implementation works
–°annot move out of borrowed content for a struct
rustc_serialize::Json value borrowed in a while loop does not live enough
Is there a more beautiful way to convert a character literal to its corresponding escape character?
How to quiet a warning for a single statement in Rust?
Make object expire given a state change in Rust
Is there a way to determine the offsets of each of the trait methods in the VTable?
Is it possible to return something or nothing?
How do I read multiple integers from a single line of stdin?
Cannot immediately decode an object written to a file with bincode
Type mismatch with closure
Satisfying the Rust borrow checker with structs

Categories

HOME
xcode
windows-8.1
concurrency
writefile
loopbackjs
iverilog
vsts-build
magento-2.0
semantic-web
qooxdoo
azure-mobile-services
impala
haxe
onvif
wagtail
bellman-ford
match
business-intelligence
dhcp
dma
maven-plugin
gmp
spam
home
amazon-mws
social-tables
gitkraken
anova
stackexchange.redis
uri
xdebug
hevc
iwebbrowser2
d3.js-v4
tightvnc
vcenter
steam-web-api
snap-framework
xmlunit
express-session
xvfb
ms-dos
cheat-engine
tidal-scheduler
grunt-contrib-watch
utf
hypothesis-test
coverage.py
haar-classifier
dbcc
expandablelistview
amazon-elastic-beanstalk
redisson
solr-query-syntax
degrees
openerp-6
multi-touch
fuzzer
eclemma
exists
utf-16
taco
largenumber
lowercase
place
auto-generate
dynamics-ax-2012-r2
kefir.js
uno
ildasm
device-admin
osascript
accessory
distributed-r
sqlbindparameter
jack
gpu-programming
nosql-aggregation
principalcontext
autonumber
grails-2.3
non-ascii-characters
unicoins
reentrancy
jsplitpane
playorm
voice-recording
prototypal-inheritance
exponent
tablet-pc
upshot
asp.net-mvc-views
cassini
rational-unified-process
spring-modules

Resources

Database Users
RDBMS discuss
Database Dev&Adm
javascript
java
csharp
php
android
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App