diff options
author | Mattias Andrée <maandree@kth.se> | 2021-03-08 00:21:02 +0100 |
---|---|---|
committer | Mattias Andrée <maandree@kth.se> | 2021-03-08 00:21:02 +0100 |
commit | b058098fdcc5d4ed9b81fdb17f64820c0360ad48 (patch) | |
tree | e39e5f547b900922775d466507c29b352f046a53 /libgamma_dummy_internal_crtc_restore_forced.c | |
parent | misc (diff) | |
download | libgamma-b058098fdcc5d4ed9b81fdb17f64820c0360ad48.tar.gz libgamma-b058098fdcc5d4ed9b81fdb17f64820c0360ad48.tar.bz2 libgamma-b058098fdcc5d4ed9b81fdb17f64820c0360ad48.tar.xz |
m + style fix + check memory allocation overflows
Signed-off-by: Mattias Andrée <maandree@kth.se>
Diffstat (limited to '')
-rw-r--r-- | libgamma_dummy_internal_crtc_restore_forced.c | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/libgamma_dummy_internal_crtc_restore_forced.c b/libgamma_dummy_internal_crtc_restore_forced.c index a3c460f..fd23e72 100644 --- a/libgamma_dummy_internal_crtc_restore_forced.c +++ b/libgamma_dummy_internal_crtc_restore_forced.c @@ -17,6 +17,9 @@ libgamma_dummy_internal_crtc_restore_forced(struct libgamma_dummy_crtc *restrict size_t rn = data->info. red_gamma_size; size_t gn = data->info.green_gamma_size; size_t bn = data->info. blue_gamma_size; + double rm = (double)(rn - 1); + double gm = (double)(gn - 1); + double bm = (double)(bn - 1); size_t i; if (!data->gamma_red) @@ -27,9 +30,9 @@ libgamma_dummy_internal_crtc_restore_forced(struct libgamma_dummy_crtc *restrict TYPE *red = data->gamma_red;\ TYPE *green = data->gamma_green;\ TYPE *blue = data->gamma_blue;\ - for (i = 0; i < rn; i++) red [i] = (TYPE)((double)(MAX) * ((double)i / (double)(rn - 1)));\ - for (i = 0; i < gn; i++) green[i] = (TYPE)((double)(MAX) * ((double)i / (double)(gn - 1)));\ - for (i = 0; i < bn; i++) blue [i] = (TYPE)((double)(MAX) * ((double)i / (double)(bn - 1)));\ + for (i = 0; i < rn; i++) red [i] = (TYPE)((double)(MAX) * ((double)i / rm));\ + for (i = 0; i < gn; i++) green[i] = (TYPE)((double)(MAX) * ((double)i / gm));\ + for (i = 0; i < bn; i++) blue [i] = (TYPE)((double)(MAX) * ((double)i / bm));\ } while (0) if (data->info.gamma_depth == 8) RESET_RAMPS(uint8_t, INT8_MAX); |