aboutsummaryrefslogtreecommitdiffstats
path: root/libgamma_internal_translated_ramp_set_.c
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--libgamma_internal_translated_ramp_set_.c17
1 files changed, 12 insertions, 5 deletions
diff --git a/libgamma_internal_translated_ramp_set_.c b/libgamma_internal_translated_ramp_set_.c
index f249e54..359193c 100644
--- a/libgamma_internal_translated_ramp_set_.c
+++ b/libgamma_internal_translated_ramp_set_.c
@@ -30,17 +30,24 @@ libgamma_internal_translated_ramp_set_(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)))
return r;
/* 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. */