-
Notifications
You must be signed in to change notification settings - Fork 71
Fixed coverity issues in src/acl_mem.cpp #219
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
f723b2f
to
f171b99
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @haoxian2! Two minor style tweaks and this is good to go 🙂
3046edd
to
207bd89
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @haoxian2! You can use the type bool
for the auxiliary vector.
207bd89
to
5eea2ac
Compare
5eea2ac
to
72fd012
Compare
68cbc2a
to
6708bc5
Compare
Changed a lot of the && to || because CL_MEM_OBJECT_IMAGE1D, CL_MEM_OBJECT_IMAGE1D_ARRAY, and CL_MEM_OBJECT_IMAGE1D_BUFFER are all defined as strictly different values respectively 0x10F4, 0x10F5, and 0x10F6. Therefore that section of the statement would never be accessed. Logically, if the object is a 1D image, no matter which one it is, the slice pitch will not have a height and would just be equal to the row pitch, therefore I think logical OR makes sense. (line 2957) ((map_flags & CL_MAP_READ) & (map_flags & CL_MAP_WRITE_INVALIDATE_REGION)), both will only return the common bit between map_flags and the 2nd value, CL_MAP_READ being 1 and CL_MAP_WRITE_INVALIDATE_REGION being 4, but there are no common bits between 1 and 4, therefore this statement will always be false. From the comments, I believe that this block takes care of the state where map_flags contains both one of CL_MAP_READ or CL_MAP_WRITE and CL_MAP_WRITE_INVALIDATE_REGION. and therefore should replace the middle & to &&.
1D image does not have initialization of height and depth members. Some functions check for that before they check for height and depth. Added an image with 0 height and 0 depth to make sure that these functions don't mistakenly use the height and depth in image_desc.
6708bc5
to
3477aef
Compare
3477aef
to
dbda512
Compare
(Line 2036) Previously, if image is NULL, src_element_size is set to 0. However, there are a bunch of 'image' dereference after this check, which does not make sense since this if statement makes it seem like this function can handle a NULL image. Therefore, I replaced it with return CL_INVALID_MEM_OBJECT like some of the other functions. (Line 6829) Except these two lines, all the other line querying about mem->block_allocation are contained in the block with a null check for mem->block_allocation. Moving the two lines with the other lines.
(Line 4172) Missing free for a malloc object before returning, same with (line 4183) Solution: Turning `needs_release_on_fail` into vector since it is only present in the scope of this function
dbda512
to
491857d
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @haoxian2!
Fixed coverity issues in acl_mem.cpp: Constant expression result
This issues happen when a condition can only have one outcome.
image_height
as per specifications, it should be an||
operator instead of&&
operator.((map_flags & CL_MAP_READ) & (map_flags & CL_MAP_WRITE_INVALIDATE_REGION))
, both will only return the common bit betweenmap_flags
and the 2nd value,CL_MAP_READ
being 1 andCL_MAP_WRITE_INVALIDATE_REGION
being 4, but there are no common bits between 1 and 4, therefore this statement will always be false. From the comments, I believe that this block takes care of the state wheremap_flags
contains both one ofCL_MAP_READ
orCL_MAP_WRITE
andCL_MAP_WRITE_INVALIDATE_REGION
. and therefore should replace the middle&&
to&
.Added new checks in acl_mem_test.cpp
Checking if
enqueue
functions can handle 1D image. These functions access theimage_desc.height
variable, making sure it is initialized by default.Fixed coverity issue in acl_mem.cpp: Dereference after null check
image
isNULL
,src_element_size
is set to0
. However, there are a bunch of 'image' dereference after this check, which does not make sense since thisif
statement makes it seem like this function can handle aNULL image
. Therefore, I replaced it withreturn CL_INVALID_MEM_OBJECT
like some of the other functions. Rewrote some blocks of code that are similar to this one to conform to better verticality of code.mem->block_allocation
are contained in the block with a null check formem->block_allocation
. Moving the two lines with the other lines.Fixed coverity issue in acl_mem.cpp: Memory leak
(Line 4172) Missing
free
for a malloc object before returning, same with (line 4183)Turned
needs_release_on_fail
into a vector to avoidmalloc
and use built in destructor when it goes out of scope.