Fixes #36. The TestStruct instance did indeed crash as described in that issue before the fix was applied. The exact calculation used for off will still run into issues with Storable instances where sizeOf (or, even less commonly, alignment) changes depending on the data, but there's an argument to be made that any such instance is poorly-written to begin with, and uncommon enough that the cost in complexity outweighs the benefits. For the record, a complete fix would require something like the following (untested):
foldl' (\ptr a -> (ptr `alignPtr` alignment a) `plusPtr` sizeOf a) nullPtr (take (max 0 $ ix - 1) as) `alignPtr` (as !! ix) `minusPtr` nullPtr
Fixes #36. The
TestStruct
instance did indeed crash as described in that issue before the fix was applied. The exact calculation used foroff
will still run into issues withStorable
instances wheresizeOf
(or, even less commonly,alignment
) changes depending on the data, but there's an argument to be made that any such instance is poorly-written to begin with, and uncommon enough that the cost in complexity outweighs the benefits. For the record, a complete fix would require something like the following (untested):