Ran the static analyzer on the codebase and found a few things.

llvm-svn: 160338
diff --git a/lldb/tools/debugserver/source/DNB.cpp b/lldb/tools/debugserver/source/DNB.cpp
index d668744..820da8b 100644
--- a/lldb/tools/debugserver/source/DNB.cpp
+++ b/lldb/tools/debugserver/source/DNB.cpp
@@ -1214,9 +1214,9 @@
         case '%':
             {
                 f++;    // Skip the '%' character
-                int min_field_width = 0;
-                int precision = 0;
-                uint32_t flags = 0;
+//                int min_field_width = 0;
+//                int precision = 0;
+                //uint32_t flags = 0;
                 uint32_t length_modifiers = 0;
                 uint32_t byte_size = 0;
                 uint32_t actual_byte_size = 0;
@@ -1233,12 +1233,12 @@
                 // Decode any flags
                 switch (*f)
                 {
-                case '#': fprintf_format += *f++; flags |= alternate_form;            break;
-                case '0': fprintf_format += *f++; flags |= zero_padding;            break;
-                case '-': fprintf_format += *f++; flags |= negative_field_width;    break;
-                case ' ': fprintf_format += *f++; flags |= blank_space;                break;
-                case '+': fprintf_format += *f++; flags |= show_sign;                break;
-                case ',': fprintf_format += *f++; flags |= show_thousands_separator;break;
+                case '#': fprintf_format += *f++; break; //flags |= alternate_form;          break;
+                case '0': fprintf_format += *f++; break; //flags |= zero_padding;            break;
+                case '-': fprintf_format += *f++; break; //flags |= negative_field_width;    break;
+                case ' ': fprintf_format += *f++; break; //flags |= blank_space;             break;
+                case '+': fprintf_format += *f++; break; //flags |= show_sign;               break;
+                case ',': fprintf_format += *f++; break; //flags |= show_thousands_separator;break;
                 case '{':
                 case '[':
                     {
@@ -1330,7 +1330,8 @@
                 // Check for a minimum field width
                 if (isdigit(*f))
                 {
-                    min_field_width = strtoul(f, &end, 10);
+                    //min_field_width = strtoul(f, &end, 10);
+                    strtoul(f, &end, 10);
                     if (end > f)
                     {
                         fprintf_format.append(f, end - f);
@@ -1346,7 +1347,8 @@
                     if (isdigit(*f))
                     {
                         fprintf_format += '.';
-                        precision = strtoul(f, &end, 10);
+                        //precision = strtoul(f, &end, 10);
+                        strtoul(f, &end, 10);
                         if (end > f)
                         {
                             fprintf_format.append(f, end - f);
@@ -1453,7 +1455,7 @@
                             byte_size = sizeof(char);
                         else if (length_modifiers & length_mod_h)
                             byte_size = sizeof(short);
-                        if (length_modifiers & length_mod_ll)
+                        else if (length_modifiers & length_mod_ll)
                             byte_size = sizeof(long long);
                         else if (length_modifiers & length_mod_l)
                             byte_size = sizeof(long);
diff --git a/lldb/tools/debugserver/source/MacOSX/MachException.cpp b/lldb/tools/debugserver/source/MacOSX/MachException.cpp
index ead512e..9856867 100644
--- a/lldb/tools/debugserver/source/MacOSX/MachException.cpp
+++ b/lldb/tools/debugserver/source/MacOSX/MachException.cpp
@@ -122,7 +122,6 @@
     mach_msg_type_number_t *new_stateCnt
 )
 {
-    kern_return_t kret;
     if (DNBLogCheckLogBit(LOG_EXCEPTIONS))
     {
         DNBLogThreaded("::%s ( exc_port = 0x%4.4x, thd_port = 0x%4.4x, tsk_port = 0x%4.4x, exc_type = %d ( %s ), exc_data[%d] = { 0x%llx, 0x%llx })",
@@ -135,8 +134,8 @@
             (uint64_t)(exc_data_count > 0 ? exc_data[0] : 0xBADDBADD),
             (uint64_t)(exc_data_count > 1 ? exc_data[1] : 0xBADDBADD));
     }
-    kret = mach_port_deallocate (mach_task_self (), task_port);
-    kret = mach_port_deallocate (mach_task_self (), thread_port);
+    mach_port_deallocate (mach_task_self (), task_port);
+    mach_port_deallocate (mach_task_self (), thread_port);
 
     return KERN_FAILURE;
 }
@@ -229,7 +228,7 @@
         if (desc < end_desc)
         {
             const char *sig_str = SysSignal::Name(soft_signal);
-            desc += snprintf(desc, end_desc - desc, " EXC_SOFT_SIGNAL( %i ( %s ))", soft_signal, sig_str ? sig_str : "unknown signal");
+            snprintf(desc, end_desc - desc, " EXC_SOFT_SIGNAL( %i ( %s ))", soft_signal, sig_str ? sig_str : "unknown signal");
         }
     }
     else
diff --git a/lldb/tools/debugserver/source/MacOSX/MachProcess.cpp b/lldb/tools/debugserver/source/MacOSX/MachProcess.cpp
index 4d78778..2dcbb67 100644
--- a/lldb/tools/debugserver/source/MacOSX/MachProcess.cpp
+++ b/lldb/tools/debugserver/source/MacOSX/MachProcess.cpp
@@ -421,8 +421,7 @@
     {
         DisableAllBreakpoints (true);
         DisableAllWatchpoints (true);
-        // The static analyzer complains about this, but just leave the following line in.
-         clear_bps_and_wps = false;
+        //clear_bps_and_wps = false;
     }
     uint32_t thread_idx = m_thread_list.GetThreadIndexForThreadStoppedWithSignal (SIGSTOP);
     if (thread_idx_ptr)
@@ -1865,18 +1864,20 @@
 
         // If our parent is setgid, lets make sure we don't inherit those
         // extra powers due to nepotism.
-        ::setgid (getgid ());
+        if (::setgid (getgid ()) == 0)
+        {
 
-        // Let the child have its own process group. We need to execute
-        // this call in both the child and parent to avoid a race condition
-        // between the two processes.
-        ::setpgid (0, 0);    // Set the child process group to match its pid
+            // Let the child have its own process group. We need to execute
+            // this call in both the child and parent to avoid a race condition
+            // between the two processes.
+            ::setpgid (0, 0);    // Set the child process group to match its pid
 
-        // Sleep a bit to before the exec call
-        ::sleep (1);
+            // Sleep a bit to before the exec call
+            ::sleep (1);
 
-        // Turn this process into
-        ::execv (path, (char * const *)argv);
+            // Turn this process into
+            ::execv (path, (char * const *)argv);
+        }
         // Exit with error code. Child process should have taken
         // over in above exec call and if the exec fails it will
         // exit the child process below.
diff --git a/lldb/tools/debugserver/source/MacOSX/MachThreadList.cpp b/lldb/tools/debugserver/source/MacOSX/MachThreadList.cpp
index b8044fe..8e35069 100644
--- a/lldb/tools/debugserver/source/MacOSX/MachThreadList.cpp
+++ b/lldb/tools/debugserver/source/MacOSX/MachThreadList.cpp
@@ -470,9 +470,9 @@
 uint32_t
 MachThreadList::EnableHardwareWatchpoint (const DNBBreakpoint* wp) const
 {
+    uint32_t hw_index = INVALID_NUB_HW_INDEX;
     if (wp != NULL)
     {
-        uint32_t hw_index;
         PTHREAD_MUTEX_LOCKER (locker, m_threads_mutex);
         const uint32_t num_threads = m_threads.size();
         for (uint32_t idx = 0; idx < num_threads; ++idx)
@@ -492,9 +492,8 @@
         // Use an arbitrary thread to signal the completion of our transaction.
         if (num_threads)
             m_threads[0]->HardwareWatchpointStateChanged();
-        return hw_index;
     }
-    return INVALID_NUB_HW_INDEX;
+    return hw_index;
 }
 
 bool
diff --git a/lldb/tools/debugserver/source/RNBRemote.cpp b/lldb/tools/debugserver/source/RNBRemote.cpp
index 9f447c7..4b2571d 100644
--- a/lldb/tools/debugserver/source/RNBRemote.cpp
+++ b/lldb/tools/debugserver/source/RNBRemote.cpp
@@ -1674,7 +1674,7 @@
                 }
             }
             // Did we get a properly formatted logging bitmask?
-            if (*p == ';')
+            if (p && *p == ';')
             {
                 // Enable DNB logging
                 DNBLogSetLogCallback(ASLLogCallback, NULL);
@@ -2028,14 +2028,21 @@
 register_value_in_hex_fixed_width (std::ostream& ostrm,
                                    nub_process_t pid,
                                    nub_thread_t tid,
-                                   const register_map_entry_t* reg)
+                                   const register_map_entry_t* reg,
+                                   const DNBRegisterValue *reg_value_ptr)
 {
     if (reg != NULL)
     {
-        DNBRegisterValue val;
-        if (DNBThreadGetRegisterValueByID (pid, tid, reg->nub_info.set, reg->nub_info.reg, &val))
+        DNBRegisterValue reg_value;
+        if (reg_value_ptr == NULL)
         {
-            append_hex_value (ostrm, val.value.v_uint8, reg->gdb_size, false);
+            if (DNBThreadGetRegisterValueByID (pid, tid, reg->nub_info.set, reg->nub_info.reg, &reg_value))
+                reg_value_ptr = &reg_value;
+        }
+        
+        if (reg_value_ptr)
+        {
+            append_hex_value (ostrm, reg_value_ptr->value.v_uint8, reg->gdb_size, false);
         }
         else
         {
@@ -2063,7 +2070,8 @@
 gdb_regnum_with_fixed_width_hex_register_value (std::ostream& ostrm,
                                                 nub_process_t pid,
                                                 nub_thread_t tid,
-                                                const register_map_entry_t* reg)
+                                                const register_map_entry_t* reg,
+                                                const DNBRegisterValue *reg_value_ptr)
 {
     // Output the register number as 'NN:VVVVVVVV;' where NN is a 2 bytes HEX
     // gdb register number, and VVVVVVVV is the correct number of hex bytes
@@ -2071,7 +2079,7 @@
     if (reg != NULL)
     {
         ostrm << RAWHEX8(reg->gdb_regnum) << ':';
-        register_value_in_hex_fixed_width (ostrm, pid, tid, reg);
+        register_value_in_hex_fixed_width (ostrm, pid, tid, reg, reg_value_ptr);
         ostrm << ';';
     }
 }
@@ -2173,15 +2181,18 @@
         if (g_num_reg_entries == 0)
             InitializeRegisters ();
 
-        DNBRegisterValue reg_value;
-        for (uint32_t reg = 0; reg < g_num_reg_entries; reg++)
+        if (g_reg_entries != NULL)
         {
-            if (g_reg_entries[reg].expedite)
+            DNBRegisterValue reg_value;
+            for (uint32_t reg = 0; reg < g_num_reg_entries; reg++)
             {
-                if (!DNBThreadGetRegisterValueByID (pid, tid, g_reg_entries[reg].nub_info.set, g_reg_entries[reg].nub_info.reg, &reg_value))
-                    continue;
+                if (g_reg_entries[reg].expedite)
+                {
+                    if (!DNBThreadGetRegisterValueByID (pid, tid, g_reg_entries[reg].nub_info.set, g_reg_entries[reg].nub_info.reg, &reg_value))
+                        continue;
 
-                gdb_regnum_with_fixed_width_hex_register_value (ostrm, pid, tid, &g_reg_entries[reg]);
+                    gdb_regnum_with_fixed_width_hex_register_value (ostrm, pid, tid, &g_reg_entries[reg], &reg_value);
+                }
             }
         }
 
@@ -2496,7 +2507,7 @@
     }
     
     for (uint32_t reg = 0; reg < g_num_reg_entries; reg++)
-        register_value_in_hex_fixed_width (ostrm, pid, tid, &g_reg_entries[reg]);
+        register_value_in_hex_fixed_width (ostrm, pid, tid, &g_reg_entries[reg], NULL);
 
     return SendPacket (ostrm.str ());
 }
@@ -2695,7 +2706,6 @@
     }
     else if (strstr (p, "vCont") == p)
     {
-        rnb_err_t rnb_err = rnb_success;
         typedef struct
         {
             nub_thread_t tid;
@@ -2747,7 +2757,7 @@
                     break;
 
                 default:
-                    rnb_err = HandlePacket_ILLFORMED (__FILE__, __LINE__, p, "Unsupported action in vCont packet");
+                    HandlePacket_ILLFORMED (__FILE__, __LINE__, p, "Unsupported action in vCont packet");
                     break;
             }
             if (*c == ':')
@@ -3194,7 +3204,7 @@
     }
     else
     {
-        register_value_in_hex_fixed_width (ostrm, pid, tid, reg_entry);
+        register_value_in_hex_fixed_width (ostrm, pid, tid, reg_entry, NULL);
     }
     return SendPacket (ostrm.str());
 }
diff --git a/lldb/tools/debugserver/source/debugserver.cpp b/lldb/tools/debugserver/source/debugserver.cpp
index 3274925..fe98848 100644
--- a/lldb/tools/debugserver/source/debugserver.cpp
+++ b/lldb/tools/debugserver/source/debugserver.cpp
@@ -1141,6 +1141,7 @@
 
     int listen_port = INT32_MAX;
     char str[PATH_MAX];
+    str[0] = '\0';
 
     if (g_lockdown_opt == 0 && g_applist_opt == 0)
     {