[PATCH][wireguard-android] fix formatBytes to be able to display gibibytes

François Guerraz kubrick at fgv6.net
Tue Feb 25 23:41:00 CET 2020


The default type for literal numerals is int, not long it, therefore
1024*1024*1024*1024
overflows and
    bytes < 1024*1024*1024*1024
is always false.
Therefore, GiBi is never displayed and switches to TiBi immediately.
---
diff --git a/app/src/main/java/com/wireguard/android/fragment/TunnelDetailFragment.java
b/app/src/main/java/com/wireguard/android/fragment/TunnelDetailFragment.java
index 57e0d8e..bc0726a 100644
--- a/app/src/main/java/com/wireguard/android/fragment/TunnelDetailFragment.java
+++ b/app/src/main/java/com/wireguard/android/fragment/TunnelDetailFragment.java
@@ -115,7 +115,7 @@ public class TunnelDetailFragment extends BaseFragment {
             return
getContext().getString(R.string.transfer_kibibytes, bytes/1024.0);
         else if (bytes < 1024*1024*1024)
             return
getContext().getString(R.string.transfer_mibibytes,
bytes/(1024.0*1024.0));
-        else if (bytes < 1024*1024*1024*1024)
+        else if (bytes < 1024*1024*1024*1024L)
             return
getContext().getString(R.string.transfer_gibibytes,
bytes/(1024.0*1024.0*1024.0));
         return getContext().getString(R.string.transfer_tibibytes,
bytes/(1024.0*1024.0*1024.0)/1024.0);
     }


More information about the WireGuard mailing list