Commit Graph

68 Commits

Author SHA1 Message Date
Daniel Flanagan dd33444f7e Clean up existing whitespace 2019-10-31 11:39:12 -05:00
Hisham Muhammad ff78a1bfce Fix out-of-bounds read
Detected by Coverity:
https://scan8.coverity.com/reports.htm#v13252/p10402/fileInstanceId=22093847&defectInstanceId=7543344&mergedDefectId=174181
2018-02-18 10:17:56 -03:00
Hisham Muhammad f4f35da7e0 Fix indentation 2018-02-18 10:17:29 -03:00
Hisham Muhammad b544c22c72 Fix issue with small terminals.
Fixes #733.
2018-02-13 06:41:44 -02:00
coypoop b84ebfd4e8 Clarify we are looking for the null termination
Not for a comparison to zero
2018-02-04 17:02:30 +01:00
Hisham Muhammad 09e241fb12 Security review: check results of snprintf.
Calls marked with xSnprintf shouldn't fail.
Abort program cleanly if any of them does.
2017-07-27 16:07:50 -03:00
Hisham Muhammad 821d50f0b4 Merge pull request #651 from Explorer09/graph-mode-draw
Round values in graph drawing (instead of implicit truncate)
2017-07-26 16:15:59 -03:00
Richard d5faf64374 Mark some things as const
Several string pointer arrays pointed to const strings
but were not const themselves.

A few various structures and arrays were also marked const.
2017-07-22 22:34:30 -05:00
Explorer09 143a7de6b2 Round values in graph drawing (instead of implicit truncate) 2017-07-15 22:14:44 +08:00
Explorer09 6b9b6db655 Let BarMeterMode_characters[] be const array. 2016-07-22 14:58:29 +08:00
Explorer09 313b3d3752 Remove redundant is-null checks on free(Meter.drawData) 2016-05-27 17:11:54 +08:00
Explorer09 9dea20e068 Rename Meter.setValues() functions to updateValues()
Rationale (copied from htop issue #471):
The function name "setValues" is misleading. For most OOP (object-
oriented programming) contexts, setXXX functions mean they will change
some member variables of an object into something specified in
function arguments. But in the *Meter_setValues() case, the new values
are not from the arguments, but from a hard-coded source. The caller
is not supposed to change the values[] to anything it likes, but
rather to "update" the values from the source. Hence, updateValues is
a better name for this family of functions.
2016-05-04 13:39:26 +08:00
Explorer09 7b3c8bc77a BarMeterMode_draw minor code improvement
Removed a loop that sets the bar[] buffer with spaces and merged that
task to the snprintf() call just below. No need for the barOffset
variable. Display behavior is unchanged.

Size comparision (when compiled on Ubuntu 14.04 64-bit):

    $ size htop.old htop.new
       text    data     bss     dec     hex filename
     137312   15112    3776  156200   26228 htop.old
     137216   15112    3776  156104   261c8 htop.new
2016-03-22 14:52:31 +08:00
Explorer09 99fb3070a2 Explicit "maxItems" property of meters
Two changes in this commit:
- All meters now explicitly specify "maxItems" property, even for just
  1 item. (Exception is "container" CPU meter classes, which use
  CUSTOM_METERMODE.)
- "maxItems" being 0 is now allowed. This will let bar meters and graph
  meters render an empty meter.
2016-03-11 10:54:34 +08:00
Hisham d311e85b91 Avoid crash on huge screens.
Fix by @Explorer09 (see discussion on #355).
2016-02-02 23:20:11 +00:00
Hisham b54d2dde40 Check for failure in allocations. 2016-02-02 15:53:02 +01:00
Explorer09 040613db33 Change variable 'dot' to avoid division by reciprocal.
(Cherry-picked from d56bcd8e0d8d6a177fc2e40db32fc73ea4588684, the
experimental graph coloring branch)

The variable 'dot' in GraphMeterMode_draw now means "maximum number of
dots per value (column) in graph". The old meaning was "amount of value
that is to be represented by a dot" and was always a fraction. Due to
a limitation in floating point computing, if GRAPH_HEIGHT were not a
power of 2, then rounding errors will occur on numbers like (1.0/3).
(Currently GRAPH_HEIGHT is 4 and so no precision loss.) 'dot' was used
as a divisor, and it's "division by a reciprocal". We change that to
simple multiplication.
2016-01-21 14:06:11 +08:00
Explorer09 d54ab24d97 New macro GRAPH_HEIGHT for Graph Meter height
(Cherry-picked from e93028d7fa0c5f00b5dc3336fd28abaf905cd572, the
experimental graph coloring branch)

Currently GRAPH_HEIGHT=4 . This prevents hard-coding the height of the graph
meters, and allows user to change it at compile-time.
2016-01-21 10:11:54 +08:00
Explorer09 6dae8108f8 Introduce CLAMP macro. Unify all MIN(MAX(a,b),c) uses.
With the CLAMP macro replacing the combination of MIN and MAX, we will
have at least two advantages:
1. It's more obvious semantically.
2. There are no more mixes of confusing uses like MIN(MAX(a,b),c) and
   MAX(MIN(a,b),c) and MIN(a,MAX(b,c)) appearing everywhere. We unify
   the 'clamping' with a single macro.
Note that the behavior of this CLAMP macro is different from
the combination `MAX(low,MIN(x,high))`.
* This CLAMP macro expands to two comparisons instead of three from
  MAX and MIN combination. In theory, this makes the code slightly
  smaller, in case that (low) or (high) or both are computed at
  runtime, so that compilers cannot optimize them. (The third
  comparison will matter if (low)>(high); see below.)
* CLAMP has a side effect, that if (low)>(high) it will produce weird
  results. Unlike MIN & MAX which will force either (low) or (high) to
  win. No assertion of ((low)<=(high)) is done in this macro, for now.

This CLAMP macro is implemented like described in glib
<http://developer.gnome.org/glib/stable/glib-Standard-Macros.html>
and does not handle weird uses like CLAMP(a++, low++, high--) .
2016-01-15 20:26:01 +08:00
Hisham Muhammad c6ca311d18 Present IO-Wait as a dot in monochrome. Fixes #345.
Thank you @Explorer09 for the report!
2016-01-11 20:38:10 -02:00
Hisham Muhammad d34645f8f1 Array entries have been oddly flipped here for years. 2015-11-23 03:46:43 -02:00
Christian Hesse bf456972b7 kilobytes is the smallest unit and never has precision
Signed-off-by: Christian Hesse <mail@eworm.de>
2015-08-29 21:22:46 +02:00
Hisham Muhammad bdadd45a88 Fix indentation. 2015-08-27 21:37:06 -03:00
Hisham Muhammad f585fc9825 Merge pull request #208 from eworm-de/dynamic-unit
Dynamic unit
2015-08-27 17:33:24 -03:00
Christian Hesse 6f58fbc5dd make units more dynamic
Signed-off-by: Christian Hesse <mail@eworm.de>
2015-08-27 06:13:27 +02:00
Christian Hesse 93b811a051 use ASCII blank even for graphical meter in UTF-8 mode
If the terminal has no font with braille characters we see... Nothing
useful. Use an ASCII blank at least, so we have an idea about what's
going on.
2015-08-25 17:40:36 +02:00
Hisham Muhammad 4597014ea3 Standardize variable name. 2015-08-20 01:27:07 -03:00
Christian Hesse a2a34e89a1 simplify Meter loop
* Use MIN() and MAX() to make sure values are inside bounds. This should
  fix an issue where Meters were missing dots at the bottom.
* Remove variable 'level' and calculate on the fly.
2015-08-19 22:42:34 +02:00
Christian Hesse d8e23bb084 remove UTF-8 code when compiling with --disable-unicode 2015-08-19 22:42:34 +02:00
Christian Hesse 9e67b6585e make arrays one dimensional
With more dimensional arrays we have to define the array size. Use
one dimensional arrays to be more flexible.
Additionally this allows to shrink array size for ASCII.
2015-08-19 22:42:34 +02:00
David Hunt 5e602f18d5 Rename String to StringUtils.
Fixes building on case-insensitive filesystems where String.h gets confused with <string.h>.

From d734dacea0a10d0465dad4e95b3421511e7da112 Mon Sep 17 00:00:00 2001
From: David Hunt <dhunt@iolanthe.attlocal.net>
Date: Sat, 11 Jul 2015 20:56:31 -0500
Subject: [PATCH 1/8] Rename String to StringUtils
2015-08-19 13:45:20 -03:00
Hisham Muhammad 9ff5d2b243 Fix saving of header states, motion in Setup screen. 2015-03-16 23:01:21 -03:00
Hisham Muhammad 14a177800b Remove spurious UTF-8 char from ASCII mode. 2015-03-16 22:58:56 -03:00
Hisham Muhammad 574c3decb5 Move graph according to configured CRT_delay. 2015-02-04 11:42:54 -02:00
Hisham Muhammad 14bd77c5f4 Add longer descriptions to available meters. 2015-02-03 22:31:44 +01:00
Hisham Muhammad c2108e5a48 Another mega-patch for the refactoring process.
Kinda runs, but functionality from the original main loop
is still missing. Patience.
2015-01-23 03:08:21 -02:00
Hisham Muhammad 3383d8e556 Sorry about the mega-patch.
This is a work-in-progress, code is currently broken.
(Some actions, and notably, the header, are missing.)
2015-01-21 23:27:31 -02:00
Hisham Muhammad 357e7a3243 Move UptimeMeter into platform-dependent area.
Set up environment to move other meters.
2014-11-27 19:18:14 -02:00
Hisham Muhammad 2bf8754bc2 Remove useless assignment. 2014-04-21 18:59:52 -03:00
Hisham Muhammad 6d90e58c01 alignment improvements 2014-02-27 16:35:22 -03:00
Hisham Muhammad 76a715ee8c Fix order of calloc arguments.
(Patch by Dawid Gajownik)
2014-01-16 18:51:16 -02:00
Hisham Muhammad c1e0f6e17c BUGFIX: Fix crash when adding meters and toggling detailed CPU time.
See https://bugzilla.redhat.com/show_bug.cgi?id=987805 for details.
(thanks to Dawid Gajownik for the detailed analysis!)
2014-01-16 01:40:47 -02:00
Hisham Muhammad 00b324bfc1 Changes in object model: separate class objects to store vtable. Also, nicer UTF-8 display of big numbers. 2012-12-05 15:12:20 +00:00
Hisham Muhammad 45f7a4fc8d Remove old memory debugging routines. We have Valgrind nowadays. 2011-12-26 22:04:29 +00:00
Hisham Muhammad 84281bdc44 major header cleanup 2011-12-26 21:35:57 +00:00
Hisham Muhammad 7ca1081712 Mega-commit with features and tweaks for 1.0:
* Performance improvements
* Support for splitting CPU meters into two or four columns
  (thanks to Wim Heirman)
* Switch from PLPA, which is now deprecated, to HWLOC.
* Bring back support for native Linux sched_setaffinity,
  so we don't have to use HWLOC where we don't need to.
* Support for typing in user names and column fields in selection panels.
2011-11-18 06:08:56 +00:00
Hisham Muhammad d1b1cbc757 cleanups and fixes, thanks to cppcheck and gcc -Wextra 2011-10-25 00:05:46 +00:00
Hisham Muhammad 717758409e Fix segfault in BarMeterMode_draw() for small terminal widths 2011-08-26 20:55:09 +00:00
Hisham Muhammad 300caa076e Tempus fugit. 2011-05-26 16:35:07 +00:00
Hisham Muhammad bd459776a4 retain meter state when it is reinit'ed in the Setup screen 2011-03-31 20:24:59 +00:00