Skip to content

Commit

Permalink
Merge pull request #2137 from weiznich/fix/remove_mem_uninitialized
Browse files Browse the repository at this point in the history
Fix/remove mem uninitialized
  • Loading branch information
weiznich authored Aug 7, 2019
2 parents 0cacfa0 + 9e9802d commit b649a86
Show file tree
Hide file tree
Showing 9 changed files with 19 additions and 16 deletions.
6 changes: 3 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ matrix:
env: RUSTFLAGS="--cap-lints=warn"
script:
- (cd diesel_compile_tests && cargo +$TRAVIS_RUST_VERSION test)
- rust: 1.34.0
- rust: 1.36.0
name: "Rustfmt && Clippy"
script:
- rustup component add rustfmt clippy
Expand All @@ -60,8 +60,8 @@ matrix:
- SQLITE_DATABASE_URL=/tmp/test.db
script:
- (cd diesel_cli && cargo +$TRAVIS_RUST_VERSION test --no-default-features --features "sqlite-bundled")
- rust: 1.34.0
name: "Minimal supported rust version == 1.34.0"
- rust: 1.36.0
name: "Minimal supported rust version == 1.36.0"
script:
- cargo +$TRAVIS_RUST_VERSION check --all

Expand Down
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ for Rust libraries in [RFC #1105](https://github.com/rust-lang/rfcs/blob/master/
`&DB::RawValue` or `&<DB as Backend>::RawValue>`) should use
[`backend::RawValue<DB>`][raw-value-2-0-0] instead. Implementors of `Backend`
should check the relevant section of [the migration guide][2-0-migration].
* The minimal officially supported rustc version is now 1.34.0

[backend-2-0-0]: http://docs.diesel.rs/diesel/backend/trait.Backend.html
[raw-value-2-0-0]: http://docs.diesel.rs/diesel/backend/type.RawValue.html
Expand All @@ -38,6 +37,8 @@ for Rust libraries in [RFC #1105](https://github.com/rust-lang/rfcs/blob/master/
`Mysql::TypeMetadata`, you will need to take the new struct
`MysqlTypeMetadata` instead.

* The minimal officially supported rustc version is now 1.36.0

### Fixed

* Many types were incorrectly considered non-aggregate when they should not
Expand Down
6 changes: 3 additions & 3 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ jobs:
- template: _build/install-rust.yml
parameters:
platform: Linux
rust_version: 1.34.0
rust_version: 1.36.0
- bash: |
sudo apt-get update &&
sudo apt-get -y install libsqlite3-dev libpq-dev libmysqlclient-dev
Expand Down Expand Up @@ -241,11 +241,11 @@ jobs:
- template: _build/install-rust.yml
parameters:
platform: Linux
rust_version: 1.34.0
rust_version: 1.36.0
- bash: |
sudo apt-get update &&
sudo apt-get -y install libsqlite3-dev libpq-dev libmysqlclient-dev
displayName: Install build dependencies
- bash: |
cargo check --all
displayName: Check building with rust 1.34.0
displayName: Check building with rust 1.36.0
2 changes: 1 addition & 1 deletion clippy.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
cyclomatic-complexity-threshold = 30
cognitive-complexity-threshold = 30
doc-valid-idents = [
"MiB", "GiB", "TiB", "PiB", "EiB",
"DirectX", "OpenGL", "TrueType",
Expand Down
2 changes: 1 addition & 1 deletion diesel/src/expression/functions/date_and_time.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ sql_function! {
/// ```ignore
/// # #[macro_use] extern crate diesel;
/// # extern crate chrono;
/// # include!(\"../../doctest_setup.rs\");
/// # include!("../../doctest_setup.rs");
/// # use diesel::dsl::*;
/// #
/// # fn main() {
Expand Down
7 changes: 3 additions & 4 deletions diesel/src/mysql/types/date_and_time.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,13 @@ macro_rules! mysql_time_impls {
}

impl FromSql<$ty, Mysql> for ffi::MYSQL_TIME {
// ptr::copy_nonoverlapping does not require aligned pointers
#[allow(clippy::cast_ptr_alignment)]
fn from_sql(bytes: Option<&[u8]>) -> deserialize::Result<Self> {
let bytes = not_none!(bytes);
let bytes_ptr = bytes.as_ptr() as *const ffi::MYSQL_TIME;
unsafe {
let mut result = mem::uninitialized();
ptr::copy_nonoverlapping(bytes_ptr, &mut result, 1);
let mut result = mem::MaybeUninit::uninit();
ptr::copy_nonoverlapping(bytes_ptr, result.as_mut_ptr(), 1);
let result = result.assume_init();
if result.neg == 0 {
Ok(result)
} else {
Expand Down
5 changes: 4 additions & 1 deletion diesel/src/serialize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,10 @@ impl<DB: TypeMetadata> Output<'static, Vec<u8>, DB> {
/// Unsafe to use for testing types which perform dynamic metadata lookup.
pub fn test() -> Self {
use std::mem;
#[allow(clippy::invalid_ref)]
// Allowing `deprecated` here because we are ok with using `mem::uninitialized`
// here. (Yes it's UB, but that won't be fixed by using `mem::MaybeUninit`
// but hey it's only for test code …)
#[allow(clippy::invalid_ref, deprecated)]
Self::new(Vec::new(), unsafe { mem::uninitialized() })
}
}
Expand Down
2 changes: 1 addition & 1 deletion diesel_derives/src/sql_function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use meta::*;
use util::*;

// Extremely curious why this triggers on a nearly branchless function
#[allow(clippy::cyclomatic_complexity)]
#[allow(clippy::cognitive_complexity)]
pub(crate) fn expand(input: SqlFunctionDecl) -> Result<TokenStream, Diagnostic> {
let SqlFunctionDecl {
mut attributes,
Expand Down
2 changes: 1 addition & 1 deletion rust-toolchain
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.34.0
1.36.0

0 comments on commit b649a86

Please sign in to comment.