[New-bugs-announce] [issue39605] Fix some casts to not cast away const

Andy Lester report at bugs.python.org
Mon Feb 10 23:45:37 EST 2020

New submission from Andy Lester <andy at petdance.com>:

gcc -Wcast-qual turns up a number of instances of casting away constness of pointers.  Some of these can be safely modified, by either:

* Adding the const to the type cast, as in:

-    return _PyUnicode_FromUCS1((unsigned char*)s, size);
+    return _PyUnicode_FromUCS1((const unsigned char*)s, size);

* Removing the cast entirely, because it's not necessary (but probably was at one time), as in:

-    PyDTrace_FUNCTION_ENTRY((char *)filename, (char *)funcname, lineno);
+    PyDTrace_FUNCTION_ENTRY(filename, funcname, lineno);

These changes will not change code, but they will make it much easier to check for errors in consts.

components: Interpreter Core
messages: 361780
nosy: petdance
priority: normal
severity: normal
status: open
title: Fix some casts to not cast away const
type: enhancement

Python tracker <report at bugs.python.org>

More information about the New-bugs-announce mailing list