Skip to content

Fix size check when result length exceeds sum of inputs#7

Open
jackscan wants to merge 1 commit intoinspier:masterfrom
jackscan:master
Open

Fix size check when result length exceeds sum of inputs#7
jackscan wants to merge 1 commit intoinspier:masterfrom
jackscan:master

Conversation

@jackscan
Copy link

The current size check is only catching cases where the inferred result array length is shorter than the sum of the input array lengths.
Longer arrays are accepted and the following code is currently compiling:
let c: [u32; 6] = concat_array!([1, 2, 3], [4, 5]);
This results in an array with undefined values.

@Daniel-Aaron-Bloom
Copy link
Contributor

Good find. Can you add a test case?

@jackscan
Copy link
Author

I added doc tests with examples which are supposed to fail.

@Daniel-Aaron-Bloom
Copy link
Contributor

Oh, one more thing. Can you fix the same check in split_array? PANIC there should also be impacted in the same way if I'm not mistaken.

Ensure the union fields of ArrayConcatComposed have matching sizes by
updating the size validations in the macros concat_array and
split_array.

Previously, the size check in concat_arrays were only catching cases
where the inferred result type was shorter than the sum of input array
lengths. It failed to detect longer result arrays, since the size of
Self matches its biggest union field.
For example, this compiled without error:
let c: [u32; 6] = concat_arrays!([1, 2, 3], [4, 5]);
This led to arrays containing undefined values.
The same applied for split_array when the input array is longer than
the sum of the output array lengths. While this did not lead to
undefined values, the exceeding elements would not be dropped.
@jackscan
Copy link
Author

I've updated the commit to include fix for size check in split_array.
Sry for the late response.

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.

2 participants