diff options
author | Alan Coopersmith <alan.coopersmith@oracle.com> | 2022-04-30 11:31:33 -0700 |
---|---|---|
committer | Alan Coopersmith <alan.coopersmith@oracle.com> | 2022-04-30 11:32:17 -0700 |
commit | 6ff9e623b48a8998324a75ebaadb6adc97b189ae (patch) | |
tree | b93910d951afb5713a6a63d74ccde3bc40ccde36 | |
parent | 54b7f6247be611d1f357220a59be05322d78998a (diff) |
Remove unnecessary casts and make allocation failure checks more consistent
Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>
-rw-r--r-- | loadData.c | 135 | ||||
-rw-r--r-- | xcmsdb.c | 8 |
2 files changed, 70 insertions, 73 deletions
@@ -530,7 +530,7 @@ ProcessIProfile(FILE *stream, XDCCC_Correction *pCorrection) while ((nextline(buf, BUFSIZ, stream)) != NULL) { ptoken = keyword = strtok(buf, DATA_DELIMS); - if (keyword != (char *) NULL) { + if (keyword != NULL) { switch (SCKeyOf(keyword)) { case ITBL_BEGIN: if (state != 0) { @@ -538,9 +538,9 @@ ProcessIProfile(FILE *stream, XDCCC_Correction *pCorrection) linenum, keyword); return (0); } - tableStr = strtok((char *) NULL, DATA_DELIMS); - sizeStr = strtok((char *) NULL, DATA_DELIMS); - if ((sizeStr == (char *) NULL) || + tableStr = strtok(NULL, DATA_DELIMS); + sizeStr = strtok(NULL, DATA_DELIMS); + if ((sizeStr == NULL) || sscanf(sizeStr, "%d", &size) != 1) { fprintf(stderr, "Line %d: invalid Intensity Table size, %s.\n", @@ -567,8 +567,8 @@ ProcessIProfile(FILE *stream, XDCCC_Correction *pCorrection) } pCorrection->pGreenTbl->nEntries = size; pCorrection->pGreenTbl->pBase = - (IntensityRec *) calloc(size, sizeof(IntensityRec)); - if (!pCorrection->pGreenTbl->pBase) { + calloc(size, sizeof(IntensityRec)); + if (pCorrection->pGreenTbl->pBase == NULL) { fprintf(stderr, "Line %d: Unable to allocate space for GREEN Intensity Profile\n", linenum); @@ -591,8 +591,8 @@ ProcessIProfile(FILE *stream, XDCCC_Correction *pCorrection) } pCorrection->pBlueTbl->nEntries = size; pCorrection->pBlueTbl->pBase = - (IntensityRec *) calloc(size, sizeof(IntensityRec)); - if (!pCorrection->pBlueTbl->pBase) { + calloc(size, sizeof(IntensityRec)); + if (pCorrection->pBlueTbl->pBase == NULL) { fprintf(stderr, "Line %d: Unable to allocate space for BLUE Intensity Profile\n", linenum); @@ -615,8 +615,8 @@ ProcessIProfile(FILE *stream, XDCCC_Correction *pCorrection) } pCorrection->pRedTbl->nEntries = size; pCorrection->pRedTbl->pBase = - (IntensityRec *) calloc(size, sizeof(IntensityRec)); - if (!pCorrection->pRedTbl->pBase) { + calloc(size, sizeof(IntensityRec)); + if (pCorrection->pRedTbl->pBase == NULL) { fprintf(stderr, "Line %d: Unable to allocate space for intensity table\n", linenum); @@ -854,11 +854,11 @@ LoadCorrections(Display *pDpy, Window root, XDCCC_Correction *pCorrection, int targetFormat) { unsigned char *pCard8; - unsigned char *pCard8Array = (unsigned char *) NULL; + unsigned char *pCard8Array = NULL; unsigned short *pCard16; - unsigned short *pCard16Array = (unsigned short *) NULL; + unsigned short *pCard16Array = NULL; unsigned long *pCard32; - unsigned long *pCard32Array = (unsigned long *) NULL; + unsigned long *pCard32Array = NULL; Atom CorrectAtom; int total; int i; @@ -916,8 +916,8 @@ LoadCorrections(Display *pDpy, Window root, XDCCC_Correction *pCorrection, case 8: total = 7 + (pCorrection->pRedTbl->nEntries * (pCorrection->tableType == 0 ? 2 : 1)); - if ((pCard8 = pCard8Array = (unsigned char *) - calloc(total, sizeof(unsigned char))) == NULL) { + pCard8 = pCard8Array = calloc(total, sizeof(unsigned char)); + if (pCard8 == NULL) { fprintf(stderr, "Unable allocate array of ints\n"); return (0); } @@ -941,8 +941,8 @@ LoadCorrections(Display *pDpy, Window root, XDCCC_Correction *pCorrection, case 16: total = 5 + (pCorrection->pRedTbl->nEntries * (pCorrection->tableType == 0 ? 2 : 1)); - if ((pCard16 = pCard16Array = (unsigned short *) - calloc(total, sizeof (unsigned short))) == NULL) { + pCard16 = pCard16Array = calloc(total, sizeof (unsigned short)); + if (pCard16 == NULL) { fprintf(stderr, "Unable allocate array of ints\n"); return (0); } @@ -964,9 +964,8 @@ LoadCorrections(Display *pDpy, Window root, XDCCC_Correction *pCorrection, case 32: total = 4 + (pCorrection->pRedTbl->nEntries * (pCorrection->tableType == 0 ? 2 : 1)); - if ((pCard32 = pCard32Array = - (unsigned long *) calloc(total, - sizeof(unsigned long))) == NULL) { + pCard32 = pCard32Array = calloc(total, sizeof(unsigned long)); + if (pCard32 == NULL) { fprintf(stderr, "Unable allocate array of ints\n"); return (0); } @@ -1021,9 +1020,8 @@ LoadCorrections(Display *pDpy, Window root, XDCCC_Correction *pCorrection, (pCorrection->tableType == 0 ? 2 : 1)) + (pCorrection->pBlueTbl->nEntries * (pCorrection->tableType == 0 ? 2 : 1)); - if ((pCard8 = pCard8Array = - (unsigned char *) calloc(total, - sizeof(unsigned char))) == NULL) { + pCard8 = pCard8Array = calloc(total, sizeof(unsigned char)); + if (pCard8 == NULL) { fprintf(stderr, "Unable allocate array of ints\n"); return (0); } @@ -1056,8 +1054,8 @@ LoadCorrections(Display *pDpy, Window root, XDCCC_Correction *pCorrection, (pCorrection->tableType == 0 ? 2 : 1)) + (pCorrection->pBlueTbl->nEntries * (pCorrection->tableType == 0 ? 2 : 1)); - if ((pCard16 = pCard16Array = (unsigned short *) - calloc(total, sizeof(unsigned short))) == NULL) { + pCard16 = pCard16Array = calloc(total, sizeof(unsigned short)); + if (pCard16 == NULL) { fprintf(stderr, "Unable allocate array of ints\n"); return (0); } @@ -1088,8 +1086,8 @@ LoadCorrections(Display *pDpy, Window root, XDCCC_Correction *pCorrection, (pCorrection->tableType == 0 ? 2 : 1)) + (pCorrection->pBlueTbl->nEntries * (pCorrection->tableType == 0 ? 2 : 1)); - if ((pCard32 = pCard32Array = (unsigned long *) - calloc(total, sizeof(unsigned long))) == NULL) { + pCard32 = pCard32Array = calloc(total, sizeof(unsigned long)); + if (pCard32 == NULL) { fprintf(stderr, "Unable allocate array of ints\n"); return (0); } @@ -1139,11 +1137,11 @@ LoadDataGray(Display *pDpy, window root, int tableType, int count; int nLevels; unsigned char *pCard8; - unsigned char *pCard8Array = (unsigned char *) NULL; + unsigned char *pCard8Array = NULL; unsigned short *pCard16; - unsigned short *pCard16Array = (unsigned short *) NULL; + unsigned short *pCard16Array = NULL; unsigned long *pCard32; - unsigned long *pCard32Array = (unsigned long *) NULL; + unsigned long *pCard32Array = NULL; unsigned long Card32Array[18]; int ret_format; unsigned long ret_len, ret_after; @@ -1171,7 +1169,7 @@ LoadDataGray(Display *pDpy, window root, int tableType, &ret_prop); if (ret_format != 0) { XDeleteProperty(pDpy, root, CorrectAtom); - XFree((char *) ret_prop); + XFree(ret_prop); } return (1); } @@ -1184,8 +1182,8 @@ LoadDataGray(Display *pDpy, window root, int tableType, case 8: total = 6 /* visualID, type, length */ + (nLevels * (tableType == 0 ? 2 : 1)); - if ((pCard8 = pCard8Array = (unsigned char *) - calloc(total, sizeof(unsigned char))) == NULL) { + pCard8 = pCard8Array = calloc(total, sizeof(unsigned char)); + if (pCard8 == NULL) { fprintf(stderr, "Unable allocate array of Card8\n"); return (0); } @@ -1207,8 +1205,8 @@ LoadDataGray(Display *pDpy, window root, int tableType, case 16: total = 4 /* visualID, type, length */ + (nLevels * (tableType == 0 ? 2 : 1)); - if ((pCard16 = pCard16Array = (unsigned short *) - calloc(total, sizeof(unsigned short))) == NULL) { + pCard16 = pCard16Array = calloc(total, sizeof(unsigned short)); + if (pCard16 == NULL) { fprintf(stderr, "Unable allocate array of Card16\n"); return (0); } @@ -1228,8 +1226,8 @@ LoadDataGray(Display *pDpy, window root, int tableType, case 32: total = 3 /* visualID, type, length */ + (nLevels * (tableType == 0 ? 2 : 1)); - if ((pCard32 = pCard32Array = (unsigned long *) - calloc(total, sizeof(unsigned long))) == NULL) { + pCard32 = pCard32Array = calloc(total, sizeof(unsigned long)); + if ((pCard32 == NULL) { fprintf(stderr, "Unable allocate array of Card32\n"); return (0); } @@ -1314,8 +1312,8 @@ ParseVisualOptions(Display *pDpy, XDCCC_Correction *pCorrection, char *pbuf) do { long tmp; - value = strtok((char *) NULL, delims); - if ((key == (char *) NULL) || (value == (char *) NULL)) { + value = strtok(NULL, delims); + if ((key == NULL) || (value == NULL)) { return (0); } switch (StrToDefine(VisualOptKeyTbl, key)) { @@ -1419,8 +1417,8 @@ ParseVisualOptions(Display *pDpy, XDCCC_Correction *pCorrection, char *pbuf) fprintf(stderr, "Line %d: invalid keyword %s\n", linenum, key); return (0); } - key = strtok((char *) NULL, delims); - } while (key != (char *) NULL); + key = strtok(NULL, delims); + } while (key != NULL); vinfo = XGetVisualInfo(pDpy, pCorrection->visual_info_mask, @@ -1439,8 +1437,7 @@ ParseVisualOptions(Display *pDpy, XDCCC_Correction *pCorrection, char *pbuf) fprintf(stderr, " Using VisualId 0x%lx\n", (unsigned long) vinfo->visualid); } - memcpy((char *) &pCorrection->visual_info, (char *) vinfo, - sizeof(XVisualInfo)); + memcpy(&pCorrection->visual_info, vinfo, sizeof(XVisualInfo)); return (1); } @@ -1479,8 +1476,8 @@ LoadSCCData(Display *pDpy, int screenNumber, const char *filename, int VisualFlag = -2; Window root; XDCCC_Matrix matrix; - XDCCC_Correction *CorrectionTail = (XDCCC_Correction *) NULL; - XDCCC_Correction *CorrectionHead = (XDCCC_Correction *) NULL; + XDCCC_Correction *CorrectionTail = NULL; + XDCCC_Correction *CorrectionHead = NULL; XDCCC_Correction *pCurrent; if (screenNumber < 0) { @@ -1513,7 +1510,7 @@ LoadSCCData(Display *pDpy, int screenNumber, const char *filename, while ((pStr = nextline(buf, BUFSIZ, stream)) != NULL) { keyword = strtok(buf, DATA_DELIMS); - if (keyword != (char *) NULL && + if (keyword != NULL && (strcmp(keyword, SC_BEGIN_KEYWORD) == 0)) { break; } /* else ignore the line */ @@ -1525,7 +1522,7 @@ LoadSCCData(Display *pDpy, int screenNumber, const char *filename, return (0); } - token1 = strtok((char *) NULL, DATA_DELIMS); + token1 = strtok(NULL, DATA_DELIMS); if (token1 && (strcmp(token1, TXT_FORMAT_VERSION) != 0) && (strcmp(token1, "0.3") != 0)) { fprintf(stderr, @@ -1537,7 +1534,7 @@ LoadSCCData(Display *pDpy, int screenNumber, const char *filename, while ((pStr = nextline(buf, BUFSIZ, stream)) != NULL) { keyword = strtok(buf, DATA_DELIMS); - if (keyword != (char *) NULL) { + if (keyword != NULL) { switch (SCKeyOf(keyword)) { case COMMENT: case NAME: @@ -1548,15 +1545,15 @@ LoadSCCData(Display *pDpy, int screenNumber, const char *filename, /* Do nothing */ break; case SCREEN_CLASS: - token1 = strtok((char *) NULL, DATA_DELIMS); - token2 = strtok((char *) NULL, DATA_DELIMS); - if ((token1 == (char *) NULL) + token1 = strtok(NULL, DATA_DELIMS); + token2 = strtok(NULL, DATA_DELIMS); + if ((token1 == NULL) || ((VisualFlag = SCScrnClassOf(token1)) == -1)) { closeS(stream, CorrectionHead); return (0); } /*include code to handle screen number input */ - if (token2 != (char *) NULL) { + if (token2 != NULL) { screenNumber = atoi(token2); if (screenNumber < 0) { @@ -1590,9 +1587,9 @@ LoadSCCData(Display *pDpy, int screenNumber, const char *filename, closeS(stream, CorrectionHead); return (0); } - token1 = strtok((char *) NULL, DATA_DELIMS); - token2 = strtok((char *) NULL, DATA_DELIMS); - if ((token1 == (char *) NULL) || (token2 == (char *) NULL)) { + token1 = strtok(NULL, DATA_DELIMS); + token2 = strtok(NULL, DATA_DELIMS); + if ((token1 == NULL) || (token2 == NULL)) { fprintf(stderr, "Line %d: Intensity profile missing TableType and/or nTables.", linenum); @@ -1600,8 +1597,8 @@ LoadSCCData(Display *pDpy, int screenNumber, const char *filename, return (0); } - if ((pCurrent = (XDCCC_Correction *) - calloc(1, sizeof(XDCCC_Correction))) == NULL) { + pCurrent = calloc(1, sizeof(XDCCC_Correction)); + if (pCurrent == NULL) { fprintf(stderr, "Line %d: Could not allocate memory for intensity profile.", linenum); @@ -1618,7 +1615,7 @@ LoadSCCData(Display *pDpy, int screenNumber, const char *filename, return (0); } - if ((VisualFlag == VIDEO_RGB) && (token2 == (char *) NULL)) { + if ((VisualFlag == VIDEO_RGB) && (token2 == NULL)) { fprintf(stderr, "Line %d: invalid number of tables specified -- %s\n", linenum, buf); @@ -1641,8 +1638,8 @@ LoadSCCData(Display *pDpy, int screenNumber, const char *filename, pCurrent->nTables = 0; } - token3 = strtok((char *) NULL, "\n"); - if (token3 != (char *) NULL) { + token3 = strtok(NULL, "\n"); + if (token3 != NULL) { if (!ParseVisualOptions(pDpy, pCurrent, token3)) { goto ByPassThisIProfile; } @@ -1650,24 +1647,24 @@ LoadSCCData(Display *pDpy, int screenNumber, const char *filename, switch (pCurrent->nTables) { case 3: - if (!(pCurrent->pRedTbl = (IntensityTbl *) - calloc(1, sizeof(IntensityTbl)))) { + pCurrent->pRedTbl = calloc(1, sizeof(IntensityTbl)); + if (pCurrent->pRedTbl == NULL) { fprintf(stderr, "Line %d: Could not allocate Red Intensity Table\n", linenum); closeS(stream, CorrectionHead); return (0); } - if (!(pCurrent->pGreenTbl = (IntensityTbl *) - calloc(1, sizeof(IntensityTbl)))) { + pCurrent->pGreenTbl = calloc(1, sizeof(IntensityTbl)); + if (pCurrent->pGreenTbl == NULL) { fprintf(stderr, "Line %d: Could not allocate Green Intensity Table\n", linenum); closeS(stream, CorrectionHead); return (0); } - if (!(pCurrent->pBlueTbl = (IntensityTbl *) - calloc(1, sizeof(IntensityTbl)))) { + pCurrent->pBlueTbl = calloc(1, sizeof(IntensityTbl)); + if (pCurrent->pBlueTbl == NULL) { fprintf(stderr, "Line %d: Could not allocate Blue Intensity Table", linenum); @@ -1679,8 +1676,8 @@ LoadSCCData(Display *pDpy, int screenNumber, const char *filename, } break; case 1: - if (!(pCurrent->pRedTbl = (IntensityTbl *) - calloc(1, sizeof(IntensityTbl)))) { + pCurrent->pRedTbl = calloc(1, sizeof(IntensityTbl)); + if (pCurrent->pRedTbl == NULL) { fprintf(stderr, "Line %d: Could not allocate Red Intensity Table", linenum); @@ -1711,7 +1708,7 @@ LoadSCCData(Display *pDpy, int screenNumber, const char *filename, /* read till INTENSITY_PROFILE_END */ while ((pStr = nextline(buf, BUFSIZ, stream)) != NULL) { keyword = strtok(buf, DATA_DELIMS); - if (keyword != (char *) NULL) { + if (keyword != NULL) { switch (SCKeyOf(keyword)) { case ITBL_BEGIN: case ITBL_END: @@ -758,7 +758,7 @@ RemoveSCCData(Display *dpy, Window root, int colorFlag) else { printf("Deleting property %s\n", XDCCC_MATRIX_ATOM_NAME); XDeleteProperty(dpy, root, MatricesAtom); - XFree((char *) ret_prop); + XFree(ret_prop); } CorrectAtom = XInternAtom(dpy, XDCCC_CORRECT_ATOM_NAME, True); @@ -774,7 +774,7 @@ RemoveSCCData(Display *dpy, Window root, int colorFlag) else { printf("Deleting property %s\n", XDCCC_CORRECT_ATOM_NAME); XDeleteProperty(dpy, root, CorrectAtom); - XFree((char *) ret_prop); + XFree(ret_prop); } } #ifdef GRAY @@ -793,7 +793,7 @@ RemoveSCCData(Display *dpy, Window root, int colorFlag) else { printf("Deleting property %s\n", XDCCC_SCREENWHITEPT_ATOM_NAME); XDeleteProperty(dpy, root, MatricesAtom); - XFree((char *) ret_prop); + XFree(ret_prop); } CorrectAtom = XInternAtom(dpy, XDCCC_GRAY_CORRECT_ATOM_NAME, True); @@ -810,7 +810,7 @@ RemoveSCCData(Display *dpy, Window root, int colorFlag) else { printf("Deleting property %s\n", XDCCC_GRAY_CORRECT_ATOM_NAME); XDeleteProperty(dpy, root, CorrectAtom); - XFree((char *) ret_prop); + XFree(ret_prop); } } #endif /* GRAY */ |