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_internal_translated_ramp_get_.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_internal_translated_ramp_get_.c | 17 |
1 files changed, 12 insertions, 5 deletions
diff --git a/libgamma_internal_translated_ramp_get_.c b/libgamma_internal_translated_ramp_get_.c index 852f6c9..c5f563e 100644 --- a/libgamma_internal_translated_ramp_get_.c +++ b/libgamma_internal_translated_ramp_get_.c @@ -30,7 +30,7 @@ libgamma_internal_translated_ramp_get_(struct libgamma_crtc_state *restrict this size_t n; int r; union gamma_ramps_any ramps_sys; - uint64_t *restrict ramps_full; + uint64_t *restrict ramps_full = NULL; /* Allocate ramps with proper data type */ if ((r = libgamma_internal_allocated_any_ramp(&ramps_sys, ramps, depth_system, &n))) @@ -43,10 +43,17 @@ libgamma_internal_translated_ramp_get_(struct libgamma_crtc_state *restrict this } /* Allocate intermediary ramps */ - ramps_full = malloc(n * sizeof(*ramps_full)); - if (!ramps_full) { - free(ramps_sys.ANY.red); - return LIBGAMMA_ERRNO_SET; + if (n) { + if (n > SIZE_MAX / sizeof(*ramps_full)) { + errno = ENOMEM; + free(ramps_sys.ANY.red); + return LIBGAMMA_ERRNO_SET; + } + ramps_full = malloc(n * sizeof(*ramps_full)); + if (!ramps_full) { + free(ramps_sys.ANY.red); + return LIBGAMMA_ERRNO_SET; + } } /* Translate ramps to 64-bit integers */ |