diff options
author | Mattias Andrée <maandree@kth.se> | 2021-03-08 00:21:02 +0100 |
---|---|---|
committer | Mattias Andrée <maandree@kth.se> | 2021-03-08 00:21:02 +0100 |
commit | b058098fdcc5d4ed9b81fdb17f64820c0360ad48 (patch) | |
tree | e39e5f547b900922775d466507c29b352f046a53 /libgamma_gamma_ramps8_initialise.c | |
parent | misc (diff) | |
download | libgamma-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 '')
-rw-r--r-- | libgamma_gamma_ramps8_initialise.c | 8 |
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]; |