JuliaLang/julia — pull request #8302 by danluu (2014-09-11 01:08:47+00:00)
Title: Prevent Array(foo, n) from returning an array of the wrong size

~~~
julia> Array(Int, -14195763867060736356299439484696781493)
4611694853239872843-element Array{Int64,1}:
...

julia> x = int128(2)^65+10
36893488147419103242

julia> Array(Int, x)
10-element Array{Int64,1}:
...
~~~

The first statement only fails on my mac (10.9.2), but the second returns a mis-sized array on both linux and mac.

This could also be fixed by passing an `Int128` to `jl_alloc_array*` and changing `_new_array_`. But, currently, both of my machines use `uint64_t` for the internal calculations because of this typedef:

~~~
#if defined(_P64) && defined(UINT128MAX)
typedef __uint128_t wideint_t;
#else
typedef uint64_t wideint_t;
#endif
~~~

Sorry for the all of the weird corner case issue spam; I spent a few minutes [a really simplistic fuzzer](https://github.com/danluu/Fuzz.jl). It's found a couple of bugs I could imagine actually running into, and a bunch of obscure issues like this one. IME, it's more effective to fix these really unlikely bugs than it is to try to target "good" bugs, and I've heard that mozilla had the same experience with jsfunfuzz.