aboutsummaryrefslogtreecommitdiffstats
path: root/libgamma_internal_translated_ramp_get_.c
diff options
context:
space:
mode:
authorMattias Andrée <maandree@kth.se>2021-03-08 00:21:02 +0100
committerMattias Andrée <maandree@kth.se>2021-03-08 00:21:02 +0100
commitb058098fdcc5d4ed9b81fdb17f64820c0360ad48 (patch)
treee39e5f547b900922775d466507c29b352f046a53 /libgamma_internal_translated_ramp_get_.c
parentmisc (diff)
downloadlibgamma-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_.c17
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 */