[issue10951] gcc 4.6 warnings

Terry J. Reedy report at bugs.python.org
Thu Jan 20 00:55:10 CET 2011


Terry J. Reedy <tjreedy at udel.edu> added the comment:

I took a look at an example of each type.

Sign-compare, Parser/node.c, 94
        if (required_capacity > PY_SIZE_MAX / sizeof(node))

I presume PY_SIZE_MAX and sizeof(node) are both unsigned.
So is, conceptually, required_capacity, but it is defined as an int because it is defined with XXXROUNDUP() and hence fancy_roundup(), which returns -1 if n1->n_nchildren is so large that the smallest power of 2 larger is too big for an int.

The comparison is 'OK' in context in that it is preceded by and guarded by
    if (current_capacity < 0 || required_capacity < 0)
        return E_OVERFLOW;

If I had written this, I might have thought about replacing all the comparisons with one check of n1->n_nchildren against some reasonable limit calculated from PY_SIZE_MAX / sizeof(node), and making both capacities unsigned.

---
Unused, Parser/parsetok.c, 130: local vars handling_with and handling_import are both set to 0 both here and again on line 157 and not seen elsewhere in the file. I presume both could just be deleted both places. 

---
Empty body, pgen, multiple places: those I checked are appearances of the REQN() macro. The REQ() macro did not generate a warning. 

#ifdef Py_DEBUG
#define REQN(i, count) \
    if (i < count) { \
        fprintf(stderr, REQNFMT, count); \
        Py_FatalError("REQN"); \
    } else
#else
#define REQN(i, count)  /* empty */
#endif

Since all invocations of REQN look like "     REQN(i, 1);", I presume the 'else' is there to swallow up the ';' which is added to make macro calls look like statements with a function call. I guess this is a style issue. As I remember, the suggestion to simply add '{}' to the macro would make syntax errors.

---
Uninitialized, Objects/setobject.c, 2445, in test_c_api: 
    while (_PySet_NextEntry((PyObject *)dup, &i, &x, &hash)) {
        s = _PyUnicode_AsString(x);

I presume x is set by _PySet... . (If i and hash are also, they are not used). So 'may be' but not actually.

---
Conclusion: the 'fix' is some real cleanup, some warning suppression.

----------
nosy: +terry.reedy

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue10951>
_______________________________________


More information about the Python-bugs-list mailing list