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