--- gpilotd/manager.c~	2005-06-25 02:13:04.000000000 -0400
+++ gpilotd/manager.c	2005-06-25 10:50:46.000000000 -0400
@@ -299,23 +299,30 @@
 
 	orbed_notify_daemon_message (pilot_info->name, NULL, _("Collecting synchronization info..."));
 
+	while (1)
 	{
-		int i;
 		pi_buffer_t *pi_buf;
 		int result;
+		GnomePilotDBInfo *dbinfo;
 
-		pi_buf = pi_buffer_new (0xffff);       
+		pi_buf = pi_buffer_new (sizeof (struct DBInfo));
 		result = dlp_ReadDBList (pfd, 0, dlpDBListRAM, index, pi_buf);
-
-		for (i=0;i<result;i++) {
-			GnomePilotDBInfo *dbinfo;
-		
-			dbinfo = g_new0 (GnomePilotDBInfo, 1);
-			memcpy (dbinfo, pi_buf->data + (sizeof(struct DBInfo)*i), sizeof(struct DBInfo));
-			index = PI_DBINFO (dbinfo)->index + 1;
-			dbs = g_list_append (dbs, dbinfo);
+		if (result < 0)
+		{
+			pi_buffer_free (pi_buf);
+			if ((result != PI_ERR_DLP_PALMOS) || (pi_palmos_error (pfd) != dlpErrNotFound))
+			{
+				g_error ("Error reading databases from Palm!");
+				g_list_free (dbs);
+				return -1;
+			}
+			break;
 		}
 
+		dbinfo = g_new0 (GnomePilotDBInfo, 1);
+		memcpy (dbinfo, pi_buf->data, sizeof (struct DBInfo));
+		index = PI_DBINFO (dbinfo)->index + 1;
+		dbs = g_list_append (dbs, dbinfo);
 		pi_buffer_free (pi_buf);
 	}
 
