glapi: parameter checking, failure paths, ... for add_function_name
authorGeorge Sapountzis <gsapountzis@gmail.com>
Sun, 7 Mar 2010 23:40:14 +0000 (01:40 +0200)
committerGeorge Sapountzis <gsapountzis@gmail.com>
Wed, 10 Mar 2010 16:44:45 +0000 (18:44 +0200)
src/mesa/glapi/glapi_getproc.c

index a4d2cb907c9e0d79826c87ceca66e0d26c0a10d1..ea905bb2cb46ad77c06b50b98c6d21b9b9f08ad9 100644 (file)
@@ -293,20 +293,34 @@ static struct _glapi_function *
 add_function_name( const char * funcName )
 {
    struct _glapi_function * entry = NULL;
-   
-   if (NumExtEntryPoints < MAX_EXTENSION_FUNCS) {
-      _glapi_proc entrypoint = generate_entrypoint(~0);
-      if (entrypoint != NULL) {
-        entry = & ExtEntryTable[NumExtEntryPoints];
-
-        ExtEntryTable[NumExtEntryPoints].name = str_dup(funcName);
-        ExtEntryTable[NumExtEntryPoints].parameter_signature = NULL;
-        ExtEntryTable[NumExtEntryPoints].dispatch_offset = ~0;
-        ExtEntryTable[NumExtEntryPoints].dispatch_stub = entrypoint;
-        NumExtEntryPoints++;
-      }
+   _glapi_proc entrypoint = NULL;
+   char * name_dup = NULL;
+
+   if (NumExtEntryPoints >= MAX_EXTENSION_FUNCS)
+      return NULL;
+
+   if (funcName == NULL)
+      return NULL;
+
+   name_dup = str_dup(funcName);
+   if (name_dup == NULL)
+      return NULL;
+
+   entrypoint = generate_entrypoint(~0);
+
+   if (entrypoint == NULL) {
+      free(name_dup);
+      return NULL;
    }
 
+   entry = & ExtEntryTable[NumExtEntryPoints];
+   NumExtEntryPoints++;
+
+   entry->name = name_dup;
+   entry->parameter_signature = NULL;
+   entry->dispatch_offset = ~0;
+   entry->dispatch_stub = entrypoint;
+
    return entry;
 }