Ensure usage of __attribute__(cleanup) never frees un-initialized memory

Use macros that take an initializer parameter to, thereby ensuring the
variable to be cleaned up is always initialized.
This commit is contained in:
Kovid Goyal
2023-08-07 11:52:52 +05:30
parent 9af4d5e0fc
commit 6c7a8f8fa9
19 changed files with 75 additions and 77 deletions

View File

@@ -192,18 +192,18 @@ text_composition_strategy(PyObject *val, Options *opts) {
else if (PyUnicode_CompareWithASCIIString(val, "legacy") == 0) {
opts->text_old_gamma = true;
} else {
DECREF_AFTER_FUNCTION PyObject *parts = PyUnicode_Split(val, NULL, 2);
RAII_PyObject(parts, PyUnicode_Split(val, NULL, 2));
int size = PyList_GET_SIZE(parts);
if (size < 1 || 2 < size) { PyErr_SetString(PyExc_ValueError, "text_rendering_strategy must be of the form number:[number]"); return; }
if (size > 0) {
DECREF_AFTER_FUNCTION PyObject *ga = PyFloat_FromString(PyList_GET_ITEM(parts, 0));
RAII_PyObject(ga, PyFloat_FromString(PyList_GET_ITEM(parts, 0)));
if (PyErr_Occurred()) return;
opts->text_gamma_adjustment = MAX(0.01f, PyFloat_AsFloat(ga));
}
if (size > 1) {
DECREF_AFTER_FUNCTION PyObject *contrast = PyFloat_FromString(PyList_GET_ITEM(parts, 1));
RAII_PyObject(contrast, PyFloat_FromString(PyList_GET_ITEM(parts, 1)));
if (PyErr_Occurred()) return;
opts->text_contrast = MAX(0.0f, PyFloat_AsFloat(contrast));
opts->text_contrast = MIN(100.0f, opts->text_contrast);