Skip to content

Commit 81c6ae9

Browse files
haoxian2pcolberg
authored andcommitted
Fixed coverity issues in acl_mem.cpp: Constant expression result
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 &&.
1 parent 22226db commit 81c6ae9

File tree

1 file changed

+16
-12
lines changed

1 file changed

+16
-12
lines changed

src/acl_mem.cpp

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1521,6 +1521,10 @@ ACL_EXPORT CL_API_ENTRY cl_mem CL_API_CALL clCreateImageIntelFPGA(
15211521
BAIL(local_errcode_ret);
15221522
}
15231523

1524+
if (image_desc == NULL) {
1525+
BAIL_INFO(CL_INVALID_IMAGE_DESCRIPTOR, context, "image_desc is NULL");
1526+
}
1527+
15241528
local_errcode_ret = clGetSupportedImageFormats(
15251529
context, flags, image_desc->image_type, 0, NULL, &num_image_formats);
15261530
if (local_errcode_ret != CL_SUCCESS) {
@@ -2060,8 +2064,8 @@ CL_API_ENTRY cl_int CL_API_CALL clEnqueueReadImageIntelFPGA(
20602064
image->fields.image_objs.image_desc->image_width * src_element_size;
20612065
}
20622066

2063-
if (image->mem_object_type == CL_MEM_OBJECT_IMAGE1D &&
2064-
image->mem_object_type == CL_MEM_OBJECT_IMAGE1D_ARRAY &&
2067+
if (image->mem_object_type == CL_MEM_OBJECT_IMAGE1D ||
2068+
image->mem_object_type == CL_MEM_OBJECT_IMAGE1D_ARRAY ||
20652069
image->mem_object_type == CL_MEM_OBJECT_IMAGE1D_BUFFER) {
20662070
tmp_slice_pitch = tmp_row_pitch;
20672071
} else {
@@ -2161,8 +2165,8 @@ CL_API_ENTRY cl_int CL_API_CALL clEnqueueWriteImageIntelFPGA(
21612165
image->fields.image_objs.image_desc->image_width * dst_element_size;
21622166
}
21632167

2164-
if (image->mem_object_type == CL_MEM_OBJECT_IMAGE1D &&
2165-
image->mem_object_type == CL_MEM_OBJECT_IMAGE1D_ARRAY &&
2168+
if (image->mem_object_type == CL_MEM_OBJECT_IMAGE1D ||
2169+
image->mem_object_type == CL_MEM_OBJECT_IMAGE1D_ARRAY ||
21662170
image->mem_object_type == CL_MEM_OBJECT_IMAGE1D_BUFFER) {
21672171
tmp_slice_pitch = tmp_row_pitch;
21682172
} else {
@@ -2351,8 +2355,8 @@ CL_API_ENTRY cl_int CL_API_CALL clEnqueueFillImageIntelFPGA(
23512355
region[0] *
23522356
dst_element_size; // Width of each row of the memory that ptr points to.
23532357

2354-
if (image->mem_object_type == CL_MEM_OBJECT_IMAGE1D &&
2355-
image->mem_object_type == CL_MEM_OBJECT_IMAGE1D_ARRAY &&
2358+
if (image->mem_object_type == CL_MEM_OBJECT_IMAGE1D ||
2359+
image->mem_object_type == CL_MEM_OBJECT_IMAGE1D_ARRAY ||
23562360
image->mem_object_type == CL_MEM_OBJECT_IMAGE1D_BUFFER) {
23572361
tmp_slice_pitch = tmp_row_pitch;
23582362
} else {
@@ -2554,8 +2558,8 @@ CL_API_ENTRY cl_int CL_API_CALL clEnqueueCopyImageToBufferIntelFPGA(
25542558

25552559
tmp_row_pitch =
25562560
src_image->fields.image_objs.image_desc->image_width * src_element_size;
2557-
if (src_image->mem_object_type == CL_MEM_OBJECT_IMAGE1D &&
2558-
src_image->mem_object_type == CL_MEM_OBJECT_IMAGE1D_ARRAY &&
2561+
if (src_image->mem_object_type == CL_MEM_OBJECT_IMAGE1D ||
2562+
src_image->mem_object_type == CL_MEM_OBJECT_IMAGE1D_ARRAY ||
25592563
src_image->mem_object_type == CL_MEM_OBJECT_IMAGE1D_BUFFER) {
25602564
tmp_slice_pitch = tmp_row_pitch;
25612565
} else {
@@ -2649,8 +2653,8 @@ CL_API_ENTRY cl_int CL_API_CALL clEnqueueCopyBufferToImageIntelFPGA(
26492653

26502654
tmp_row_pitch =
26512655
dst_image->fields.image_objs.image_desc->image_width * dst_element_size;
2652-
if (dst_image->mem_object_type == CL_MEM_OBJECT_IMAGE1D &&
2653-
dst_image->mem_object_type == CL_MEM_OBJECT_IMAGE1D_ARRAY &&
2656+
if (dst_image->mem_object_type == CL_MEM_OBJECT_IMAGE1D ||
2657+
dst_image->mem_object_type == CL_MEM_OBJECT_IMAGE1D_ARRAY ||
26542658
dst_image->mem_object_type == CL_MEM_OBJECT_IMAGE1D_BUFFER) {
26552659
tmp_slice_pitch = tmp_row_pitch;
26562660
} else {
@@ -2954,9 +2958,9 @@ CL_API_ENTRY void *CL_API_CALL clEnqueueMapBufferIntelFPGA(
29542958
~(CL_MAP_READ | CL_MAP_WRITE | CL_MAP_WRITE_INVALIDATE_REGION)) {
29552959
BAIL_INFO(CL_INVALID_VALUE, context, "Invalid or unsupported flags");
29562960
}
2957-
if (((map_flags & CL_MAP_READ) &
2961+
if (((map_flags & CL_MAP_READ) &&
29582962
(map_flags & CL_MAP_WRITE_INVALIDATE_REGION)) ||
2959-
((map_flags & CL_MAP_WRITE) &
2963+
((map_flags & CL_MAP_WRITE) &&
29602964
(map_flags & CL_MAP_WRITE_INVALIDATE_REGION))) {
29612965
BAIL_INFO(
29622966
CL_INVALID_VALUE, context,

0 commit comments

Comments
 (0)