diff options
author | Simon Ser <contact@emersion.fr> | 2022-09-18 15:20:39 +0200 |
---|---|---|
committer | Simon Ser <contact@emersion.fr> | 2022-09-18 15:20:39 +0200 |
commit | 2ad25b1460400e66ea26bd6489b04072be7d9dbb (patch) | |
tree | 1d77e43ab237469251fa2ba759f682378db3b0e1 | |
parent | ebd4c83cd6699c606e57f141187984f0818a2973 (diff) |
output: fix wlr_output_set_gamma() with zero size
This is documented to reset the gamma LUT, but we don't handle this
properly.
While at it, make sure we leave wlr_output.pending in a good state
on allocation failure.
-rw-r--r-- | types/output/output.c | 22 |
1 files changed, 13 insertions, 9 deletions
diff --git a/types/output/output.c b/types/output/output.c index a4cb8980..cd0cc934 100644 --- a/types/output/output.c +++ b/types/output/output.c @@ -925,18 +925,22 @@ void wlr_output_send_present(struct wlr_output *output, void wlr_output_set_gamma(struct wlr_output *output, size_t size, const uint16_t *r, const uint16_t *g, const uint16_t *b) { + uint16_t *gamma_lut = NULL; + if (size > 0) { + gamma_lut = malloc(3 * size * sizeof(uint16_t)); + if (gamma_lut == NULL) { + wlr_log_errno(WLR_ERROR, "Allocation failed"); + return; + } + memcpy(gamma_lut, r, size * sizeof(uint16_t)); + memcpy(gamma_lut + size, g, size * sizeof(uint16_t)); + memcpy(gamma_lut + 2 * size, b, size * sizeof(uint16_t)); + } + output_state_clear_gamma_lut(&output->pending); output->pending.gamma_lut_size = size; - output->pending.gamma_lut = malloc(3 * size * sizeof(uint16_t)); - if (output->pending.gamma_lut == NULL) { - wlr_log_errno(WLR_ERROR, "Allocation failed"); - return; - } - memcpy(output->pending.gamma_lut, r, size * sizeof(uint16_t)); - memcpy(output->pending.gamma_lut + size, g, size * sizeof(uint16_t)); - memcpy(output->pending.gamma_lut + 2 * size, b, size * sizeof(uint16_t)); - + output->pending.gamma_lut = gamma_lut; output->pending.committed |= WLR_OUTPUT_STATE_GAMMA_LUT; } |