~pythonregexp2.7/python/issue2636-09-01+10

« back to all changes in this revision

Viewing changes to Objects/listobject.c

  • Committer: Jeffrey C. "The TimeHorse" Jacobs
  • Date: 2008-09-22 21:39:45 UTC
  • mfrom: (39055.1.33 Regexp-2.7)
  • Revision ID: darklord@timehorse.com-20080922213945-23717m5eiqpamcyn
Merged in changes from the Single-Loop Engine branch.

Show diffs side-by-side

added added

removed removed

Lines of Context:
45
45
         * system realloc().
46
46
         * The growth pattern is:  0, 4, 8, 16, 25, 35, 46, 58, 72, 88, ...
47
47
         */
48
 
        new_allocated = (newsize >> 3) + (newsize < 9 ? 3 : 6) + newsize;
 
48
        new_allocated = (newsize >> 3) + (newsize < 9 ? 3 : 6);
 
49
 
 
50
        /* check for integer overflow */
 
51
        if (new_allocated > PY_SIZE_MAX - newsize) {
 
52
                PyErr_NoMemory();
 
53
                return -1;
 
54
        } else {
 
55
                new_allocated += newsize;
 
56
        }
 
57
 
49
58
        if (newsize == 0)
50
59
                new_allocated = 0;
51
60
        items = self->ob_item;
118
127
                return NULL;
119
128
        }
120
129
        nbytes = size * sizeof(PyObject *);
121
 
        /* Check for overflow */
122
 
        if (nbytes / sizeof(PyObject *) != (size_t)size)
 
130
        /* Check for overflow without an actual overflow,
 
131
         *  which can cause compiler to optimise out */
 
132
        if (size > PY_SIZE_MAX / sizeof(PyObject *))
123
133
                return PyErr_NoMemory();
124
134
        if (numfree) {
125
135
                numfree--;
1407
1417
         * we don't care what's in the block.
1408
1418
         */
1409
1419
        merge_freemem(ms);
 
1420
        if (need > PY_SSIZE_T_MAX / sizeof(PyObject*)) {
 
1421
                PyErr_NoMemory();
 
1422
                return -1;
 
1423
        }
1410
1424
        ms->a = (PyObject **)PyMem_Malloc(need * sizeof(PyObject*));
1411
1425
        if (ms->a) {
1412
1426
                ms->alloced = need;
2589
2603
                                step = -step;
2590
2604
                        }
2591
2605
 
 
2606
                        assert(slicelength <= PY_SIZE_MAX / sizeof(PyObject*));
 
2607
 
2592
2608
                        garbage = (PyObject**)
2593
2609
                                PyMem_MALLOC(slicelength*sizeof(PyObject*));
2594
2610
                        if (!garbage) {
2726
2742
        0,                                      /* tp_as_number */
2727
2743
        &list_as_sequence,                      /* tp_as_sequence */
2728
2744
        &list_as_mapping,                       /* tp_as_mapping */
2729
 
        0,                                      /* tp_hash */
 
2745
        (hashfunc)PyObject_HashNotImplemented,  /* tp_hash */
2730
2746
        0,                                      /* tp_call */
2731
2747
        0,                                      /* tp_str */
2732
2748
        PyObject_GenericGetAttr,                /* tp_getattro */