mirror of
https://github.com/python-pillow/Pillow.git
synced 2024-12-26 18:06:18 +03:00
Replaced PyErr_NoMemory with ImagingError_MemoryError
This commit is contained in:
parent
c1707d5d55
commit
75542fea6d
|
@ -377,7 +377,7 @@ getlist(PyObject* arg, Py_ssize_t* length, const char* wrong_length, int type)
|
||||||
calloc checks for overflow */
|
calloc checks for overflow */
|
||||||
list = calloc(n, type & 0xff);
|
list = calloc(n, type & 0xff);
|
||||||
if ( ! list) {
|
if ( ! list) {
|
||||||
return PyErr_NoMemory();
|
return ImagingError_MemoryError();
|
||||||
}
|
}
|
||||||
|
|
||||||
seq = PySequence_Fast(arg, must_be_sequence);
|
seq = PySequence_Fast(arg, must_be_sequence);
|
||||||
|
@ -789,7 +789,7 @@ _prepare_lut_table(PyObject* table, Py_ssize_t table_size)
|
||||||
if (free_table_data) {
|
if (free_table_data) {
|
||||||
free(table_data);
|
free(table_data);
|
||||||
}
|
}
|
||||||
return (INT16*) PyErr_NoMemory();
|
return (INT16*) ImagingError_MemoryError();
|
||||||
}
|
}
|
||||||
|
|
||||||
for (i = 0; i < table_size; i++) {
|
for (i = 0; i < table_size; i++) {
|
||||||
|
@ -2234,7 +2234,7 @@ _getprojection(ImagingObject* self, PyObject* args)
|
||||||
if (xprofile == NULL || yprofile == NULL) {
|
if (xprofile == NULL || yprofile == NULL) {
|
||||||
free(xprofile);
|
free(xprofile);
|
||||||
free(yprofile);
|
free(yprofile);
|
||||||
return PyErr_NoMemory();
|
return ImagingError_MemoryError();
|
||||||
}
|
}
|
||||||
|
|
||||||
ImagingGetProjection(self->image, (unsigned char *)xprofile, (unsigned char *)yprofile);
|
ImagingGetProjection(self->image, (unsigned char *)xprofile, (unsigned char *)yprofile);
|
||||||
|
|
|
@ -80,7 +80,7 @@ PyImaging_DecoderNew(int contextsize)
|
||||||
context = (void*) calloc(1, contextsize);
|
context = (void*) calloc(1, contextsize);
|
||||||
if (!context) {
|
if (!context) {
|
||||||
Py_DECREF(decoder);
|
Py_DECREF(decoder);
|
||||||
(void) PyErr_NoMemory();
|
(void) ImagingError_MemoryError();
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -204,14 +204,14 @@ _setimage(ImagingDecoderObject* decoder, PyObject* args)
|
||||||
if (state->bits > 0) {
|
if (state->bits > 0) {
|
||||||
if (!state->bytes) {
|
if (!state->bytes) {
|
||||||
if (state->xsize > ((INT_MAX / state->bits)-7)){
|
if (state->xsize > ((INT_MAX / state->bits)-7)){
|
||||||
return PyErr_NoMemory();
|
return ImagingError_MemoryError();
|
||||||
}
|
}
|
||||||
state->bytes = (state->bits * state->xsize+7)/8;
|
state->bytes = (state->bits * state->xsize+7)/8;
|
||||||
}
|
}
|
||||||
/* malloc check ok, overflow checked above */
|
/* malloc check ok, overflow checked above */
|
||||||
state->buffer = (UINT8*) malloc(state->bytes);
|
state->buffer = (UINT8*) malloc(state->bytes);
|
||||||
if (!state->buffer) {
|
if (!state->buffer) {
|
||||||
return PyErr_NoMemory();
|
return ImagingError_MemoryError();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
16
src/encode.c
16
src/encode.c
|
@ -72,7 +72,7 @@ PyImaging_EncoderNew(int contextsize)
|
||||||
context = (void*) calloc(1, contextsize);
|
context = (void*) calloc(1, contextsize);
|
||||||
if (!context) {
|
if (!context) {
|
||||||
Py_DECREF(encoder);
|
Py_DECREF(encoder);
|
||||||
(void) PyErr_NoMemory();
|
(void) ImagingError_MemoryError();
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -194,7 +194,7 @@ _encode_to_file(ImagingEncoderObject* encoder, PyObject* args)
|
||||||
/* malloc check ok, either constant int, or checked by PyArg_ParseTuple */
|
/* malloc check ok, either constant int, or checked by PyArg_ParseTuple */
|
||||||
buf = (UINT8*) malloc(bufsize);
|
buf = (UINT8*) malloc(bufsize);
|
||||||
if (!buf) {
|
if (!buf) {
|
||||||
return PyErr_NoMemory();
|
return ImagingError_MemoryError();
|
||||||
}
|
}
|
||||||
|
|
||||||
ImagingSectionEnter(&cookie);
|
ImagingSectionEnter(&cookie);
|
||||||
|
@ -271,13 +271,13 @@ _setimage(ImagingEncoderObject* encoder, PyObject* args)
|
||||||
/* Allocate memory buffer (if bits field is set) */
|
/* Allocate memory buffer (if bits field is set) */
|
||||||
if (state->bits > 0) {
|
if (state->bits > 0) {
|
||||||
if (state->xsize > ((INT_MAX / state->bits)-7)) {
|
if (state->xsize > ((INT_MAX / state->bits)-7)) {
|
||||||
return PyErr_NoMemory();
|
return ImagingError_MemoryError();
|
||||||
}
|
}
|
||||||
state->bytes = (state->bits * state->xsize+7)/8;
|
state->bytes = (state->bits * state->xsize+7)/8;
|
||||||
/* malloc check ok, overflow checked above */
|
/* malloc check ok, overflow checked above */
|
||||||
state->buffer = (UINT8*) malloc(state->bytes);
|
state->buffer = (UINT8*) malloc(state->bytes);
|
||||||
if (!state->buffer) {
|
if (!state->buffer) {
|
||||||
return PyErr_NoMemory();
|
return ImagingError_MemoryError();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -604,7 +604,7 @@ PyImaging_ZipEncoderNew(PyObject* self, PyObject* args)
|
||||||
/* malloc check ok, size comes from PyArg_ParseTuple */
|
/* malloc check ok, size comes from PyArg_ParseTuple */
|
||||||
char* p = malloc(dictionary_size);
|
char* p = malloc(dictionary_size);
|
||||||
if (!p) {
|
if (!p) {
|
||||||
return PyErr_NoMemory();
|
return ImagingError_MemoryError();
|
||||||
}
|
}
|
||||||
memcpy(p, dictionary, dictionary_size);
|
memcpy(p, dictionary, dictionary_size);
|
||||||
dictionary = p;
|
dictionary = p;
|
||||||
|
@ -1005,7 +1005,7 @@ static unsigned int* get_qtables_arrays(PyObject* qtables, int* qtablesLen) {
|
||||||
qarrays = (unsigned int*) malloc(num_tables * DCTSIZE2 * sizeof(unsigned int));
|
qarrays = (unsigned int*) malloc(num_tables * DCTSIZE2 * sizeof(unsigned int));
|
||||||
if (!qarrays) {
|
if (!qarrays) {
|
||||||
Py_DECREF(tables);
|
Py_DECREF(tables);
|
||||||
PyErr_NoMemory();
|
ImagingError_MemoryError();
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
for (i = 0; i < num_tables; i++) {
|
for (i = 0; i < num_tables; i++) {
|
||||||
|
@ -1091,7 +1091,7 @@ PyImaging_JpegEncoderNew(PyObject* self, PyObject* args)
|
||||||
/* malloc check ok, length is from python parsearg */
|
/* malloc check ok, length is from python parsearg */
|
||||||
char* p = malloc(extra_size); // Freed in JpegEncode, Case 5
|
char* p = malloc(extra_size); // Freed in JpegEncode, Case 5
|
||||||
if (!p) {
|
if (!p) {
|
||||||
return PyErr_NoMemory();
|
return ImagingError_MemoryError();
|
||||||
}
|
}
|
||||||
memcpy(p, extra, extra_size);
|
memcpy(p, extra, extra_size);
|
||||||
extra = p;
|
extra = p;
|
||||||
|
@ -1106,7 +1106,7 @@ PyImaging_JpegEncoderNew(PyObject* self, PyObject* args)
|
||||||
if (extra) {
|
if (extra) {
|
||||||
free(extra);
|
free(extra);
|
||||||
}
|
}
|
||||||
return PyErr_NoMemory();
|
return ImagingError_MemoryError();
|
||||||
}
|
}
|
||||||
memcpy(pp, rawExif, rawExifLen);
|
memcpy(pp, rawExif, rawExifLen);
|
||||||
rawExif = pp;
|
rawExif = pp;
|
||||||
|
|
|
@ -53,16 +53,16 @@ alloc_array(Py_ssize_t count)
|
||||||
{
|
{
|
||||||
double* xy;
|
double* xy;
|
||||||
if (count < 0) {
|
if (count < 0) {
|
||||||
PyErr_NoMemory();
|
ImagingError_MemoryError();
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
if ((unsigned long long)count > (SIZE_MAX / (2 * sizeof(double))) - 1 ) {
|
if ((unsigned long long)count > (SIZE_MAX / (2 * sizeof(double))) - 1 ) {
|
||||||
PyErr_NoMemory();
|
ImagingError_MemoryError();
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
xy = malloc(2 * count * sizeof(double) + 1);
|
xy = malloc(2 * count * sizeof(double) + 1);
|
||||||
if (!xy) {
|
if (!xy) {
|
||||||
PyErr_NoMemory();
|
ImagingError_MemoryError();
|
||||||
}
|
}
|
||||||
return xy;
|
return xy;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user