Skip to content

Commit 59e32bb

Browse files
carlpittfaf0
andauthored
Fix cppcheck style warnings (#40)
Co-authored-by: Fabian Foerg <[email protected]>
1 parent 2d4dff2 commit 59e32bb

File tree

2 files changed

+9
-10
lines changed

2 files changed

+9
-10
lines changed

src/xsct.c

+8-9
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
#include "xsct.h"
88

9-
static void usage(char * pname)
9+
static void usage(const char *const pname)
1010
{
1111
printf("Xsct (%s)\n"
1212
"Usage: %s [options] [temperature] [brightness]\n"
@@ -23,7 +23,7 @@ static void usage(char * pname)
2323

2424
static double DoubleTrim(double x, double a, double b)
2525
{
26-
double buff[3] = {a, x, b};
26+
const double buff[3] = {a, x, b};
2727
return buff[ (int)(x > a) + (int)(x > b) ];
2828
}
2929

@@ -34,10 +34,9 @@ static struct temp_status get_sct_for_screen(Display *dpy, int screen, int icrtc
3434

3535
int n, c;
3636
double t = 0.0;
37-
double gammar = 0.0, gammag = 0.0, gammab = 0.0, gammad = 0.0;
37+
double gammar = 0.0, gammag = 0.0, gammab = 0.0;
3838
struct temp_status temp;
3939
temp.temp = 0;
40-
temp.brightness = 1.0;
4140

4241
n = res->ncrtc;
4342
if ((icrtc >= 0) && (icrtc < n))
@@ -70,7 +69,7 @@ static struct temp_status get_sct_for_screen(Display *dpy, int screen, int icrtc
7069
temp.brightness /= BRIGHTHESS_DIV;
7170
temp.brightness = DoubleTrim(temp.brightness, 0.0, 1.0);
7271
if (fdebug > 0) fprintf(stderr, "DEBUG: Gamma: %f, %f, %f, brightness: %f\n", gammar, gammag, gammab, temp.brightness);
73-
gammad = gammab - gammar;
72+
const double gammad = gammab - gammar;
7473
if (gammad < 0.0)
7574
{
7675
if (gammab > 0.0)
@@ -97,7 +96,7 @@ static struct temp_status get_sct_for_screen(Display *dpy, int screen, int icrtc
9796

9897
static void sct_for_screen(Display *dpy, int screen, int icrtc, struct temp_status temp, int fdebug)
9998
{
100-
double t = 0.0, b = 1.0, g = 0.0, gammar, gammag, gammab;
99+
double t = 0.0, b = 1.0, gammar, gammag, gammab;
101100
int n, c;
102101
Window root = RootWindow(dpy, screen);
103102
XRRScreenResources *res = XRRGetScreenResourcesCurrent(dpy, root);
@@ -109,7 +108,7 @@ static void sct_for_screen(Display *dpy, int screen, int icrtc, struct temp_stat
109108
gammar = 1.0;
110109
if (temp.temp > TEMPERATURE_ZERO)
111110
{
112-
g = log(t - TEMPERATURE_ZERO);
111+
const double g = log(t - TEMPERATURE_ZERO);
113112
gammag = DoubleTrim(GAMMA_K0GR + GAMMA_K1GR * g, 0.0, 1.0);
114113
gammab = DoubleTrim(GAMMA_K0BR + GAMMA_K1BR * g, 0.0, 1.0);
115114
}
@@ -121,7 +120,7 @@ static void sct_for_screen(Display *dpy, int screen, int icrtc, struct temp_stat
121120
}
122121
else
123122
{
124-
g = log(t - (TEMPERATURE_NORM - TEMPERATURE_ZERO));
123+
const double g = log(t - (TEMPERATURE_NORM - TEMPERATURE_ZERO));
125124
gammar = DoubleTrim(GAMMA_K0RB + GAMMA_K1RB * g, 0.0, 1.0);
126125
gammag = DoubleTrim(GAMMA_K0GB + GAMMA_K1GB * g, 0.0, 1.0);
127126
gammab = 1.0;
@@ -144,7 +143,7 @@ static void sct_for_screen(Display *dpy, int screen, int icrtc, struct temp_stat
144143

145144
for (i = 0; i < size; i++)
146145
{
147-
g = GAMMA_MULT * b * (double)i / (double)size;
146+
const double g = GAMMA_MULT * b * (double)i / (double)size;
148147
crtc_gamma->red[i] = (unsigned short int)(g * gammar + 0.5);
149148
crtc_gamma->green[i] = (unsigned short int)(g * gammag + 0.5);
150149
crtc_gamma->blue[i] = (unsigned short int)(g * gammab + 0.5);

src/xsct.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ struct temp_status
5050
double brightness;
5151
};
5252

53-
static void usage(char * pname);
53+
static void usage(const char *const pname);
5454
static double DoubleTrim(double x, double a, double b);
5555
static struct temp_status get_sct_for_screen(Display *dpy, int screen, int icrtc, int fdebug);
5656
static void sct_for_screen(Display *dpy, int screen, int icrtc, struct temp_status temp, int fdebug);

0 commit comments

Comments
 (0)