---
st.c | 37 ++++++++++++++++++++-----------------
win.h | 2 +-
x.c | 26 +++++++++++++-------------
3 files changed, 34 insertions(+), 31 deletions(-)
diff --git a/st.c b/st.c
index 112864e..30406fa 100644
--- a/st.c
+++ b/st.c
@@ -134,7 +134,7 @@ typedef struct {
/* ESC '[' [[ [<priv>] <arg> [;]] <mode> [<mode>]] */
typedef struct {
char buf[ESC_BUF_SIZ]; /* raw string */
- int len; /* raw string length */
+ size_t len; /* raw string length */
char priv;
int arg[ESC_ARG_SIZ];
int narg; /* nb of args */
@@ -146,7 +146,7 @@ typedef struct {
typedef struct {
char type; /* ESC type ... */
char buf[STR_BUF_SIZ]; /* raw string */
- int len; /* raw string length */
+ size_t len; /* raw string length */
char *args[STR_ARG_SIZ];
int narg; /* nb of args */
} STREscape;
@@ -191,7 +191,7 @@ static void tsetdirt(int, int);
static void tsetscroll(int, int);
static void tswapscreen(void);
static void tsetmode(int, int, int *, int);
-static int twrite(const char *, int, int);
+static size_t twrite(const char *, size_t, int);
static void tfulldirt(void);
static void tcontrolcode(uchar );
static void tdectest(char );
@@ -824,8 +824,8 @@ size_t
ttyread(void)
{
static char buf[BUFSIZ];
- static int buflen = 0;
- int written;
+ static size_t buflen = 0;
+ size_t written;
int ret;
/* append read bytes to unprocessed bytes */
@@ -903,7 +903,7 @@ ttywriteraw(const char *s, size_t n)
*/
if ((r = write(cmdfd, s, (n < lim)? n : lim)) < 0)
goto write_error;
- if (r < n) {
+ if ((size_t)r < n) {
/*
* We weren't able to write out everything.
* This means the buffer is getting full
@@ -1012,7 +1012,7 @@ tcursor(int mode)
void
treset(void)
{
- uint i;
+ int i;
term.c = (TCursor){{
.mode = ATTR_NULL,
@@ -1811,7 +1811,7 @@ void
csidump(void)
{
fprintf(stderr, "ESC[");
- for (int i = 0; i < csiescseq.len; i++) {
+ for (size_t i = 0; i < csiescseq.len; i++) {
uint c = csiescseq.buf[i] & 0xff;
if (isprint(c)) {
putc(c, stderr);
@@ -1838,7 +1838,8 @@ void
strhandle(void)
{
char *p = NULL;
- int j, narg, par;
+ int narg, par;
+ size_t j;
term.esc &= ~(ESC_STR_END|ESC_STR);
strparse();
@@ -1872,8 +1873,9 @@ strhandle(void)
p = strescseq.args[2];
/* FALLTHROUGH */
case 104: /* color reset, here p = NULL */
- j = (narg > 1) ? atoi(strescseq.args[1]) : -1;
- if (xsetcolorname(j, p)) {
+ if (narg > 1) {
+ j = strtoul(strescseq.args[1], NULL, 10);
+ } else if (narg <= 1 || xsetcolorname(j, p)) {
fprintf(stderr, "erresc: invalid color %s\n",
p);
} else {
/*
@@ -1925,7 +1927,7 @@ void
strdump(void)
{
fprintf(stderr, "ESC%c", strescseq.type);
- for (int i = 0; i < strescseq.len; i++) {
+ for (size_t i = 0; i < strescseq.len; i++) {
uint c = strescseq.buf[i] & 0xff;
if (c == '\0') {
putc('\n', stderr);
@@ -2024,7 +2026,7 @@ tdump(void)
void
tputtab(int n)
{
- uint x = term.c.x;
+ int x = term.c.x;
if (n > 0) {
while (x < term.col && n--)
@@ -2285,7 +2287,8 @@ tputc(Rune u)
{
char c[UTF_SIZ];
int control = ISCONTROL(u);;
- int width = 1, len = 1;
+ int width = 1;
+ size_t len = 1;
Glyph *gp;
if (!IS_SET(MODE_UTF8) && !IS_SET(MODE_SIXEL)) {
@@ -2425,12 +2428,12 @@ check_control_code:
}
}
-int
-twrite(const char *buf, int buflen, int show_ctrl)
+size_t
+twrite(const char *buf, size_t buflen, int show_ctrl)
{
int charsize;
Rune u;
- int n;
+ size_t n;
for (n = 0; n < buflen; n += charsize) {
if (IS_SET(MODE_UTF8) && !IS_SET(MODE_SIXEL)) {
diff --git a/win.h b/win.h
index 31f327d..867cd54 100644
--- a/win.h
+++ b/win.h
@@ -29,7 +29,7 @@ void xdrawcursor(int, int, Glyph, int, int, Glyph);
void xdrawline(Line, int, int, int);
void xfinishdraw(void);
void xloadcols(void);
-int xsetcolorname(int, const char *);
+int xsetcolorname(size_t, const char *);
void xsettitle(char *);
int xsetcursor(int);
void xsetmode(int, unsigned int);
diff --git a/x.c b/x.c
index da6b1e6..b3cba01 100644
--- a/x.c
+++ b/x.c
@@ -134,7 +134,7 @@ typedef struct {
} DC;
static inline ushort sixd_to_16bit(int);
-static int xmakeglyphfontspecs(XftGlyphFontSpec *, const Glyph *, int, int,
int);
+static int xmakeglyphfontspecs(XftGlyphFontSpec *, const Glyph *, size_t, int,
int);
static void xdrawglyphfontspecs(const XftGlyphFontSpec *, Glyph, int, int,
int);
static void xdrawglyph(Glyph, int, int);
static void xclear(int, int, int, int);
@@ -143,7 +143,7 @@ static void xinit(int, int);
static void cresize(int, int);
static void xresize(int, int);
static void xhints(void);
-static int xloadcolor(int, const char *, Color *);
+static int xloadcolor(size_t, const char *, Color *);
static int xloadfont(Font *, FcPattern *);
static void xloadfonts(const char *, double);
static void xunloadfont(Font *);
@@ -224,7 +224,7 @@ typedef struct {
/* Fontcache is an array now. A new font will be appended to the array. */
static Fontcache frc[16];
-static int frclen = 0;
+static size_t frclen = 0;
static const char *usedfont = NULL;
static double usedfontsize = 0;
static double defaultfontsize = 0;
@@ -327,7 +327,7 @@ evrow(XEvent *e)
void
mousesel(XEvent *e, int done)
{
- int type, seltype = SEL_REGULAR;
+ size_t type, seltype = SEL_REGULAR;
uint state = e->xbutton.state & ~(Button1Mask | forceselmod);
for (type = 1; type < LEN(selmasks); ++type) {
@@ -703,7 +703,7 @@ sixd_to_16bit(int x)
}
int
-xloadcolor(int i, const char *name, Color *ncolor)
+xloadcolor(size_t i, const char *name, Color *ncolor)
{
XRenderColor color = { .alpha = 0xffff };
@@ -729,7 +729,7 @@ xloadcolor(int i, const char *name, Color *ncolor)
void
xloadcols(void)
{
- int i;
+ size_t i;
static int loaded;
Color *cp;
@@ -752,11 +752,11 @@ xloadcols(void)
}
int
-xsetcolorname(int x, const char *name)
+xsetcolorname(size_t x, const char *name)
{
Color ncolor;
- if (!BETWEEN(x, 0, dc.collen))
+ if (x < dc.collen)
return 1;
@@ -1121,7 +1121,7 @@ xinit(int cols, int rows)
}
int
-xmakeglyphfontspecs(XftGlyphFontSpec *specs, const Glyph *glyphs, int len, int
x, int y)
+xmakeglyphfontspecs(XftGlyphFontSpec *specs, const Glyph *glyphs, size_t len,
int x, int y)
{
float winx = borderpx + x * win.cw, winy = borderpx + y * win.ch, xp,
yp;
ushort mode, prevmode = USHRT_MAX;
@@ -1134,7 +1134,7 @@ xmakeglyphfontspecs(XftGlyphFontSpec *specs, const Glyph
*glyphs, int len, int x
FcPattern *fcpattern, *fontpattern;
FcFontSet *fcsets[] = { NULL };
FcCharSet *fccharset;
- int i, f, numspecs = 0;
+ size_t i, f, numspecs = 0;
for (i = 0, xp = winx, yp = winy + font->ascent; i < len; ++i) {
/* Fetch rune and mode for current glyph. */
@@ -1297,7 +1297,7 @@ xdrawglyphfontspecs(const XftGlyphFontSpec *specs, Glyph
base, int len, int x, i
}
/* Change basic system colors [0-7] to bright system colors [8-15] */
- if ((base.mode & ATTR_BOLD_FAINT) == ATTR_BOLD && BETWEEN(base.fg, 0,
7))
+ if ((base.mode & ATTR_BOLD_FAINT) == ATTR_BOLD && base.fg <= 7)
fg = &dc.col[base.fg + 8];
if (IS_SET(MODE_REVERSE)) {
@@ -1652,7 +1652,7 @@ const char*
kmap(KeySym k, uint state)
{
Key *kp;
- int i;
+ size_t i;
/* Check for mapped keys out of X11 function keys. */
for (i = 0; i < LEN(mappedkeys); i++) {
@@ -1748,7 +1748,7 @@ cmessage(XEvent *e)
} else if (e->xclient.data.l[1] == XEMBED_FOCUS_OUT) {
win.mode &= ~MODE_FOCUSED;
}
- } else if (e->xclient.data.l[0] == xw.wmdeletewin) {
+ } else if (e->xclient.data.l[0] >= 0 && labs(e->xclient.data.l[0]) ==
xw.wmdeletewin) {
ttyhangup();
exit(0);
}
--
2.20.1