Skip to content

Commit

Permalink
Merge pull request #22 from exaexa/mk-ubsan
Browse files Browse the repository at this point in the history
fix clang ubsan issues
  • Loading branch information
exaexa authored Jun 11, 2023
2 parents a3cf77d + a62db7a commit 542077a
Show file tree
Hide file tree
Showing 10 changed files with 39 additions and 31 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: scattermore
Title: Scatterplots with More Points
Version: 1.1
Version: 1.2
Authors@R:
c(person(given = "Tereza",
family = "Kulichova",
Expand Down
5 changes: 3 additions & 2 deletions src/histogram_to_rgbwt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

#include "scatters.h"

#include <stddef.h>
#include <cstddef>

// colorize histogram with given color palette
void
Expand All @@ -36,7 +36,8 @@ histogram_to_rgbwt(const unsigned *dim,

for (size_t i = 0; i < size_out; ++i) {
size_t histogram_value = histogram[i] < 0 ? 0 : histogram[i];
if(histogram_value >= size_palette) histogram_value = size_palette - 1;
if (histogram_value >= size_palette)
histogram_value = size_palette - 1;

const float R = palette[4 * histogram_value + 0];
const float G = palette[4 * histogram_value + 1];
Expand Down
2 changes: 1 addition & 1 deletion src/kernel_histogram.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
#include "kernels.h"
#include "thread_blocks.h"

#include <stddef.h>
#include <cstddef>

using namespace std;

Expand Down
2 changes: 1 addition & 1 deletion src/kernel_rgbwt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
#include "thread_blocks.h"

#include <cmath>
#include <stddef.h>
#include <cstddef>
#include <thread>
#include <vector>

Expand Down
14 changes: 11 additions & 3 deletions src/macros.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* This file is part of scattermore.
*
* Copyright (C) 2022 Mirek Kratochvil <[email protected]>
* Copyright (C) 2022-2023 Mirek Kratochvil <[email protected]>
* 2022-2023 Tereza Kulichova <[email protected]>
*
* scattermore is free software: you can redistribute it and/or modify it under
Expand All @@ -21,7 +21,15 @@
#ifndef MACROS_H
#define MACROS_H

#define max(x, y) (((x) >= (y)) ? (x) : (y))
#define min(x, y) (((x) <= (y)) ? (x) : (y))
#include <cstddef>
#include <limits>

inline size_t
f2i(float x)
{
if (x < 0 || x > float(std::numeric_limits<size_t>::max()))
return std::numeric_limits<size_t>::max();
return size_t(x);
}

#endif
13 changes: 6 additions & 7 deletions src/scatter_histogram.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* This file is part of scattermore.
*
* Copyright (C) 2022 Mirek Kratochvil <[email protected]>
* Copyright (C) 2022-2023 Mirek Kratochvil <[email protected]>
* 2022-2023 Tereza Kulichova <[email protected]>
*
* scattermore is free software: you can redistribute it and/or modify it under
Expand All @@ -18,9 +18,10 @@
* scattermore. If not, see <https://www.gnu.org/licenses/>.
*/

#include "macros.h"
#include "scatters.h"

#include <stddef.h>
#include <cstddef>

void
scatter_histogram(const unsigned *pn,
Expand All @@ -42,11 +43,9 @@ scatter_histogram(const unsigned *pn,
const float y_end = ylim[0];
const float y_bin = (size_out_y - 1) / (y_end - y_begin);

size_t i;
for (i = 0; i < size_data; ++i) {
size_t x =
(xy[i] - x_begin) * x_bin; // get new point coordinates for histogram
size_t y = (xy[i + size_data] - y_begin) * y_bin;
for (size_t i = 0; i < size_data; ++i) {
size_t x = f2i((xy[i] - x_begin) * x_bin);
size_t y = f2i((xy[i + size_data] - y_begin) * y_bin);

if (x >= size_out_x || y >= size_out_y)
continue;
Expand Down
10 changes: 5 additions & 5 deletions src/scatter_indexed_rgbwt.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* This file is part of scattermore.
*
* Copyright (C) 2022 Mirek Kratochvil <[email protected]>
* Copyright (C) 2022-2023 Mirek Kratochvil <[email protected]>
* 2022-2023 Tereza Kulichova <[email protected]>
*
* scattermore is free software: you can redistribute it and/or modify it under
Expand All @@ -18,9 +18,10 @@
* scattermore. If not, see <https://www.gnu.org/licenses/>.
*/

#include "macros.h"
#include "scatters.h"

#include <stddef.h>
#include <cstddef>

// calculate RGBWT matrix with given color palette and mapping
void
Expand Down Expand Up @@ -54,9 +55,8 @@ scatter_indexed_rgbwt(const unsigned *dim,

size_t i;
for (i = 0; i < size_data; ++i) {
size_t x =
(xy[i] - x_begin) * x_bin; // get new point coordinates for result raster
size_t y = (xy[i + size_data] - y_begin) * y_bin;
size_t x = f2i((xy[i] - x_begin) * x_bin);
size_t y = f2i((xy[i + size_data] - y_begin) * y_bin);

if (x >= size_out_x || y >= size_out_y)
continue;
Expand Down
2 changes: 1 addition & 1 deletion src/scatter_lines_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
#ifndef SCATTERS_LINES_IMPL_H
#define SCATTERS_LINES_IMPL_H

#include <cstddef>
#include <cstdlib>
#include <stddef.h>

template<typename PF>
inline void
Expand Down
10 changes: 5 additions & 5 deletions src/scatter_multicolor_rgbwt.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* This file is part of scattermore.
*
* Copyright (C) 2022 Mirek Kratochvil <[email protected]>
* Copyright (C) 2022-2023 Mirek Kratochvil <[email protected]>
* 2022-2023 Tereza Kulichova <[email protected]>
*
* scattermore is free software: you can redistribute it and/or modify it under
Expand All @@ -18,9 +18,10 @@
* scattermore. If not, see <https://www.gnu.org/licenses/>.
*/

#include "macros.h"
#include "scatters.h"

#include <stddef.h>
#include <cstddef>

// calculate RGBWT matrix with given color for each point
void
Expand Down Expand Up @@ -53,9 +54,8 @@ scatter_multicolor_rgbwt(const unsigned *dim,

size_t i;
for (i = 0; i < size_data; ++i) {
size_t x =
(xy[i] - x_begin) * x_bin; // get new point coordinates for result raster
size_t y = (xy[i + size_data] - y_begin) * y_bin;
size_t x = f2i((xy[i] - x_begin) * x_bin);
size_t y = f2i((xy[i + size_data] - y_begin) * y_bin);

if (x >= size_out_x || y >= size_out_y)
continue;
Expand Down
10 changes: 5 additions & 5 deletions src/scatter_singlecolor_rgbwt.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* This file is part of scattermore.
*
* Copyright (C) 2022 Mirek Kratochvil <[email protected]>
* Copyright (C) 2022-2023 Mirek Kratochvil <[email protected]>
* 2022-2023 Tereza Kulichova <[email protected]>
*
* scattermore is free software: you can redistribute it and/or modify it under
Expand All @@ -18,9 +18,10 @@
* scattermore. If not, see <https://www.gnu.org/licenses/>.
*/

#include "macros.h"
#include "scatters.h"

#include <stddef.h>
#include <cstddef>

// calculate RGBWT matrix with one given color
void
Expand Down Expand Up @@ -57,9 +58,8 @@ scatter_singlecolor_rgbwt(const unsigned *dim,

size_t i;
for (i = 0; i < size_data; ++i) {
size_t x =
(xy[i] - x_begin) * x_bin; // get new point coordinates for result raster
size_t y = (xy[i + size_data] - y_begin) * y_bin;
size_t x = f2i((xy[i] - x_begin) * x_bin);
size_t y = f2i((xy[i + size_data] - y_begin) * y_bin);

if (x >= size_out_x || y >= size_out_y)
continue;
Expand Down

0 comments on commit 542077a

Please sign in to comment.