Skip to content

Commit

Permalink
do not append on empty buffer (#268)
Browse files Browse the repository at this point in the history
Co-authored-by: Linwei Shang <[email protected]>
  • Loading branch information
chmllr and lwshang authored May 26, 2022
1 parent 468cc63 commit a080645
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 1 deletion.
4 changes: 4 additions & 0 deletions e2e-tests/canisters/reverse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,9 @@ fn reverse() {
assert_eq!(arg_bytes.len(), arg_data_raw_size());
reply_raw(arg_bytes.into_iter().rev().collect::<Vec<_>>().as_ref());
}
#[export_name = "canister_update empty_call"]
fn empty_call() {
reply_raw(&[]);
}

fn main() {}
5 changes: 5 additions & 0 deletions e2e-tests/tests/e2e.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,11 @@ fn test_raw_api() {

let result = env.query(canister_id, "reverse", vec![1, 2, 3, 4]).unwrap();
assert_eq!(result, WasmResult::Reply(vec![4, 3, 2, 1]));

let result = env
.execute_ingress(canister_id, "empty_call", Default::default())
.unwrap();
assert_eq!(result, WasmResult::Reply(Default::default()));
}

#[test]
Expand Down
1 change: 1 addition & 0 deletions src/ic-cdk/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Fixed
- Use explicitly type u8 in vector initialization (#264)
- Make `reply_raw` avoid writing empty replies
- Uses new format for candid environment variables in import macros. Requires DFX >=0.9.2 (#270)

## [0.5.1] - 2022-05-16
Expand Down
4 changes: 3 additions & 1 deletion src/ic-cdk/src/api/call.rs
Original file line number Diff line number Diff line change
Expand Up @@ -573,7 +573,9 @@ pub fn arg_data_raw_size() -> usize {
/// Replies with the bytes passed
pub fn reply_raw(buf: &[u8]) {
unsafe {
ic0::msg_reply_data_append(buf.as_ptr() as i32, buf.len() as i32);
if !buf.is_empty() {
ic0::msg_reply_data_append(buf.as_ptr() as i32, buf.len() as i32)
};
ic0::msg_reply();
}
}
Expand Down

0 comments on commit a080645

Please sign in to comment.