Skip to content

Commit 78efb23

Browse files
committed
Auto merge of #43691 - GuillaumeGomez:fix-rustdoc, r=QuietMisdreavus
Fix rustdoc Fixes #43625. r? @rust-lang/dev-tools cc @rust-lang/docs
2 parents 215e0b1 + ec0ca3a commit 78efb23

File tree

2 files changed

+25
-9
lines changed

2 files changed

+25
-9
lines changed

src/librustdoc/html/markdown.rs

+7-9
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ use std::ascii::AsciiExt;
3232
use std::cell::RefCell;
3333
use std::collections::{HashMap, VecDeque};
3434
use std::default::Default;
35-
use std::ffi::CString;
3635
use std::fmt::{self, Write};
3736
use std::str;
3837
use syntax::feature_gate::UnstableFeatures;
@@ -529,8 +528,8 @@ extern {
529528
fn hoedown_document_free(md: *mut hoedown_document);
530529

531530
fn hoedown_buffer_new(unit: libc::size_t) -> *mut hoedown_buffer;
532-
fn hoedown_buffer_puts(b: *mut hoedown_buffer, c: *const libc::c_char);
533531
fn hoedown_buffer_free(b: *mut hoedown_buffer);
532+
fn hoedown_buffer_put(b: *mut hoedown_buffer, c: *const u8, len: libc::size_t);
534533
}
535534

536535
impl hoedown_buffer {
@@ -620,8 +619,7 @@ pub fn render(w: &mut fmt::Formatter,
620619
Some("rust-example-rendered"),
621620
None,
622621
playground_button.as_ref().map(String::as_str)));
623-
let output = CString::new(s).unwrap();
624-
hoedown_buffer_puts(ob, output.as_ptr());
622+
hoedown_buffer_put(ob, s.as_ptr(), s.len());
625623
})
626624
}
627625
}
@@ -630,7 +628,7 @@ pub fn render(w: &mut fmt::Formatter,
630628
level: libc::c_int, data: *const hoedown_renderer_data,
631629
_: libc::size_t) {
632630
// hoedown does this, we may as well too
633-
unsafe { hoedown_buffer_puts(ob, "\n\0".as_ptr() as *const _); }
631+
unsafe { hoedown_buffer_put(ob, "\n".as_ptr(), 1); }
634632

635633
// Extract the text provided
636634
let s = if text.is_null() {
@@ -681,8 +679,7 @@ pub fn render(w: &mut fmt::Formatter,
681679
<a href='#{id}'>{sec}{}</a></h{lvl}>",
682680
s, lvl = level, id = id, sec = sec);
683681

684-
let text = CString::new(text).unwrap();
685-
unsafe { hoedown_buffer_puts(ob, text.as_ptr()) }
682+
unsafe { hoedown_buffer_put(ob, text.as_ptr(), text.len()); }
686683
}
687684

688685
extern fn codespan(
@@ -700,8 +697,9 @@ pub fn render(w: &mut fmt::Formatter,
700697
};
701698

702699
let content = format!("<code>{}</code>", Escape(&content));
703-
let element = CString::new(content).unwrap();
704-
unsafe { hoedown_buffer_puts(ob, element.as_ptr()); }
700+
unsafe {
701+
hoedown_buffer_put(ob, content.as_ptr(), content.len());
702+
}
705703
// Return anything except 0, which would mean "also print the code span verbatim".
706704
1
707705
}

src/test/rustdoc/nul-error.rs

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
// build-aux-docs
12+
// ignore-cross-compile
13+
14+
#![crate_name = "foo"]
15+
16+
// @has foo/fn.foo.html '//code' ''
17+
#[doc = "Attempted to pass a string containing `\0`"]
18+
pub fn foo() {}

0 commit comments

Comments
 (0)