From 4a9f45531d889094f8d1c6b3568706d9c63097c1 Mon Sep 17 00:00:00 2001 From: Gavin Wood Date: Wed, 11 Sep 2019 15:34:28 +0200 Subject: [PATCH 1/2] Update with_std.rs --- core/sr-io/with_std.rs | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/core/sr-io/with_std.rs b/core/sr-io/with_std.rs index ff377b3358df0..d630a4942db7a 100644 --- a/core/sr-io/with_std.rs +++ b/core/sr-io/with_std.rs @@ -54,11 +54,9 @@ impl StorageApi for () { fn read_storage(key: &[u8], value_out: &mut [u8], value_offset: usize) -> Option { ext::with(|ext| ext.storage(key).map(|value| { - if value_offset < value.len() { - let value = &value[value_offset..]; - let written = std::cmp::min(value.len(), value_out.len()); - value_out[..written].copy_from_slice(&value[..written]); - } + let value = &value[value_offset.min(value.len())..]; + let written = std::cmp::min(value.len(), value_out.len()); + value_out[..written].copy_from_slice(&value[..written]); value.len() })).expect("read_storage cannot be called outside of an Externalities-provided environment.") } From 32506e5145b4daa781b13880211c152adfad81b7 Mon Sep 17 00:00:00 2001 From: Gavin Wood Date: Wed, 11 Sep 2019 15:36:05 +0200 Subject: [PATCH 2/2] Update with_std.rs --- core/sr-io/with_std.rs | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/core/sr-io/with_std.rs b/core/sr-io/with_std.rs index d630a4942db7a..45c0c9f824465 100644 --- a/core/sr-io/with_std.rs +++ b/core/sr-io/with_std.rs @@ -85,11 +85,9 @@ impl StorageApi for () { let storage_key = child_storage_key_or_panic(storage_key); ext.child_storage(storage_key, key) .map(|value| { - if value_offset < value.len() { - let value = &value[value_offset..]; - let written = std::cmp::min(value.len(), value_out.len()); - value_out[..written].copy_from_slice(&value[..written]); - } + let value = &value[value_offset.min(value.len())..]; + let written = std::cmp::min(value.len(), value_out.len()); + value_out[..written].copy_from_slice(&value[..written]); value.len() }) })