Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
View | Details | Raw Unified | Return to bug 591762 | Differences between
and this patch

Collapse All | Expand All

(-)a/top/top.c (-5 / +30 lines)
Lines 1552-1566 static const char *scale_mem (int target, unsigned long num, int width, int just Link Here
1552
   if (Rc.zero_suppress && 0 >= num)
1552
   if (Rc.zero_suppress && 0 >= num)
1553
      goto end_justifies;
1553
      goto end_justifies;
1554
1554
1555
   i = SK_Kb;
1556
   psfx = Scaled_sfxtab;
1555
   scaled_num = num;
1557
   scaled_num = num;
1556
   for (i = SK_Kb, psfx = Scaled_sfxtab; i < SK_Eb; psfx++, i++) {
1558
1557
      if (i >= target
1559
   // apply the minimum scaling
1558
      && (width >= snprintf(buf, sizeof(buf), fmttab[i], scaled_num, *psfx)))
1560
   while (i < target) {
1559
         goto end_justifies;
1561
      psfx++;
1562
      i++;
1560
      scaled_num /= 1024.0;
1563
      scaled_num /= 1024.0;
1561
   }
1564
   }
1562
1565
1563
   // well shoot, this outta' fit...
1566
   // get it to fit in the buffer
1567
   while (i <= SK_Eb) {
1568
      // first try lopping off digits
1569
      static char fmt[SMLBUFSIZ];
1570
      int precision = (i == 0 ? 0 : 3);
1571
1572
      do {
1573
         snprintf(fmt, sizeof(fmt), "%%.%uf%%c", precision);
1574
         if (snprintf(buf, sizeof(buf), fmt, scaled_num, (i > 0 ? *psfx : '\0')) <= width) {
1575
            goto end_justifies; // it fits!
1576
         }
1577
         // drop a digit off the end and try again
1578
         precision--;
1579
      } while (precision > 0);
1580
1581
      // dropped all digits after decimal, still too big
1582
      // scale it and try again.
1583
      psfx++;
1584
      i++;
1585
      scaled_num /= 1024.0;
1586
   }
1587
1588
   // everything failed
1564
   snprintf(buf, sizeof(buf), "?");
1589
   snprintf(buf, sizeof(buf), "?");
1565
end_justifies:
1590
end_justifies:
1566
   return justify_pad(buf, width, justr);
1591
   return justify_pad(buf, width, justr);

Return to bug 591762