]> granicus.if.org Git - python/commitdiff
Handle alloca failures.
authorNeal Norwitz <nnorwitz@gmail.com>
Sun, 13 Aug 2006 18:40:39 +0000 (18:40 +0000)
committerNeal Norwitz <nnorwitz@gmail.com>
Sun, 13 Aug 2006 18:40:39 +0000 (18:40 +0000)
Klocwork 225-228

Modules/_ctypes/_ctypes.c
Modules/_ctypes/callproc.c

index d26ad1d3e26113ff0dbfbdf3fff3b0892760b7e7..cf0b20dd6f9d4f75bd3403536eeec8406e980019 100644 (file)
@@ -2475,6 +2475,8 @@ static PPROC FindAddress(void *handle, char *name, PyObject *type)
           where n is 0, 4, 8, 12, ..., 128
         */
        mangled_name = alloca(strlen(name) + 1 + 1 + 1 + 3); /* \0 _ @ %d */
+       if (!mangled_name)
+               return NULL;
        for (i = 0; i < 32; ++i) {
                sprintf(mangled_name, "_%s@%d", name, i*4);
                address = (PPROC)GetProcAddress(handle, mangled_name);
index d6f875b946008d8218e1061a534734db7c710ef8..77f879eab80ce5fe67cc2a24aae5a562188adfda 100644 (file)
@@ -915,6 +915,10 @@ PyObject *_CallProc(PPROC pProc,
 #endif
 
        args = (struct argument *)alloca(sizeof(struct argument) * argcount);
+       if (!args) {
+               PyErr_NoMemory();
+               return NULL;
+       }
        memset(args, 0, sizeof(struct argument) * argcount);
        argtype_count = argtypes ? PyTuple_GET_SIZE(argtypes) : 0;
 #ifdef MS_WIN32
@@ -968,6 +972,10 @@ PyObject *_CallProc(PPROC pProc,
 
        avalues = (void **)alloca(sizeof(void *) * argcount);
        atypes = (ffi_type **)alloca(sizeof(ffi_type *) * argcount);
+       if (!resbuf || !avalues || !atypes) {
+               PyErr_NoMemory();
+               goto cleanup;
+       }
        for (i = 0; i < argcount; ++i) {
                atypes[i] = args[i].ffi_type;
                if (atypes[i]->type == FFI_TYPE_STRUCT)
@@ -1068,6 +1076,11 @@ static PyObject *load_library(PyObject *self, PyObject *args)
                return NULL;
 #ifdef _UNICODE
        name = alloca((PyString_Size(nameobj) + 1) * sizeof(WCHAR));
+       if (!name) {
+               PyErr_NoMemory();
+               return NULL;
+       }
+
        {
                int r;
                char *aname = PyString_AsString(nameobj);