libcvd
libcvd copied to clipboard
CVD_IMAGE_DEBUG and bounds checking with img[y][x] syntax
The CVD_IMAGE_DEBUG
macro is very useful for checking out-of-bounds memory violations, but it does not work in many cases throughout the CVD library where the img[y][x]
syntax is used.
One idea is when CVD_IMAGE_DEBUG
is defined img[y]
returns a BoundsCheckedBuffer<T>
instead of a T*
. BoundsCheckedBuffer<T>
is a type that behaves like a T*
but returns an error when an attempt is made to access outside the horizontal scan-line. The only situation where this would not work is when a type is specialized on a T*
but I imagine this case is rare.
On 19 April 2017 at 18:58, Damian Eads [email protected] wrote:
The CVD_IMAGE_DEBUG macro is very useful for checking out-of-bounds memory violations, but it does not work in many cases throughout the CVD library where the img[y][x] syntax is used.
One idea is when CVD_IMAGE_DEBUG is defined img[y] returns a BoundsCheckedBuffer<T> instead of a T*. BoundsCheckedBuffer<T> is a type that behaves like a T* but returns an error when an attempt is made to access outside the horizontal scan-line. The only situation where this would not work is when a type is specialized on a T* but I imagine this case is rare.
Oh yes this one :)
I think a bounds checked buffer would be entirely fine. I'm pretty sure that these days with a modern optimizer, it would be equally efficient.
An alternative option would be to use something like span from the GSL.
-Ed
— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/edrosten/libcvd/issues/30, or mute the thread https://github.com/notifications/unsubscribe-auth/ABGW641YqWd7iFXefmDdho_8mdslZ4k9ks5rxktLgaJpZM4NCB8d .
array_view or span would work exactly like that. these classes are great, make defining APIs much more flexible.
cheers, Gerhard
On Wed, Apr 19, 2017 at 9:24 PM, Edward Rosten [email protected] wrote:
On 19 April 2017 at 18:58, Damian Eads [email protected] wrote:
The CVD_IMAGE_DEBUG macro is very useful for checking out-of-bounds memory violations, but it does not work in many cases throughout the CVD library where the img[y][x] syntax is used.
One idea is when CVD_IMAGE_DEBUG is defined img[y] returns a BoundsCheckedBuffer<T> instead of a T*. BoundsCheckedBuffer<T> is a type that behaves like a T* but returns an error when an attempt is made to access outside the horizontal scan-line. The only situation where this would not work is when a type is specialized on a T* but I imagine this case is rare.
Oh yes this one :)
I think a bounds checked buffer would be entirely fine. I'm pretty sure that these days with a modern optimizer, it would be equally efficient.
An alternative option would be to use something like span from the GSL.
-Ed
— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/edrosten/libcvd/issues/30, or mute the thread <https://github.com/notifications/unsubscribe- auth/ABGW641YqWd7iFXefmDdho_8mdslZ4k9ks5rxktLgaJpZM4NCB8d> .
— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/edrosten/libcvd/issues/30#issuecomment-295401504, or mute the thread https://github.com/notifications/unsubscribe-auth/AAyvIHSEQOCTJ8ukwjuyCNIKhDiniOhFks5rxl9cgaJpZM4NCB8d .
On 19 April 2017 at 21:27, Gerhard Reitmayr [email protected] wrote:
array_view or span would work exactly like that. these classes are great, make defining APIs much more flexible.
Seems like array_view has been bumped from C++17 so span from the GSL seems the obvious choice.
The main problem I see is which GSL, and how to avoid clashing with the GSL that a user might have in their program. Wee could make it a hard dependency, but so far, CVD has none of those, though perhaps that ought to change.
-Ed
cheers, Gerhard
On Wed, Apr 19, 2017 at 9:24 PM, Edward Rosten [email protected] wrote:
On 19 April 2017 at 18:58, Damian Eads [email protected] wrote:
The CVD_IMAGE_DEBUG macro is very useful for checking out-of-bounds memory violations, but it does not work in many cases throughout the CVD library where the img[y][x] syntax is used.
One idea is when CVD_IMAGE_DEBUG is defined img[y] returns a BoundsCheckedBuffer<T> instead of a T*. BoundsCheckedBuffer<T> is a type that behaves like a T* but returns an error when an attempt is made to access outside the horizontal scan-line. The only situation where this would not work is when a type is specialized on a T* but I imagine this case is rare.
Oh yes this one :)
I think a bounds checked buffer would be entirely fine. I'm pretty sure that these days with a modern optimizer, it would be equally efficient.
An alternative option would be to use something like span from the GSL.
-Ed
— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/edrosten/libcvd/issues/30, or mute the thread <https://github.com/notifications/unsubscribe- auth/ABGW641YqWd7iFXefmDdho_8mdslZ4k9ks5rxktLgaJpZM4NCB8d> .
— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/edrosten/libcvd/issues/30#issuecomment-295401504, or mute the thread <https://github.com/notifications/unsubscribe-auth/ AAyvIHSEQOCTJ8ukwjuyCNIKhDiniOhFks5rxl9cgaJpZM4NCB8d> .
— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/edrosten/libcvd/issues/30#issuecomment-295426274, or mute the thread https://github.com/notifications/unsubscribe-auth/ABGW687kpykgfRQAy6hKFhmxi0jiSodyks5rxm4XgaJpZM4NCB8d .
Perfect. I suppose the only issue is that GSL requires GCC-5.1 and above. This is slightly trickier for closed source deployments where you have little control over the environment. In my case, I can use Docker so I have a bit more flexibility.
To find a memory violation this week, I ended up using ASAN. It's nice to have bounds checks done via assert and resort to ASAN to catch the outliers.