| Summary: | Python bindings confuse signed and unsigned integers | ||
|---|---|---|---|
| Product: | [Community] Virtualization Tools | Reporter: | Robie Basak <robie.basak> |
| Component: | libvirt-python | Assignee: | Libvirt Maintainers <libvirt-maint> |
| Status: | CLOSED CURRENTRELEASE | QA Contact: | |
| Severity: | unspecified | Docs Contact: | |
| Priority: | unspecified | ||
| Version: | unspecified | CC: | crobinso, eblake, rbalakri |
| Target Milestone: | --- | ||
| Target Release: | --- | ||
| Hardware: | Unspecified | ||
| OS: | Unspecified | ||
| Whiteboard: | |||
| Fixed In Version: | Doc Type: | Bug Fix | |
| Doc Text: | Story Points: | --- | |
| Clone Of: | Environment: | ||
| Last Closed: | 2016-04-11 17:08:31 UTC | Type: | Bug |
| Regression: | --- | Mount Type: | --- |
| Documentation: | --- | CRM: | |
| Verified Versions: | Category: | --- | |
| oVirt Team: | --- | RHEL 7.3 requirements from Atomic Host: | |
| Cloudforms Team: | --- | Target Upstream Version: | |
Present in commit 12dc729a711ef586ba632e90ff48667b4176f41f (In reply to Robie Basak from comment #0) > The definition of py_types in python/generator.py does not use the correct > PyArg_ParseTuple specifiers. It confuses signed and unsigned integers. > > The C standard defines an "int" as implementation-specific signedness. You > cannot rely on it being one particular way. On Intel, it's generally signed; > on ARM, generally unsigned. Wrong. 'char' has implementation-specific signedness, but 'int' is always signed. (See C99 6.2.5 paragraph 4) > > There exist separate PyArg_ParseTuple specifiers for unsigned integers ("i", > "k" and "K" for unsigned int, unsigned long and unsigned long long > respectively). When creating bindings for unsigned integer types, > python/generator.py should use these specifiers to prevent potential > signed/unsigned conversion errors on ARM. It looks like differentiation is > already present, but the specifiers are just wrong for the unsigned cases. Using the correct specifier is still a good idea, for better overflow checking. > Wrong. 'char' has implementation-specific signedness, but 'int' is always signed. (See C99 6.2.5 paragraph 4)
Ah. Thank you for the correction.
I believe this was fixed, there's a series of commits like:
commit 1bba3ca4e250c20b63515085f7be4b2c8ec5e237
Author: Pavel Hrdina <phrdina>
Date: Tue Feb 23 13:46:45 2016 +0100
libvirt-override: fix PyArg_ParseTuple for size_t
|
The definition of py_types in python/generator.py does not use the correct PyArg_ParseTuple specifiers. It confuses signed and unsigned integers. The C standard defines an "int" as implementation-specific signedness. You cannot rely on it being one particular way. On Intel, it's generally signed; on ARM, generally unsigned. There exist separate PyArg_ParseTuple specifiers for unsigned integers ("i", "k" and "K" for unsigned int, unsigned long and unsigned long long respectively). When creating bindings for unsigned integer types, python/generator.py should use these specifiers to prevent potential signed/unsigned conversion errors on ARM. It looks like differentiation is already present, but the specifiers are just wrong for the unsigned cases. I don't have a specific failure case; I noticed this when addressing a separate issue and thought I should flag this.