aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndroid Build Coastguard Worker <android-build-coastguard-worker@google.com>2024-02-02 23:52:07 +0000
committerAndroid Build Coastguard Worker <android-build-coastguard-worker@google.com>2024-02-02 23:52:07 +0000
commitd7451677ff61eb73164190ff419f7b93be04ce28 (patch)
tree243037fd02a49b4da66e5eab487066b2038b3166
parent98ca0bead6c7d1e23cf590c2b2c4c742b4554def (diff)
parentbadce5123634a0535e2bc420d1ba5782638092e7 (diff)
downloadbitreader-simpleperf-release.tar.gz
Snap for 11400057 from badce5123634a0535e2bc420d1ba5782638092e7 to simpleperf-releasesimpleperf-release
Change-Id: I846f193cde8ee894d81f9fb031cc0e56b9aa723b
-rw-r--r--.cargo_vcs_info.json6
-rw-r--r--.github/workflows/rust.yml22
-rw-r--r--.gitignore3
-rw-r--r--Android.bp2
-rw-r--r--Cargo.toml37
-rw-r--r--Cargo.toml.orig2
-rw-r--r--LICENSE-MIT25
-rw-r--r--METADATA26
-rw-r--r--src/lib.rs4
-rw-r--r--src/tests.rs15
10 files changed, 114 insertions, 28 deletions
diff --git a/.cargo_vcs_info.json b/.cargo_vcs_info.json
new file mode 100644
index 0000000..6998af2
--- /dev/null
+++ b/.cargo_vcs_info.json
@@ -0,0 +1,6 @@
+{
+ "git": {
+ "sha1": "506cbba158e26180a114fe3769578c14f1d78657"
+ },
+ "path_in_vcs": ""
+} \ No newline at end of file
diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml
new file mode 100644
index 0000000..14e166a
--- /dev/null
+++ b/.github/workflows/rust.yml
@@ -0,0 +1,22 @@
+name: build
+
+on:
+ push:
+ branches: [ "master" ]
+ pull_request:
+ branches: [ "master" ]
+
+env:
+ CARGO_TERM_COLOR: always
+
+jobs:
+ build:
+
+ runs-on: ubuntu-latest
+
+ steps:
+ - uses: actions/checkout@v3
+ - name: Build
+ run: cargo build --verbose
+ - name: Run tests
+ run: cargo test --verbose
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..64f40ab
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,3 @@
+target
+Cargo.lock
+.idea
diff --git a/Android.bp b/Android.bp
index fcae469..165e953 100644
--- a/Android.bp
+++ b/Android.bp
@@ -23,7 +23,7 @@ rust_library {
host_supported: true,
crate_name: "bitreader",
cargo_env_compat: true,
- cargo_pkg_version: "0.3.6",
+ cargo_pkg_version: "0.3.8",
srcs: ["src/lib.rs"],
edition: "2015",
features: [
diff --git a/Cargo.toml b/Cargo.toml
index 4ec13d2..4ffa549 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -1,27 +1,38 @@
+# THIS FILE IS AUTOMATICALLY GENERATED BY CARGO
+#
+# When uploading crates to the registry Cargo will automatically
+# "normalize" Cargo.toml files for maximal compatibility
+# with all versions of Cargo and also rewrite `path` dependencies
+# to registry (e.g., crates.io) dependencies.
+#
+# If you are reading this file be aware that the original Cargo.toml
+# will likely look very different (and much more reasonable).
+# See Cargo.toml.orig for the original contents.
+
[package]
name = "bitreader"
-version = "0.3.6"
+version = "0.3.8"
authors = ["Ilkka Rauta <ilkka.rauta@gmail.com>"]
-
description = """
BitReader helps reading individual bits from a slice of bytes.
-You can read "unusual" numbers of bits from the byte slice, for example 13 bits
+You can read \"unusual\" numbers of bits from the byte slice, for example 13 bits
at once. The reader internally keeps track of position within the buffer.
"""
-
-documentation = "https://docs.rs/bitreader"
homepage = "https://github.com/irauta/bitreader"
-repository = "https://github.com/irauta/bitreader"
-
-keywords = ["bit", "bits", "bitstream"]
-
+documentation = "https://docs.rs/bitreader"
+readme = "README.md"
+keywords = [
+ "bit",
+ "bits",
+ "bitstream",
+]
license = "MIT OR Apache-2.0"
+repository = "https://github.com/irauta/bitreader"
-[dependencies]
-cfg-if = "1"
+[dependencies.cfg-if]
+version = "1"
[features]
-std = []
-
default = ["std"]
+std = []
diff --git a/Cargo.toml.orig b/Cargo.toml.orig
index 4ec13d2..33cc434 100644
--- a/Cargo.toml.orig
+++ b/Cargo.toml.orig
@@ -1,6 +1,6 @@
[package]
name = "bitreader"
-version = "0.3.6"
+version = "0.3.8"
authors = ["Ilkka Rauta <ilkka.rauta@gmail.com>"]
description = """
diff --git a/LICENSE-MIT b/LICENSE-MIT
new file mode 100644
index 0000000..f8bbc4d
--- /dev/null
+++ b/LICENSE-MIT
@@ -0,0 +1,25 @@
+Copyright (c) 2015 Ilkka Rauta
+
+Permission is hereby granted, free of charge, to any
+person obtaining a copy of this software and associated
+documentation files (the "Software"), to deal in the
+Software without restriction, including without
+limitation the rights to use, copy, modify, merge,
+publish, distribute, sublicense, and/or sell copies of
+the Software, and to permit persons to whom the Software
+is furnished to do so, subject to the following
+conditions:
+
+The above copyright notice and this permission notice
+shall be included in all copies or substantial portions
+of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF
+ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
+TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
+PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT
+SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
+IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+DEALINGS IN THE SOFTWARE.
diff --git a/METADATA b/METADATA
index 8884e7f..b998ed7 100644
--- a/METADATA
+++ b/METADATA
@@ -1,20 +1,20 @@
+# This project was upgraded with external_updater.
+# Usage: tools/external_updater/updater.sh update external/rust/crates/bitreader
+# For more info, check https://cs.android.com/android/platform/superproject/+/main:tools/external_updater/README.md
+
name: "bitreader"
description: "BitReader helps reading individual bits from a slice of bytes. You can read \"unusual\" numbers of bits from the byte slice, for example 13 bits at once. The reader internally keeps track of position within the buffer."
third_party {
- url {
- type: HOMEPAGE
- value: "https://crates.io/crates/bitreader"
- }
- url {
- type: ARCHIVE
- value: "https://static.crates.io/crates/bitreader/bitreader-0.3.6.crate"
- }
- version: "0.3.6"
- # Dual-licensed, using the least restrictive per go/thirdpartylicenses#same.
license_type: NOTICE
last_upgrade_date {
- year: 2022
- month: 11
- day: 2
+ year: 2024
+ month: 1
+ day: 31
+ }
+ homepage: "https://crates.io/crates/bitreader"
+ identifier {
+ type: "Archive"
+ value: "https://static.crates.io/crates/bitreader/bitreader-0.3.8.crate"
+ version: "0.3.8"
}
}
diff --git a/src/lib.rs b/src/lib.rs
index 6c85391..e62571a 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -322,6 +322,10 @@ impl<'a> BitReader<'a> {
// depending on the sign bit.
let sign_bit = unsigned >> (bit_count - 1) & 1;
let high_bits = if sign_bit == 1 { -1 } else { 0 };
+ if bit_count == 64 {
+ // Avoid left-shift-with-overflow exception
+ return Ok(unsigned as i64);
+ }
Ok(high_bits << bit_count | unsigned as i64)
}
diff --git a/src/tests.rs b/src/tests.rs
index f91a23b..452070a 100644
--- a/src/tests.rs
+++ b/src/tests.rs
@@ -221,6 +221,7 @@ fn signed_values() {
}
}
+#[cfg(feature = "std")]
#[test]
fn boolean_values() {
let bytes: Vec<u8> = (0..16).collect();
@@ -314,3 +315,17 @@ fn relative_reader() {
requested: 1
});
}
+
+#[test]
+fn test_read_u64_max() {
+ let bytes = &[0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF];
+ let mut reader = BitReader::new(bytes);
+ assert_eq!(reader.read_u64(64).unwrap(), u64::MAX);
+}
+
+#[test]
+fn test_read_i64_max() {
+ let bytes = &[0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF];
+ let mut reader = BitReader::new(bytes);
+ assert_eq!(reader.read_i64(64).unwrap(), -1);
+}