aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBoris Faure <billiob@gmail.com>2018-12-24 01:37:53 +0100
committerBoris Faure <billiob@gmail.com>2018-12-27 22:14:44 +0100
commitc162b07b1697685e893d67323a80d38bbc7c1d18 (patch)
tree1051fb80761041f7766a49d9f86af635e564d9da
parentREADME: add codecov's badge (diff)
downloadterminology-c162b07b1697685e893d67323a80d38bbc7c1d18.tar.gz
col: assert in case of invalid values
-rw-r--r--src/bin/col.c29
1 files changed, 12 insertions, 17 deletions
diff --git a/src/bin/col.c b/src/bin/col.c
index 8b1da89..ae6a518 100644
--- a/src/bin/col.c
+++ b/src/bin/col.c
@@ -1,4 +1,5 @@
#include "private.h"
+#include <assert.h>
#include <Elementary.h>
#include "config.h"
#include "col.h"
@@ -88,7 +89,7 @@ static const Color default_colors256[256] =
{ 0xc0, 0x00, 0xc0, 0xff }, // COL_MAGENTA
{ 0x00, 0xc0, 0xc0, 0xff }, // COL_CYAN
{ 0xc0, 0xc0, 0xc0, 0xff }, // COL_WHITE
-
+
{ 0x80, 0x80, 0x80, 0xff }, // COL_BLACK
{ 0xff, 0x80, 0x80, 0xff }, // COL_RED
{ 0x80, 0xff, 0x80, 0xff }, // COL_GREEN
@@ -498,22 +499,15 @@ colors_standard_get(int set, int col,
unsigned char *b,
unsigned char *a)
{
- if ((set >= 0) && (set < 4))
- {
- int s1, s2;
-
- s1 = set / 2;
- s2 = set % 2;
- *r = default_colors[s1][s2][col].r;
- *g = default_colors[s1][s2][col].g;
- *b = default_colors[s1][s2][col].b;
- *a = default_colors[s1][s2][col].a;
- return;
- }
- *r = 0;
- *g = 0;
- *b = 0;
- *a = 0;
+ int s1, s2;
+ assert((set >= 0) && (set < 4));
+
+ s1 = set / 2;
+ s2 = set % 2;
+ *r = default_colors[s1][s2][col].r;
+ *g = default_colors[s1][s2][col].g;
+ *b = default_colors[s1][s2][col].b;
+ *a = default_colors[s1][s2][col].a;
}
void
@@ -523,6 +517,7 @@ colors_256_get(int col,
unsigned char *b,
unsigned char *a)
{
+ assert(col < 256);
*r = default_colors256[col].r;
*g = default_colors256[col].g;
*b = default_colors256[col].b;