From 9f5eff971ed31437ea7a0d6f5ad59df12909aa1a Mon Sep 17 00:00:00 2001 From: Rashad Kanavath Date: Sat, 15 Feb 2020 16:34:00 +0100 Subject: [PATCH] MSVC: Fix pointer arithmetic MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Apply current clang-format formatting to commit Co-authored-by: Edouard Choinière <27212526+echoix@users.noreply.github.com> --- lib/raster3d/mask.c | 6 +-- raster/r.in.lidar/main.c | 2 +- raster/r.in.lidar/point_binning.c | 66 ++++++++++++++++--------------- 3 files changed, 39 insertions(+), 35 deletions(-) diff --git a/lib/raster3d/mask.c b/lib/raster3d/mask.c index b670058b5f1..d55f5536310 100644 --- a/lib/raster3d/mask.c +++ b/lib/raster3d/mask.c @@ -300,12 +300,12 @@ void Rast3d_mask_tile(RASTER3D_Map *map, int tileIndex, void *tile, int type) for (dy = y; dy < rows; dy++) { for (dx = x; dx < cols; dx++) { RASTER3D_MASKNUM(map, dx, dy, dz, tile, type); - tile = (char *)tile + length; + tile = (int *)tile + length; } - tile = (char *)tile + xLength; + tile = (int *)tile + xLength; } - tile = (char *)tile + yLength; + tile = (int *)tile + yLength; } } diff --git a/raster/r.in.lidar/main.c b/raster/r.in.lidar/main.c index 9ca8a905e71..4b045f38c2d 100644 --- a/raster/r.in.lidar/main.c +++ b/raster/r.in.lidar/main.c @@ -645,7 +645,7 @@ int main(int argc, char *argv[]) G_debug(2, "filling base raster array"); for (row = 0; row < rows; row++) { Rast_get_row(base_raster, - base_array + + (double *)base_array + ((size_t)row * cols * Rast_cell_size(base_raster_data_type)), row, base_raster_data_type); diff --git a/raster/r.in.lidar/point_binning.c b/raster/r.in.lidar/point_binning.c index 8a4b08cfd27..3d5640e1ee7 100644 --- a/raster/r.in.lidar/point_binning.c +++ b/raster/r.in.lidar/point_binning.c @@ -381,9 +381,9 @@ void write_variance(void *raster_row, void *n_array, void *sum_array, for (col = 0; col < cols; col++) { offset = ((size_t)row * cols + col) * Rast_cell_size(rtype); n_offset = ((size_t)row * cols + col) * Rast_cell_size(CELL_TYPE); - n = Rast_get_c_value(n_array + n_offset, CELL_TYPE); - sum = Rast_get_d_value(sum_array + offset, rtype); - sumsq = Rast_get_d_value(sumsq_array + offset, rtype); + n = Rast_get_c_value((CELL *)n_array + n_offset, CELL_TYPE); + sum = Rast_get_d_value((DCELL *)sum_array + offset, rtype); + sumsq = Rast_get_d_value((DCELL *)sumsq_array + offset, rtype); if (n == 0) Rast_set_null_value(ptr, 1, rtype); @@ -429,12 +429,13 @@ void write_median(struct BinIndex *bin_index, void *raster_row, for (col = 0; col < cols; col++) { n_offset = ((size_t)row * cols + col) * Rast_cell_size(CELL_TYPE); - if (Rast_is_null_value(index_array + n_offset, + if (Rast_is_null_value((CELL *)index_array + n_offset, CELL_TYPE)) /* no points in cell */ Rast_set_null_value(ptr, 1, rtype); else { /* one or more points in cell */ - head_id = Rast_get_c_value(index_array + n_offset, CELL_TYPE); + head_id = + Rast_get_c_value((CELL *)index_array + n_offset, CELL_TYPE); node_id = head_id; n = 0; @@ -489,11 +490,12 @@ void write_percentile(struct BinIndex *bin_index, void *raster_row, for (col = 0; col < cols; col++) { n_offset = ((size_t)row * cols + col) * Rast_cell_size(CELL_TYPE); - if (Rast_is_null_value(index_array + n_offset, + if (Rast_is_null_value((CELL *)index_array + n_offset, CELL_TYPE)) /* no points in cell */ Rast_set_null_value(ptr, 1, rtype); else { - head_id = Rast_get_c_value(index_array + n_offset, CELL_TYPE); + head_id = + Rast_get_c_value((CELL *)index_array + n_offset, CELL_TYPE); node_id = head_id; n = 0; @@ -544,11 +546,12 @@ void write_skewness(struct BinIndex *bin_index, void *raster_row, for (col = 0; col < cols; col++) { n_offset = ((size_t)row * cols + col) * Rast_cell_size(CELL_TYPE); - if (Rast_is_null_value(index_array + n_offset, + if (Rast_is_null_value((CELL *)index_array + n_offset, CELL_TYPE)) /* no points in cell */ Rast_set_null_value(ptr, 1, rtype); else { - head_id = Rast_get_c_value(index_array + n_offset, CELL_TYPE); + head_id = + Rast_get_c_value((CELL *)index_array + n_offset, CELL_TYPE); node_id = head_id; n = 0; /* count */ @@ -601,11 +604,12 @@ void write_trimmean(struct BinIndex *bin_index, void *raster_row, for (col = 0; col < cols; col++) { n_offset = ((size_t)row * cols + col) * Rast_cell_size(CELL_TYPE); - if (Rast_is_null_value(index_array + n_offset, + if (Rast_is_null_value((CELL *)index_array + n_offset, CELL_TYPE)) /* no points in cell */ Rast_set_null_value(ptr, 1, rtype); else { - head_id = Rast_get_c_value(index_array + n_offset, CELL_TYPE); + head_id = + Rast_get_c_value((CELL *)index_array + n_offset, CELL_TYPE); node_id = head_id; n = 0; @@ -666,28 +670,28 @@ void write_values(struct PointBinning *point_binning, switch (point_binning->method) { case METHOD_N: /* n is a straight copy */ Rast_raster_cpy(raster_row, - point_binning->n_array + + (CELL *)point_binning->n_array + ((size_t)row * cols * Rast_cell_size(CELL_TYPE)), cols, CELL_TYPE); break; case METHOD_MIN: Rast_raster_cpy(raster_row, - point_binning->min_array + + (CELL *)point_binning->min_array + ((size_t)row * cols * Rast_cell_size(rtype)), cols, rtype); break; case METHOD_MAX: Rast_raster_cpy(raster_row, - point_binning->max_array + + (CELL *)point_binning->max_array + ((size_t)row * cols * Rast_cell_size(rtype)), cols, rtype); break; case METHOD_SUM: Rast_raster_cpy(raster_row, - point_binning->sum_array + + (CELL *)point_binning->sum_array + ((size_t)row * cols * Rast_cell_size(rtype)), cols, rtype); break; @@ -696,10 +700,10 @@ void write_values(struct PointBinning *point_binning, ptr = raster_row; for (col = 0; col < cols; col++) { size_t offset = ((size_t)row * cols + col) * Rast_cell_size(rtype); - double min = - Rast_get_d_value(point_binning->min_array + offset, rtype); - double max = - Rast_get_d_value(point_binning->max_array + offset, rtype); + double min = Rast_get_d_value( + (DCELL *)point_binning->min_array + offset, rtype); + double max = Rast_get_d_value( + (DCELL *)point_binning->max_array + offset, rtype); Rast_set_d_value(ptr, max - min, rtype); ptr = G_incr_void_ptr(ptr, Rast_cell_size(rtype)); } @@ -711,10 +715,10 @@ void write_values(struct PointBinning *point_binning, size_t offset = ((size_t)row * cols + col) * Rast_cell_size(rtype); size_t n_offset = ((size_t)row * cols + col) * Rast_cell_size(CELL_TYPE); - int n = - Rast_get_c_value(point_binning->n_array + n_offset, CELL_TYPE); - double sum = - Rast_get_d_value(point_binning->sum_array + offset, rtype); + int n = Rast_get_c_value((CELL *)point_binning->n_array + n_offset, + CELL_TYPE); + double sum = Rast_get_d_value( + (DCELL *)point_binning->sum_array + offset, rtype); if (n == 0) Rast_set_null_value(ptr, 1, rtype); @@ -758,19 +762,19 @@ void write_values(struct PointBinning *point_binning, size_t offset = ((size_t)row * cols + col) * Rast_cell_size(rtype); size_t n_offset = ((size_t)row * cols + col) * Rast_cell_size(CELL_TYPE); - int n = - Rast_get_c_value(point_binning->n_array + n_offset, CELL_TYPE); + int n = Rast_get_c_value((CELL *)point_binning->n_array + n_offset, + CELL_TYPE); if (n == 0) continue; - double sum_x = - Rast_get_d_value(point_binning->x_array + offset, rtype); - double sum_y = - Rast_get_d_value(point_binning->y_array + offset, rtype); + double sum_x = Rast_get_d_value( + (DCELL *)point_binning->x_array + offset, rtype); + double sum_y = Rast_get_d_value( + (DCELL *)point_binning->y_array + offset, rtype); /* TODO: we do this also in mean writing */ - double sum_z = - Rast_get_d_value(point_binning->sum_array + offset, rtype); + double sum_z = Rast_get_d_value( + (DCELL *)point_binning->sum_array + offset, rtype); /* We are not writing any categories. They are not needed * and potentially it is too much trouble to do it and it is