summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlan Coopersmith <alan.coopersmith@oracle.com>2024-04-27 15:13:46 -0700
committerAlan Coopersmith <alan.coopersmith@oracle.com>2024-04-27 15:32:53 -0700
commita5a3e02ff607f8526403368e999c2fb58ddbecfb (patch)
tree046959875c92689bdcc1c3b605ee3a0f4111b3f7
parent75067cd1491e9bd74f1eb57936e62cbc162f2474 (diff)
Variable scope reduction as suggested by cppcheck
Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com> Part-of: <https://gitlab.freedesktop.org/xorg/app/xcmsdb/-/merge_requests/5>
-rw-r--r--loadData.c36
-rw-r--r--xcmsdb.c6
2 files changed, 20 insertions, 22 deletions
diff --git a/loadData.c b/loadData.c
index 6376ef6..128fc9e 100644
--- a/loadData.c
+++ b/loadData.c
@@ -295,13 +295,11 @@ SCScrnClassStringOf(int id)
static void
closeS(FILE *stream, XDCCC_Correction *pCorrection)
{
- XDCCC_Correction *pNext;
-
if (stream) {
fclose(stream);
}
while (pCorrection) {
- pNext = pCorrection->next;
+ XDCCC_Correction *pNext = pCorrection->next;
free(pCorrection);
pCorrection = pNext;
}
@@ -322,8 +320,7 @@ ProcessColorimetric(FILE *stream, XDCCC_Matrix *pMatrix, int VisualFlag)
{
char buf[BUFSIZ];
char keyword[BUFSIZ];
- char token[BUFSIZ], *ptoken;
- int ntok;
+ char token[BUFSIZ];
unsigned int matrices_processed = 0;
/* bit 0 for XYZtoRGB matrix */
/* bit 1 for RGBtoXYZ matrix */
@@ -336,7 +333,9 @@ ProcessColorimetric(FILE *stream, XDCCC_Matrix *pMatrix, int VisualFlag)
XcmsFloat *pElement = NULL;
while ((nextline(buf, BUFSIZ, stream)) != NULL) {
- if ((ntok = sscanf(buf, "%s %s", keyword, token)) > 0) {
+ int ntok = sscanf(buf, "%s %s", keyword, token);
+
+ if (ntok > 0) {
switch (SCKeyOf(keyword)) {
case XYZTORGBMAT_BEGIN:
if (VisualFlag != VIDEO_RGB) {
@@ -448,7 +447,7 @@ ProcessColorimetric(FILE *stream, XDCCC_Matrix *pMatrix, int VisualFlag)
break;
#endif /* GRAY */
case DATA:
- for (ptoken = strtok(buf, DATA_DELIMS); ptoken != NULL;
+ for (char *ptoken = strtok(buf, DATA_DELIMS); ptoken != NULL;
ptoken = strtok(NULL, DATA_DELIMS)) {
if (sscanf(ptoken, "%lf", pElement) != 1) {
if (VisualFlag == VIDEO_RGB) {
@@ -516,8 +515,7 @@ static int
ProcessIProfile(FILE *stream, XDCCC_Correction *pCorrection)
{
char buf[BUFSIZ];
- char *keyword;
- char *tableStr, *sizeStr, *ptoken;
+ char *tableStr, *sizeStr;
int size;
int state = 0;
/************************************************
@@ -529,7 +527,9 @@ ProcessIProfile(FILE *stream, XDCCC_Correction *pCorrection)
IntensityRec *pIRec = NULL;
while ((nextline(buf, BUFSIZ, stream)) != NULL) {
- ptoken = keyword = strtok(buf, DATA_DELIMS);
+ char *ptoken = strtok(buf, DATA_DELIMS);
+ char *keyword = ptoken;
+
if (keyword != NULL) {
switch (SCKeyOf(keyword)) {
case ITBL_BEGIN:
@@ -1133,8 +1133,6 @@ static int
LoadDataGray(Display *pDpy, window root, int tableType,
LINEAR_RGB_SCCData *pScreenData, int targetFormat)
{
- unsigned char *ret_prop;
- int count;
int nLevels;
unsigned char *pCard8;
unsigned char *pCard8Array = NULL;
@@ -1143,16 +1141,14 @@ LoadDataGray(Display *pDpy, window root, int tableType,
unsigned long *pCard32;
unsigned long *pCard32Array = NULL;
unsigned long Card32Array[18];
- int ret_format;
- unsigned long ret_len, ret_after;
- Atom MatricesAtom, CorrectAtom, ret_atom;
+ Atom MatricesAtom, CorrectAtom;
XcmsFloat *pValue;
int total;
/* Now store the XDCCC_SCREENWHITEPT */
pCard32 = Card32Array;
pValue = (XcmsFloat *) pScreenData->XYZtoRGBmatrix;
- for (count = 0; count < 3; count++) {
+ for (int count = 0; count < 3; count++) {
*pCard32++ = (unsigned long) (*pValue++ * (XcmsFloat) XDCCC_NUMBER);
}
MatricesAtom = XInternAtom(pDpy, XDCCC_SCREENWHITEPT_ATOM_NAME, False);
@@ -1163,6 +1159,11 @@ LoadDataGray(Display *pDpy, window root, int tableType,
CorrectAtom = XInternAtom(pDpy, XDCCC_GRAY_CORRECT_ATOM_NAME, False);
if (tableType == CORR_TYPE_NONE) {
+ unsigned char *ret_prop;
+ Atom ret_atom;
+ int ret_format;
+ unsigned long ret_len, ret_after;
+
XGetWindowProperty(pDpy, root, CorrectAtom,
0, 5, False, XA_INTEGER,
&ret_atom, &ret_format, &ret_len, &ret_after,
@@ -1300,7 +1301,6 @@ static int
ParseVisualOptions(Display *pDpy, XDCCC_Correction *pCorrection, char *pbuf)
{
char *key;
- char *value;
XVisualInfo *vinfo;
int n_matches;
const char *delims = DATA_DELIMS ":";
@@ -1309,8 +1309,8 @@ ParseVisualOptions(Display *pDpy, XDCCC_Correction *pCorrection, char *pbuf)
key = strtok(pbuf, delims);
do {
long tmp;
+ char *value = strtok(NULL, delims);
- value = strtok(NULL, delims);
if ((key == NULL) || (value == NULL)) {
return (0);
}
diff --git a/xcmsdb.c b/xcmsdb.c
index 45f852f..0f6e74b 100644
--- a/xcmsdb.c
+++ b/xcmsdb.c
@@ -108,7 +108,6 @@ int
main(int argc, char *argv[])
{
Display *dpy;
- int i;
char *displayname = NULL;
char *filename = NULL;
int query = 0;
@@ -119,7 +118,7 @@ main(int argc, char *argv[])
ProgramName = argv[0];
- for (i = 1; i < argc; i++) {
+ for (int i = 1; i < argc; i++) {
char *arg = argv[i];
if (arg[0] == '-') {
@@ -575,7 +574,6 @@ QuerySCCDataGray(Display * dpy, Window root)
*/
{
char *property_return, *pChar;
- int j;
int count, format, cType;
unsigned long nitems, nbytes_return;
Atom MatricesAtom, CorrectAtom;
@@ -604,7 +602,7 @@ QuerySCCDataGray(Display * dpy, Window root)
printf("\nQuerying property %s\n", XDCCC_SCREENWHITEPT_ATOM_NAME);
printf("\tWhite Point XYZ :\n");
printf("\t");
- for (j = 0; j < 3; j++) {
+ for (int j = 0; j < 3; j++) {
printf("\t%8.5lf",
(long) _XcmsGetElement(format, &pChar, &nitems) /
(XcmsFloat) XDCCC_NUMBER);