[PATCH] Fix incorrect usage percentage in Properties dialog for virtual filesystems
authorEfe Çiftci <efeciftci@gmail.com>
Fri, 16 May 2025 17:50:21 +0000 (20:50 +0300)
committerAurélien COUDERC <coucouf@debian.org>
Sun, 8 Jun 2025 12:42:29 +0000 (14:42 +0200)
The Properties dialog for filesystems such as `/proc/` or `/sys/` shows an
incorrect usage percentage (i.e., "-2,147,483,648% used"). This commit fixes
that issue by avoiding a divbyzero: if the `size` variable is `0`, the
`percentUsed` variable is set to `0`.

Gbp-Pq: Name upstream_81ca0e2c_Fix-incorrect-usage-percentage-in-Properties-dialog-for-virtual-filesystems.patch

src/widgets/kpropertiesdialogbuiltin_p.cpp

index 25e146de532fc87201d43c0dcb8ab211b2dc7239..910ab163030eeabe2bd7cbb9d7fb8ce93236e485 100644 (file)
@@ -664,7 +664,7 @@ void KFilePropsPlugin::slotFreeSpaceResult(KJob *_job)
         const qint64 size = job->size();
         const qint64 available = job->availableSize();
         const quint64 used = size - available;
-        const int percentUsed = qRound(100.0 * qreal(used) / qreal(size));
+        const int percentUsed = (size == 0) ? 0 : qRound(100.0 * qreal(used) / qreal(size));
 
         d->m_ui->capacityBar->setText(i18nc("Available space out of total partition size (percent used)",
                                             "%1 free of %2 (%3% used)",