aboutsummaryrefslogtreecommitdiffstats
path: root/libgamma_gamma_rampsd_initialise.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_gamma_rampsd_initialise.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 '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];