This is an automated email from the git hooks/post-receive script.
git pushed a commit to reference refs/pull/21/head
in repository legacy-imlib2.
View the commit online.
commit c928e7ebee7ae5d61db41cc8f29685580e2bac99
Author: NRK <n...@disroot.org>
AuthorDate: Sun Dec 31 09:32:13 2023 +0000
PNG saver: avoid UB on misc.data
if the value of a local variable changes between the setjmp call and the
longjmp call then it has to be marked volatile otherwise it's undefined
behavior. [0]
but making it `volatile` would slow down the saver code since it will
force byte by byte write and the pointer to be reloaded for each write.
instead just make `misc` static, since the setjmp UB condition only
applies to automatic storage variables, this also avoids the issue but
without slowing down the writing.
[0]: https://www.man7.org/linux/man-pages/man3/setjmp.3.html#CAVEATS
---
src/modules/loaders/loader_png.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/src/modules/loaders/loader_png.c b/src/modules/loaders/loader_png.c
index 2e5573a..420d494 100644
--- a/src/modules/loaders/loader_png.c
+++ b/src/modules/loaders/loader_png.c
@@ -606,7 +606,6 @@ _save(ImlibImage * im)
FILE *f = im->fi->fp;
png_structp png_ptr;
png_infop info_ptr;
- misc_data_t misc;
const uint32_t *imdata;
int x, y, j, interlace;
png_bytep row_ptr;
@@ -615,6 +614,9 @@ _save(ImlibImage * im)
int quality = 75, compression = 3;
int pass, n_passes = 1;
int has_alpha;
+ // static storage to avoid UB with setjmp.
+ // see CAVEATS section on the setjmp linux man-page.
+ static misc_data_t misc;
rc = LOAD_FAIL;
info_ptr = NULL;
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.