aboutsummaryrefslogtreecommitdiffstats
path: root/libgamma_gamma_ramps8_initialise.c
diff options
context:
space:
mode:
Diffstat (limited to 'libgamma_gamma_ramps8_initialise.c')
-rw-r--r--libgamma_gamma_ramps8_initialise.c8
1 files changed, 8 insertions, 0 deletions
diff --git a/libgamma_gamma_ramps8_initialise.c b/libgamma_gamma_ramps8_initialise.c
index 04bf465..6434707 100644
--- a/libgamma_gamma_ramps8_initialise.c
+++ b/libgamma_gamma_ramps8_initialise.c
@@ -16,6 +16,14 @@ int
libgamma_gamma_ramps8_initialise(struct libgamma_gamma_ramps8 *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];