From b058098fdcc5d4ed9b81fdb17f64820c0360ad48 Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Mon, 8 Mar 2021 00:21:02 +0100 Subject: m + style fix + check memory allocation overflows MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Andrée --- libgamma_gamma_rampsf_initialise.c | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'libgamma_gamma_rampsf_initialise.c') diff --git a/libgamma_gamma_rampsf_initialise.c b/libgamma_gamma_rampsf_initialise.c index 0937bc7..5cd9290 100644 --- a/libgamma_gamma_rampsf_initialise.c +++ b/libgamma_gamma_rampsf_initialise.c @@ -16,6 +16,14 @@ int libgamma_gamma_rampsf_initialise(struct libgamma_gamma_rampsf *restrict this) { size_t n = this->red_size + this->green_size + this->blue_size; + if (!n) { + this->red = this->green = this->blue = NULL; + return 0; + } + if (n > SIZE_MAX / sizeof(*this->red)) { + errno = ENOMEM; + return -1; + } this->red = malloc(n * sizeof(*this->red)); this->green = &this-> red[this-> red_size]; this->blue = &this->green[this->green_size]; -- cgit v1.2.3-70-g09d2