Skip to content

Commit

Permalink
Check that the feature strings are well-formed
Browse files Browse the repository at this point in the history
Assert that the feature strings are NUL terminated, so that they will
be well-formed as C strings.

This is a safety check to ease the maintaninace and update of the
feature lists.
  • Loading branch information
ranma42 committed Apr 20, 2016
1 parent deaa2fe commit ce99a5e
Showing 1 changed file with 1 addition and 0 deletions.
1 change: 1 addition & 0 deletions src/librustc_driver/target_features.rs
Expand Up @@ -54,6 +54,7 @@ pub fn add_configuration(cfg: &mut ast::CrateConfig, sess: &Session) {

let tf = InternedString::new("target_feature");
for feat in whitelist {
assert_eq!(feat.chars().last(), Some('\0'));
if unsafe { LLVMRustHasFeature(target_machine, feat.as_ptr() as *const c_char) } {
cfg.push(attr::mk_name_value_item_str(tf.clone(), intern(&feat[..feat.len()-1])))
}
Expand Down

0 comments on commit ce99a5e

Please sign in to comment.