summaryrefslogtreecommitdiff
path: root/src/XrrMonitor.c
diff options
context:
space:
mode:
authorAlan Coopersmith <alan.coopersmith@oracle.com>2022-10-17 17:24:23 -0700
committerAlan Coopersmith <alan.coopersmith@oracle.com>2022-10-17 17:24:23 -0700
commit8710ed270fbb9ec905b906826cb09095c57003f8 (patch)
treebf5c24943bd7e3251feb084c519836194e456383 /src/XrrMonitor.c
parent684ed1b997f9e8a2fe2219524c1dea04b20a7e25 (diff)
Variable scope reductions as recommended by cppcheck
Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>
Diffstat (limited to 'src/XrrMonitor.c')
-rw-r--r--src/XrrMonitor.c12
1 files changed, 6 insertions, 6 deletions
diff --git a/src/XrrMonitor.c b/src/XrrMonitor.c
index adc5330..d9acb80 100644
--- a/src/XrrMonitor.c
+++ b/src/XrrMonitor.c
@@ -39,10 +39,8 @@ XRRGetMonitors(Display *dpy, Window window, Bool get_active, int *nmonitors)
XExtDisplayInfo *info = XRRFindDisplay(dpy);
xRRGetMonitorsReply rep;
xRRGetMonitorsReq *req;
- int nbytes, nbytesRead, rbytes;
+ int nbytes, nbytesRead;
int nmon, noutput;
- int m, o;
- char *buf, *buf_head;
xRRMonitorInfo *xmon;
CARD32 *xoutput;
XRRMonitorInfo *mon = NULL;
@@ -81,6 +79,7 @@ XRRGetMonitors(Display *dpy, Window window, Bool get_active, int *nmonitors)
nbytesRead = nmon * SIZEOF(xRRMonitorInfo) + noutput * 4;
if (nmon > 0) {
+ char *buf, *buf_head;
/*
* first we must compute how much space to allocate for
@@ -88,7 +87,8 @@ XRRGetMonitors(Display *dpy, Window window, Bool get_active, int *nmonitors)
* allocation, on cleanlyness grounds.
*/
- rbytes = nmon * sizeof (XRRMonitorInfo) + noutput * sizeof(RROutput);
+ size_t rbytes = (nmon * sizeof (XRRMonitorInfo))
+ + (noutput * sizeof(RROutput));
buf = buf_head = Xmalloc (nbytesRead);
mon = Xmalloc (rbytes);
@@ -106,7 +106,7 @@ XRRGetMonitors(Display *dpy, Window window, Bool get_active, int *nmonitors)
output = (RROutput *) (mon + nmon);
- for (m = 0; m < nmon; m++) {
+ for (int m = 0; m < nmon; m++) {
xmon = (xRRMonitorInfo *) buf;
mon[m].name = xmon->name;
mon[m].primary = xmon->primary;
@@ -129,7 +129,7 @@ XRRGetMonitors(Display *dpy, Window window, Bool get_active, int *nmonitors)
return NULL;
}
rep.noutputs -= xmon->noutput;
- for (o = 0; o < xmon->noutput; o++)
+ for (int o = 0; o < xmon->noutput; o++)
output[o] = xoutput[o];
output += xmon->noutput;
buf += xmon->noutput * 4;