]> git.ipfire.org Git - thirdparty/cups.git/commitdiff
dest.c: Fix infinite loop in `cups_enum_dests()`
authorZdenek Dohnal <zdohnal@redhat.com>
Thu, 4 Jan 2024 12:33:04 +0000 (13:33 +0100)
committerZdenek Dohnal <zdohnal@redhat.com>
Fri, 5 Jan 2024 05:27:08 +0000 (06:27 +0100)
Update remaining time after `usleep()`, otherwise there is no difference
in elapsed time, so `remaining` will never be less or equal to 0.

Fixes CI on Linux

cups/dest.c

index c528fdf21910de774fcc108ff8b0b0baae36128d..2dc8a937bddb805f18e4629a9171c048b484db1f 100644 (file)
@@ -3229,8 +3229,6 @@ cups_enum_dests(
     goto enum_finished;
 
   // Get DNS-SD printers...
-  gettimeofday(&curtime, NULL);
-
   if ((dnssd = cupsDNSSDNew(dnssd_error_cb, NULL)) == NULL)
   {
     DEBUG_puts("1cups_enum_dests: Unable to create service browser, returning 0.");
@@ -3268,15 +3266,13 @@ cups_enum_dests(
   else
     remaining = msec;
 
+  gettimeofday(&curtime, NULL);
+
   while (remaining > 0 && (!cancel || !*cancel))
   {
     // Check for input...
     DEBUG_printf("1cups_enum_dests: remaining=%d", remaining);
 
-    cups_elapsed(&curtime);
-
-    remaining -= cups_elapsed(&curtime);
-
     cupsRWLockRead(&data.rwlock);
 
     for (i = 0, num_devices = cupsArrayCount(data.devices), count = 0, completed = 0; i < num_devices; i ++)
@@ -3369,6 +3365,8 @@ cups_enum_dests(
       break;
 
     usleep(100000);
+
+    remaining -= cups_elapsed(&curtime);
   }
 
   // Return...