Skip to content

examples: fix index-out-of-bounds panic in bucket_add example#267

Open
aztecEagle22 wants to merge 1 commit intorecallnet:mainfrom
aztecEagle22:patch-1
Open

examples: fix index-out-of-bounds panic in bucket_add example#267
aztecEagle22 wants to merge 1 commit intorecallnet:mainfrom
aztecEagle22:patch-1

Conversation

@aztecEagle22
Copy link

What does this PR do?

Fixes an off-by-one error that causes the bucket_add example to panic before it even starts:

thread 'main' panicked at sdk/examples/bucket_add.rs:29:23:
index out of bounds: the len is 2 but the index is 2

THe code checks that args.len() is 2, because the key is in args[1] not args[2] since index 2 is out of bounds:

    if args.len() != 2 {
        return Err(anyhow!("Usage: [private key]"));
    }

    let pk_kex = &args[2];

The example now runs as intended:

$ cargo run --example bucket_add -- <HEX_PRIVATE_KEY>
Created new bucket …

Changes

  • sdk/examples/bucket_add.rs
    • Replace let pk_kex = &args[2]; with let pk_hex = &args[1];

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant