scripts: Additional array null check -- handcoded

Add the null checks from the auto gen'd path to the handcoded routines.

Change-Id: I36983e921b0be8b7cec5ca86ccbabef5f3864f37
diff --git a/scripts/thread_safety_generator.py b/scripts/thread_safety_generator.py
index 2ba7934..9c0c7df 100644
--- a/scripts/thread_safety_generator.py
+++ b/scripts/thread_safety_generator.py
@@ -523,9 +523,11 @@
     FinishWriteObject(pAllocateInfo->commandPool);
 
     // Record mapping from command buffer to command pool
-    for (uint32_t index = 0; index < pAllocateInfo->commandBufferCount; index++) {
+    if(pCommandBuffers) {
         std::lock_guard<std::mutex> lock(command_pool_lock);
-        command_pool_map[pCommandBuffers[index]] = pAllocateInfo->commandPool;
+        for (uint32_t index = 0; index < pAllocateInfo->commandBufferCount; index++) {
+            command_pool_map[pCommandBuffers[index]] = pAllocateInfo->commandPool;
+        }
     }
 }
 
@@ -548,15 +550,22 @@
     const bool lockCommandPool = false;  // pool is already directly locked
     StartReadObject(device);
     StartWriteObject(commandPool);
-    for (uint32_t index = 0; index < commandBufferCount; index++) {
-        StartWriteObject(pCommandBuffers[index], lockCommandPool);
-    }
-    // The driver may immediately reuse command buffers in another thread.
-    // These updates need to be done before calling down to the driver.
-    for (uint32_t index = 0; index < commandBufferCount; index++) {
-        FinishWriteObject(pCommandBuffers[index], lockCommandPool);
+    if(pCommandBuffers) {
+        // Even though we're immediately "finishing" below, we still are testing for concurrency with any call in process
+        // so this isn't a no-op
+        for (uint32_t index = 0; index < commandBufferCount; index++) {
+            StartWriteObject(pCommandBuffers[index], lockCommandPool);
+        }
+        // The driver may immediately reuse command buffers in another thread.
+        // These updates need to be done before calling down to the driver.
+        for (uint32_t index = 0; index < commandBufferCount; index++) {
+            FinishWriteObject(pCommandBuffers[index], lockCommandPool);
+        }
+        // Holding the lock for the shortest time while we update the map
         std::lock_guard<std::mutex> lock(command_pool_lock);
-        command_pool_map.erase(pCommandBuffers[index]);
+        for (uint32_t index = 0; index < commandBufferCount; index++) {
+            command_pool_map.erase(pCommandBuffers[index]);
+        }
     }
 }