[hackers] [st][PATCH 12/24] fix remaining cppcheck warnings: reduce scope of some variables, and avoid compiling selcheck_ when it's not used, by adding a new setting in config.h

From: Oliver Galvin <odg_AT_riseup.net>
Date: Mon, 21 Jan 2019 23:56:27 +0000

---
 x.c | 32 ++++++++++++++++++--------------
 1 file changed, 18 insertions(+), 14 deletions(-)
diff --git a/x.c b/x.c
index ed734e2..de9ec5d 100644
--- a/x.c
+++ b/x.c
_AT_@ -164,7 +164,9 @@ static void bpress(XEvent *);
 static void bmotion(XEvent *);
 static void propnotify(XEvent *);
 static void selnotify(XEvent *);
+#if SELCLEAR != 0
 static void selclear_(XEvent *);
+#endif
 static void selrequest(XEvent *);
 static void setsel(char *, Time);
 static void mousesel(XEvent *, int);
_AT_@ -188,10 +190,12 @@ static void (*handler[LASTEvent])(XEvent *) = {
 	[ButtonPress] = bpress,
 	[ButtonRelease] = brelease,
 /*
- * Uncomment if you want the selection to disappear when you select something
+ * set when you want the selection to disappear when you select something
  * different in another window.
  */
-/*	[SelectionClear] = selclear_, */
+#if SELCLEAR != 0
+	[SelectionClear] = selclear_,
+#endif
 	[SelectionNotify] = selnotify,
 /*
  * PropertyNotify is only turned on when there is some INCR transfer happening
_AT_@ -408,7 +412,6 @@ bpress(XEvent *e)
 {
 	struct timespec now;
 	MouseShortcut *ms;
-	int snap;
 
 	if (IS_SET(MODE_MOUSE) && !(e->xbutton.state & forceselmod)) {
 		mousereport(e);
_AT_@ -428,6 +431,8 @@ bpress(XEvent *e)
 		 * If the user clicks below predefined timeouts specific
 		 * snapping behaviour is exposed.
 		 */
+		int snap;
+
 		clock_gettime(CLOCK_MONOTONIC, &now);
 		if (TIMEDIFF(now, xsel.tclick2) <= tripleclicktimeout) {
 			snap = SNAP_LINE;
_AT_@ -550,11 +555,13 @@ xclipcopy(void)
 	clipcopy(NULL);
 }
 
-void UNUSED
+#if SELCLEAR != 0
+void
 selclear_(UNUSED XEvent *e)
 {
 	selclear();
 }
+#endif
 
 void
 selrequest(XEvent *e)
_AT_@ -728,19 +735,19 @@ xloadcolor(size_t i, const char *name, Color *ncolor)
 void
 xloadcols(void)
 {
-	size_t i;
 	static int loaded;
-	Color *cp;
 
 	dc.collen = MAX(LEN(colorname), 256);
 	dc.col = xmalloc(dc.collen * sizeof(Color));
 
 	if (loaded) {
+		Color *cp;
+
 		for (cp = dc.col; cp < &dc.col[dc.collen]; ++cp)
 			XftColorFree(xw.dpy, xw.vis, xw.cmap, cp);
 	}
 
-	for (i = 0; i < dc.collen; i++)
+	for (size_t i = 0; i < dc.collen; i++)
 		if (!xloadcolor(i, NULL, &dc.col[i])) {
 			if (colorname[i])
 				die("could not allocate color '%s'\n", colorname[i]);
_AT_@ -1123,11 +1130,10 @@ int
 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;
+	ushort prevmode = USHRT_MAX;
 	Font *dcfont = &dc.font;
 	int frcflags = FRC_NORMAL;
 	float runewidth = win.cw;
-	Rune rune;
 	FT_UInt glyphidx;
 	FcResult fcres;
 	FcPattern *fcpattern, *fontpattern;
_AT_@ -1137,8 +1143,8 @@ xmakeglyphfontspecs(XftGlyphFontSpec *specs, const Glyph *glyphs, size_t len, in
 
 	for (i = 0, xp = winx, yp = winy + dcfont->ascent; i < len; ++i) {
 		/* Fetch rune and mode for current glyph. */
-		rune = glyphs[i].u;
-		mode = glyphs[i].mode;
+		Rune rune = glyphs[i].u;
+		ushort mode = glyphs[i].mode;
 
 		/* Skip dummy wide-character spacing. */
 		if (mode == ATTR_WDUMMY)
_AT_@ -1692,7 +1698,6 @@ kpress(XEvent *ev)
 	char buf[32];
 	const char *customkey;
 	int len;
-	Rune c;
 	Status status;
 	Shortcut *bp;
 
_AT_@ -1720,8 +1725,7 @@ kpress(XEvent *ev)
 	if (len == 1 && e->state & Mod1Mask) {
 		if (IS_SET(MODE_8BIT)) {
 			if (*buf < 0177) {
-				c = *buf | 0x80;
-				len = utf8encode(c, buf);
+				len = utf8encode(*buf | 0x80, buf);
 			}
 		} else {
 			buf[1] = buf[0];
-- 
2.20.1
Received on Tue Jan 22 2019 - 00:56:27 CET

This archive was generated by hypermail 2.3.0 : Tue Jan 22 2019 - 01:00:23 CET