rust-lang/rust-clippy

Warn about uses of Rust types where a C (raw) type is expected

Open

#1.631 geöffnet am 20. März 2017

Auf GitHub ansehen
 (4 Kommentare) (3 Reaktionen) (0 zugewiesene Personen)Rust (1.391 Forks)batch import
A-lintE-hardL-correctnessT-ASTgood first issue

Repository-Metriken

Stars
 (10.406 Stars)
PR-Merge-Metriken
 (Durchschn. Merge 19T 22h) (113 gemergte PRs in 30 T)

Beschreibung

I started using Rust on ARMv7 and run twice into issues where Rust types where used instead of c_* types.

  1. It should not be possible to use a C type in a function declaration and a Rust type when calling it (or vice versa.)
  2. Functions like CStr::from_ptr should not allow the use of a Rust type. It is clearly intended for use with c_char.

A few examples

This really should be libc::c_char (c_char is an alias for u8 on ARMv7)

CStr::from_ptr(ptr as *const i8)

Use of libc::c_char in declaration but when using the function i8 is used instead:

pub fn rados_append(io: rados_ioctx_t, oid: *const ::libc::c_char, buf: *const ::libc::c_char, len: size_t)
…
unsafe {
    rados_append(ctx, obj_name_str.as_ptr(), buffer.as_ptr() as *const i8, buffer.len());
}

Use of i64 instead of c_time (32bit on ARMv7):

   pub fn rados_ioctx_snap_get_stamp(io: rados_ioctx_t, id: rados_snap_t, t: *mut time_t) -> ::libc::c_int;
   …
    let mut time_id: i64 = 0;
    unsafe {
        rados_ioctx_snap_get_stamp(ctx, snap_id, &mut time_id);
   }

Contributor Guide