diff options
| author | Peter Hofmann <scm@uninformativ.de> | 2023-10-07 07:39:00 +0200 |
|---|---|---|
| committer | Hiltjo Posthuma <hiltjo@codemadness.org> | 2023-10-07 12:16:59 +0200 |
| commit | a6bbc0c96b0a1db804061b0db79101c6b26aec57 (patch) | |
| tree | dae05a1ddf976cf829441f717ff493e9d256abfe | |
| parent | Makefile: remove the options target (diff) | |
| download | st-a6bbc0c96b0a1db804061b0db79101c6b26aec57.tar.gz st-a6bbc0c96b0a1db804061b0db79101c6b26aec57.zip | |
Fix bounds checks of dc.col
dc.collen is the length of dc.col, not the maximum index, hence if x is
equal to dc.collen, then it's an error.
With config.def.h, the last valid index is 259, so this correctly
reports "black":
$ printf '\033]4;259;?\e\\'
260 is an invalid index and this reports garbage instead of printing an
error:
$ printf '\033]4;260;?\e\\'
| -rw-r--r-- | x.c | 4 |
1 files changed, 2 insertions, 2 deletions
| @@ -818,7 +818,7 @@ xloadcols(void) | |||
| 818 | int | 818 | int |
| 819 | xgetcolor(int x, unsigned char *r, unsigned char *g, unsigned char *b) | 819 | xgetcolor(int x, unsigned char *r, unsigned char *g, unsigned char *b) |
| 820 | { | 820 | { |
| 821 | if (!BETWEEN(x, 0, dc.collen)) | 821 | if (!BETWEEN(x, 0, dc.collen - 1)) |
| 822 | return 1; | 822 | return 1; |
| 823 | 823 | ||
| 824 | *r = dc.col[x].color.red >> 8; | 824 | *r = dc.col[x].color.red >> 8; |
| @@ -833,7 +833,7 @@ xsetcolorname(int x, const char *name) | |||
| 833 | { | 833 | { |
| 834 | Color ncolor; | 834 | Color ncolor; |
| 835 | 835 | ||
| 836 | if (!BETWEEN(x, 0, dc.collen)) | 836 | if (!BETWEEN(x, 0, dc.collen - 1)) |
| 837 | return 1; | 837 | return 1; |
| 838 | 838 | ||
| 839 | if (!xloadcolor(x, name, &ncolor)) | 839 | if (!xloadcolor(x, name, &ncolor)) |
