--- devel.module
+++ (clipboard)
@@ -544,60 +544,57 @@
 }
 
 function devel_block_switch_user() {
-  $links = devel_switch_user_list();
-  if (!empty($links)) {
-    $block['subject'] = t('Switch user');
-    $block['content'] = theme('links', $links);
-    $block['content'] .= drupal_get_form('devel_switch_user_form');
-    return $block;
-  }
-}
-
-function devel_switch_user_list() {
-  $links = array();
   if (user_access('switch users')) {
     $list_size = variable_get('devel_switch_user_list_size', 10);
-    $dest = drupal_get_destination();
-    // Try to find at least $list_size users that can switch.
-    $roles = user_roles(1, 'switch users');
-    if (isset($roles[2])) {
-      // If authenticated users have this permission, just grab
-      // the last $list_size users, since there won't be records in
-      // {user_roles} and every user on the system can switch.
-      $users = db_query_range("SELECT DISTINCT u.uid, u.name, u.access FROM {users} u WHERE u.uid > 0 ORDER BY u.access DESC", 0, $list_size);
-    }
-    else {
-      $where = array('u.uid = 1');
-      if (count($roles)) {
-        $where[] = 'r.rid IN ('. implode(',', array_keys($roles)) .')';
-      }
-      $where_sql = implode(' OR ', $where);
-      $users = db_query_range("SELECT DISTINCT u.uid, u.name, u.access FROM {users} u LEFT JOIN {users_roles} r ON u.uid = r.uid WHERE $where_sql ORDER BY u.access DESC", 0, $list_size);
-    }
-    while ($user = db_fetch_object($users)) {
-      $links[$user->uid] = array(
-        'title' => theme('placeholder', $user->name),
-        'href' => 'devel/switch/'. $user->name,
-        'query' => $dest,
-        'attributes' => array('title' => t('This user can switch back.')),
-        'html' => TRUE,
-      );
-    }
-    $num_links = count($links);
-    if ($num_links < $list_size) {
-      // If we don't have enough, add distinct uids until we hit $list_size.
-      $users = db_query_range('SELECT uid, name, access FROM {users} WHERE uid > 0 AND uid NOT IN ('. implode(',', array_keys($links)) .') ORDER BY access DESC', 0, $list_size - $num_links);
-      while (($user = db_fetch_object($users)) && count($links) < $list_size) {
+    $links = array();
+    if ($list_size > 0) {
+      $dest = drupal_get_destination();
+      // Try to find at least $list_size users that can switch.
+      $roles = user_roles(1, 'switch users');
+      if (isset($roles[2])) {
+        // If authenticated users have this permission, just grab
+        // the last $list_size users, since there won't be records in
+        // {user_roles} and every user on the system can switch.
+        $users = db_query_range("SELECT DISTINCT u.uid, u.name, u.access FROM {users} u WHERE u.uid > 0 ORDER BY u.access DESC", 0, $list_size);
+      }
+      else {
+        $where = array('u.uid = 1');
+        if (count($roles)) {
+          $where[] = 'r.rid IN ('. implode(',', array_keys($roles)) .')';
+        }
+        $where_sql = implode(' OR ', $where);
+        $users = db_query_range("SELECT DISTINCT u.uid, u.name, u.access FROM {users} u LEFT JOIN {users_roles} r ON u.uid = r.uid WHERE $where_sql ORDER BY u.access DESC", 0, $list_size);
+      }
+      while ($user = db_fetch_object($users)) {
         $links[$user->uid] = array(
-          'title' => $user->name ? $user->name : 'anon',
+          'title' => theme('placeholder', $user->name),
           'href' => 'devel/switch/'. $user->name,
           'query' => $dest,
-          'attributes' => array('title' => t('Caution: this user will be unable switch back.')),
+          'attributes' => array('title' => t('This user can switch back.')),
+          'html' => TRUE,
         );
       }
+      $num_links = count($links);
+      if ($num_links < $list_size) {
+        // If we don't have enough, add distinct uids until we hit $list_size.
+        $users = db_query_range('SELECT uid, name, access FROM {users} WHERE uid > 0 AND uid NOT IN ('. implode(',', array_keys($links)) .') ORDER BY access DESC', 0, $list_size - $num_links);
+        while (($user = db_fetch_object($users)) && count($links) < $list_size) {
+          $links[$user->uid] = array(
+            'title' => $user->name ? $user->name : 'anon',
+            'href' => 'devel/switch/'. $user->name,
+            'query' => $dest,
+            'attributes' => array('title' => t('Caution: this user will be unable switch back.')),
+          );
+        }
+      }
+    }
+    if (!empty($links) or $list_size == 0) {
+      $block['subject'] = t('Switch user');
+      $block['content'] = theme('links', $links);
+      $block['content'] .= drupal_get_form('devel_switch_user_form');
+      return $block;
     }
   }
-  return $links;
 }
 
 function devel_phpinfo() {

