Changed cmake version test to allow for cmake 2.8.11.x
[openjpeg.git] / src / lib / openjp2 / sparse_array.c
index 40459bdb922808b2a0b53ac83f3d3448c2111723..73192924eddcef37e24e6138faef09f4b62bd73a 100644 (file)
@@ -56,7 +56,8 @@ opj_sparse_array_int32_t* opj_sparse_array_int32_create(OPJ_UINT32 width,
         return NULL;
     }
 
-    sa = opj_calloc(1, sizeof(opj_sparse_array_int32_t));
+    sa = (opj_sparse_array_int32_t*) opj_calloc(1,
+            sizeof(opj_sparse_array_int32_t));
     sa->width = width;
     sa->height = height;
     sa->block_width = block_width;
@@ -67,8 +68,8 @@ opj_sparse_array_int32_t* opj_sparse_array_int32_create(OPJ_UINT32 width,
         opj_free(sa);
         return NULL;
     }
-    sa->data_blocks = opj_calloc(sizeof(OPJ_INT32*),
-                                 sa->block_count_hor * sa->block_count_ver);
+    sa->data_blocks = (OPJ_INT32**) opj_calloc(sizeof(OPJ_INT32*),
+                      sa->block_count_hor * sa->block_count_ver);
     if (sa->data_blocks == NULL) {
         opj_free(sa);
         return NULL;
@@ -142,14 +143,14 @@ static OPJ_BOOL opj_sparse_array_int32_read_or_write(
             if (is_read_op) {
                 if (src_block == NULL) {
                     if (buf_col_stride == 1) {
-                        OPJ_INT32* dest_ptr = buf + (y - y0) * (size_t)buf_line_stride +
+                        OPJ_INT32* dest_ptr = buf + (y - y0) * (OPJ_SIZE_T)buf_line_stride +
                                               (x - x0) * buf_col_stride;
                         for (j = 0; j < y_incr; j++) {
                             memset(dest_ptr, 0, sizeof(OPJ_INT32) * x_incr);
                             dest_ptr += buf_line_stride;
                         }
                     } else {
-                        OPJ_INT32* dest_ptr = buf + (y - y0) * (size_t)buf_line_stride +
+                        OPJ_INT32* dest_ptr = buf + (y - y0) * (OPJ_SIZE_T)buf_line_stride +
                                               (x - x0) * buf_col_stride;
                         for (j = 0; j < y_incr; j++) {
                             OPJ_UINT32 k;
@@ -161,13 +162,15 @@ static OPJ_BOOL opj_sparse_array_int32_read_or_write(
                     }
                 } else {
                     const OPJ_INT32* OPJ_RESTRICT src_ptr = src_block + block_y_offset *
-                                                            (size_t)block_width + block_x_offset;
+                                                            (OPJ_SIZE_T)block_width + block_x_offset;
                     if (buf_col_stride == 1) {
-                        OPJ_INT32* OPJ_RESTRICT dest_ptr = buf + (y - y0) * (size_t)buf_line_stride +
+                        OPJ_INT32* OPJ_RESTRICT dest_ptr = buf + (y - y0) * (OPJ_SIZE_T)buf_line_stride
+                                                           +
                                                            (x - x0) * buf_col_stride;
                         if (x_incr == 4) {
-                            // Same code as general branch, but the compiler
-                            // can have an efficient memcpy()
+                            /* Same code as general branch, but the compiler */
+                            /* can have an efficient memcpy() */
+                            (void)(x_incr); /* trick to silent cppcheck duplicateBranch warning */
                             for (j = 0; j < y_incr; j++) {
                                 memcpy(dest_ptr, src_ptr, sizeof(OPJ_INT32) * x_incr);
                                 dest_ptr += buf_line_stride;
@@ -181,7 +184,8 @@ static OPJ_BOOL opj_sparse_array_int32_read_or_write(
                             }
                         }
                     } else {
-                        OPJ_INT32* OPJ_RESTRICT dest_ptr = buf + (y - y0) * (size_t)buf_line_stride +
+                        OPJ_INT32* OPJ_RESTRICT dest_ptr = buf + (y - y0) * (OPJ_SIZE_T)buf_line_stride
+                                                           +
                                                            (x - x0) * buf_col_stride;
                         if (x_incr == 1) {
                             for (j = 0; j < y_incr; j++) {
@@ -230,8 +234,8 @@ static OPJ_BOOL opj_sparse_array_int32_read_or_write(
                 }
             } else {
                 if (src_block == NULL) {
-                    src_block = opj_calloc(1,
-                                           sa->block_width * sa->block_height * sizeof(OPJ_INT32));
+                    src_block = (OPJ_INT32*) opj_calloc(1,
+                                                        sa->block_width * sa->block_height * sizeof(OPJ_INT32));
                     if (src_block == NULL) {
                         return OPJ_FALSE;
                     }
@@ -240,12 +244,13 @@ static OPJ_BOOL opj_sparse_array_int32_read_or_write(
 
                 if (buf_col_stride == 1) {
                     OPJ_INT32* OPJ_RESTRICT dest_ptr = src_block + block_y_offset *
-                                                       (size_t)block_width + block_x_offset;
+                                                       (OPJ_SIZE_T)block_width + block_x_offset;
                     const OPJ_INT32* OPJ_RESTRICT src_ptr = buf + (y - y0) *
-                                                            (size_t)buf_line_stride + (x - x0) * buf_col_stride;
+                                                            (OPJ_SIZE_T)buf_line_stride + (x - x0) * buf_col_stride;
                     if (x_incr == 4) {
-                        // Same code as general branch, but the compiler
-                        // can have an efficient memcpy()
+                        /* Same code as general branch, but the compiler */
+                        /* can have an efficient memcpy() */
+                        (void)(x_incr); /* trick to silent cppcheck duplicateBranch warning */
                         for (j = 0; j < y_incr; j++) {
                             memcpy(dest_ptr, src_ptr, sizeof(OPJ_INT32) * x_incr);
                             dest_ptr += block_width;
@@ -260,9 +265,9 @@ static OPJ_BOOL opj_sparse_array_int32_read_or_write(
                     }
                 } else {
                     OPJ_INT32* OPJ_RESTRICT dest_ptr = src_block + block_y_offset *
-                                                       (size_t)block_width + block_x_offset;
+                                                       (OPJ_SIZE_T)block_width + block_x_offset;
                     const OPJ_INT32* OPJ_RESTRICT src_ptr = buf + (y - y0) *
-                                                            (size_t)buf_line_stride + (x - x0) * buf_col_stride;
+                                                            (OPJ_SIZE_T)buf_line_stride + (x - x0) * buf_col_stride;
                     if (x_incr == 1) {
                         for (j = 0; j < y_incr; j++) {
                             *dest_ptr = *src_ptr;