MAIN FEEDS
Do you want to continue?
https://www.reddit.com/r/programming/comments/1w630ne/branchavoidant_programming/p7mglqn/?context=3
r/programming • u/fagnerbrack • Sep 03 '26
92 comments sorted by
View all comments
Show parent comment
4
What's wrong about it? If all the numbers are >= 500 then the length will be 0 and the array will be full of uninitialised data.
7 u/Nwallins Sep 03 '26 small_numbers[0] is unconditionally assigned; it will have a single element > 500. 7 u/nukethebees Sep 03 '26 Ah, thanks for pointing that out.It will have a value written to it, yes, but smlen will remain 0 in all cases so there shouldn't be any risk. In all cases the array has SIZE elements. smlen tells us how many contain valid numbers. 4 u/tiftik Sep 03 '26 Why does that assignment matter? You're not going to use any element at i >= smlen 1 u/sopunny Sep 03 '26 You can add a sanity check at the end for this edge case. I think you actually need to check the array trail every time
7
small_numbers[0] is unconditionally assigned; it will have a single element > 500.
7 u/nukethebees Sep 03 '26 Ah, thanks for pointing that out.It will have a value written to it, yes, but smlen will remain 0 in all cases so there shouldn't be any risk. In all cases the array has SIZE elements. smlen tells us how many contain valid numbers. 4 u/tiftik Sep 03 '26 Why does that assignment matter? You're not going to use any element at i >= smlen 1 u/sopunny Sep 03 '26 You can add a sanity check at the end for this edge case. I think you actually need to check the array trail every time
Ah, thanks for pointing that out.
It will have a value written to it, yes, but smlen will remain 0 in all cases so there shouldn't be any risk. In all cases the array has SIZE elements. smlen tells us how many contain valid numbers.
smlen
SIZE
Why does that assignment matter? You're not going to use any element at i >= smlen
1
You can add a sanity check at the end for this edge case. I think you actually need to check the array trail every time
View all comments
Show parent comment
4
u/nukethebees Sep 03 '26
What's wrong about it? If all the numbers are >= 500 then the length will be 0 and the array will be full of uninitialised data.