summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlan Coopersmith <alan.coopersmith@oracle.com>2022-09-16 14:34:41 -0700
committerAlan Coopersmith <alan.coopersmith@oracle.com>2022-09-16 15:14:22 -0700
commit6d526c90729d1b66da6c2546ad3ae794ff0f7751 (patch)
treed8e839a7aa03dad62a845fbf936e0d9d1491d09f
parent548998994665241967a43e583f5d0f00ee089289 (diff)
Variable scope reductions as recommended by cppcheck
Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>
-rw-r--r--atom.c9
-rw-r--r--bdfread.c31
-rw-r--r--bdfutils.c14
-rw-r--r--bitmap.c19
-rw-r--r--bitmaputil.c27
-rw-r--r--bufio.c21
-rw-r--r--fontink.c9
-rw-r--r--pcfwrite.c10
-rw-r--r--private.c4
-rw-r--r--utilbitmap.c14
10 files changed, 68 insertions, 90 deletions
diff --git a/atom.c b/atom.c
index 818b32f..e37f322 100644
--- a/atom.c
+++ b/atom.c
@@ -72,10 +72,7 @@ ResizeHashTable(void)
int newHashSize;
int newHashMask;
AtomListPtr *newHashTable;
- int i;
- int h;
int newRehash;
- int r;
if (hashSize == 0)
newHashSize = 1024;
@@ -90,11 +87,11 @@ ResizeHashTable(void)
}
newHashMask = newHashSize - 1;
newRehash = (newHashMask - 2);
- for (i = 0; i < hashSize; i++) {
+ for (int i = 0; i < hashSize; i++) {
if (hashTable[i]) {
- h = (hashTable[i]->hash) & newHashMask;
+ int h = (hashTable[i]->hash) & newHashMask;
if (newHashTable[h]) {
- r = hashTable[i]->hash % newRehash | 1;
+ int r = hashTable[i]->hash % newRehash | 1;
do {
h += r;
if (h >= newHashSize)
diff --git a/bdfread.c b/bdfread.c
index b72cfd2..3e5517f 100644
--- a/bdfread.c
+++ b/bdfread.c
@@ -90,7 +90,7 @@ bdfReadBitmap(CharInfoPtr pCI, FontFilePtr file, int bit, int byte,
{
int widthBits, widthBytes, widthHexChars;
int height, row;
- int i, inLineLen, nextByte;
+ int i, nextByte;
unsigned char *pInBits, *picture, *line = NULL;
unsigned char lineBuf[BDFLINELEN];
@@ -120,6 +120,8 @@ bdfReadBitmap(CharInfoPtr pCI, FontFilePtr file, int bit, int byte,
/* 0 width characters? */
for (row = 0; row < height; row++) {
+ int inLineLen;
+
line = bdfGetLine(file, lineBuf, BDFLINELEN);
if (!line)
break;
@@ -222,21 +224,18 @@ bdfSkipBitmap(FontFilePtr file, int height)
static void
bdfFreeFontBits(FontPtr pFont)
{
- BitmapFontPtr bitmapFont;
- BitmapExtraPtr bitmapExtra;
- int i, nencoding;
+ BitmapFontPtr bitmapFont = (BitmapFontPtr) pFont->fontPrivate;
+ BitmapExtraPtr bitmapExtra = (BitmapExtraPtr) bitmapFont->bitmapExtra;
- bitmapFont = (BitmapFontPtr) pFont->fontPrivate;
- bitmapExtra = (BitmapExtraPtr) bitmapFont->bitmapExtra;
free(bitmapFont->ink_metrics);
if (bitmapFont->encoding) {
- nencoding = (pFont->info.lastCol - pFont->info.firstCol + 1) *
+ int nencoding = (pFont->info.lastCol - pFont->info.firstCol + 1) *
(pFont->info.lastRow - pFont->info.firstRow + 1);
- for (i = 0; i < NUM_SEGMENTS(nencoding); i++)
+ for (int i = 0; i < NUM_SEGMENTS(nencoding); i++)
free(bitmapFont->encoding[i]);
}
free(bitmapFont->encoding);
- for (i = 0; i < bitmapFont->num_chars; i++)
+ for (int i = 0; i < bitmapFont->num_chars; i++)
free(bitmapFont->metrics[i].bits);
free(bitmapFont->metrics);
if (bitmapExtra) {
@@ -861,13 +860,13 @@ bdfReadFont(FontPtr pFont, FontFilePtr file,
goto BAILOUT;
if (state.haveDefaultCh) {
- unsigned int r, c, cols;
+ unsigned int r, c;
r = pFont->info.defaultCh >> 8;
c = pFont->info.defaultCh & 0xFF;
if (pFont->info.firstRow <= r && r <= pFont->info.lastRow &&
pFont->info.firstCol <= c && c <= pFont->info.lastCol) {
- cols = pFont->info.lastCol - pFont->info.firstCol + 1;
+ unsigned int cols = pFont->info.lastCol - pFont->info.firstCol + 1;
r = r - pFont->info.firstRow;
c = c - pFont->info.firstCol;
bitmapFont->pDefault = ACCESSENCODING(bitmapFont->encoding,
@@ -950,10 +949,8 @@ bdfPadToTerminal(FontPtr pFont)
{
BitmapFontPtr bitmapFont;
BitmapExtraPtr bitmapExtra;
- int i;
int new_size;
CharInfoRec new;
- int w, h;
bitmapFont = (BitmapFontPtr) pFont->fontPrivate;
@@ -965,7 +962,7 @@ bdfPadToTerminal(FontPtr pFont)
new.metrics.characterWidth = new.metrics.rightSideBearing;
new_size = BYTES_FOR_GLYPH(&new, pFont->glyph);
- for (i = 0; i < bitmapFont->num_chars; i++) {
+ for (int i = 0; i < bitmapFont->num_chars; i++) {
new.bits = malloc(new_size);
if (!new.bits) {
bdfError("Couldn't allocate bits (%d)\n", new_size);
@@ -978,9 +975,9 @@ bdfPadToTerminal(FontPtr pFont)
}
bitmapExtra = bitmapFont->bitmapExtra;
if (bitmapExtra) {
- w = GLYPHWIDTHPIXELS(&new);
- h = GLYPHHEIGHTPIXELS(&new);
- for (i = 0; i < GLYPHPADOPTIONS; i++)
+ int w = GLYPHWIDTHPIXELS(&new);
+ int h = GLYPHHEIGHTPIXELS(&new);
+ for (int i = 0; i < GLYPHPADOPTIONS; i++)
bitmapExtra->bitmapsSizes[i] = bitmapFont->num_chars *
(BYTES_PER_ROW(w, 1 << i) * h);
}
diff --git a/bdfutils.c b/bdfutils.c
index 6eb220d..9a81b99 100644
--- a/bdfutils.c
+++ b/bdfutils.c
@@ -99,11 +99,10 @@ bdfWarning(const char *message, ...)
unsigned char *
bdfGetLine(FontFilePtr file, unsigned char *buf, int len)
{
- int c;
- unsigned char *b;
-
for (;;) {
- b = buf;
+ int c;
+ unsigned char *b = buf;
+
while ((c = FontFileGetc(file)) != FontFileEOF) {
if (c == '\r')
continue;
@@ -227,11 +226,10 @@ unsigned char
bdfHexByte(unsigned char *s)
{
unsigned char b = 0;
- register char c;
- int i;
- for (i = 2; i; i--) {
- c = *s++;
+ for (int i = 2; i; i--) {
+ char c = *s++;
+
if ((c >= '0') && (c <= '9'))
b = (b << 4) + (c - '0');
else if ((c >= 'A') && (c <= 'F'))
diff --git a/bitmap.c b/bitmap.c
index 4b2bf3c..5073782 100644
--- a/bitmap.c
+++ b/bitmap.c
@@ -49,7 +49,6 @@ bitmapGetGlyphs(FontPtr pFont, unsigned long count, unsigned char *chars,
CharInfoPtr *glyphsBase;
register unsigned int c;
register CharInfoPtr pci;
- unsigned int r;
CharInfoPtr **encoding;
CharInfoPtr pDefault;
@@ -115,6 +114,8 @@ bitmapGetGlyphs(FontPtr pFont, unsigned long count, unsigned char *chars,
firstRow = pFont->info.firstRow;
numRows = pFont->info.lastRow - firstRow + 1;
while (count--) {
+ unsigned int r;
+
r = (*chars++) - firstRow;
c = (*chars++) - firstCol;
if (r < numRows && c < numCols &&
@@ -138,23 +139,19 @@ bitmapGetMetrics(FontPtr pFont, unsigned long count, unsigned char *chars,
xCharInfo ** glyphs) /* RETURN */
{
int ret;
- xCharInfo *ink_metrics;
- CharInfoPtr metrics;
- BitmapFontPtr bitmapFont;
- CharInfoPtr oldDefault;
- int i;
+ BitmapFontPtr bitmapFont = (BitmapFontPtr) pFont->fontPrivate;
+ CharInfoPtr oldDefault = bitmapFont->pDefault;
- bitmapFont = (BitmapFontPtr) pFont->fontPrivate;
- oldDefault = bitmapFont->pDefault;
bitmapFont->pDefault = &nonExistantChar;
ret =
bitmapGetGlyphs(pFont, count, chars, charEncoding, glyphCount,
(CharInfoPtr *) glyphs);
if (ret == Successful) {
if (bitmapFont->ink_metrics) {
- metrics = bitmapFont->metrics;
- ink_metrics = bitmapFont->ink_metrics;
- for (i = 0; i < *glyphCount; i++) {
+ CharInfoPtr metrics = bitmapFont->metrics;
+ xCharInfo *ink_metrics = bitmapFont->ink_metrics;
+
+ for (int i = 0; i < *glyphCount; i++) {
if (glyphs[i] != (xCharInfo *) & nonExistantChar)
glyphs[i] =
ink_metrics + (((CharInfoPtr) glyphs[i]) - metrics);
diff --git a/bitmaputil.c b/bitmaputil.c
index c74964a..324bd8f 100644
--- a/bitmaputil.c
+++ b/bitmaputil.c
@@ -73,7 +73,6 @@ bitmapComputeFontBounds(FontPtr pFont)
{
BitmapFontPtr bitmapFont = (BitmapFontPtr) pFont->fontPrivate;
int nchars;
- int r, c;
CharInfoPtr ci;
int maxOverlap;
int overlap;
@@ -117,8 +116,8 @@ bitmapComputeFontBounds(FontPtr pFont)
*maxbounds = initMaxMetrics;
i = 0;
maxOverlap = MINSHORT;
- for (r = pFont->info.firstRow; r <= pFont->info.lastRow; r++) {
- for (c = pFont->info.firstCol; c <= pFont->info.lastCol; c++) {
+ for (int r = pFont->info.firstRow; r <= pFont->info.lastRow; r++) {
+ for (int c = pFont->info.firstCol; c <= pFont->info.lastCol; c++) {
ci = ACCESSENCODING(bitmapFont->encoding, i);
if (ci) {
COMPUTE_MINMAX(&ci->metrics);
@@ -148,13 +147,6 @@ void
bitmapComputeFontInkBounds(FontPtr pFont)
{
BitmapFontPtr bitmapFont = (BitmapFontPtr) pFont->fontPrivate;
- int nchars;
- int r, c;
- CharInfoPtr cit;
- xCharInfo *ci;
- int offset;
- xCharInfo *minbounds, *maxbounds;
- int i;
if (!bitmapFont->ink_metrics) {
if (bitmapFont->bitmapExtra) {
@@ -167,6 +159,9 @@ bitmapComputeFontInkBounds(FontPtr pFont)
pFont->info.ink_maxbounds = pFont->info.maxbounds;
}
else {
+ xCharInfo *minbounds, *maxbounds, *ci;
+ int nchars, i;
+
if (bitmapFont->bitmapExtra) {
minbounds = &bitmapFont->bitmapExtra->info.ink_minbounds;
maxbounds = &bitmapFont->bitmapExtra->info.ink_maxbounds;
@@ -189,11 +184,12 @@ bitmapComputeFontInkBounds(FontPtr pFont)
*minbounds = initMinMetrics;
*maxbounds = initMaxMetrics;
i = 0;
- for (r = pFont->info.firstRow; r <= pFont->info.lastRow; r++) {
- for (c = pFont->info.firstCol; c <= pFont->info.lastCol; c++) {
- cit = ACCESSENCODING(bitmapFont->encoding, i);
+ for (int r = pFont->info.firstRow; r <= pFont->info.lastRow; r++) {
+ for (int c = pFont->info.firstCol; c <= pFont->info.lastCol; c++)
+ {
+ CharInfoPtr cit = ACCESSENCODING(bitmapFont->encoding, i);
if (cit) {
- offset = cit - bitmapFont->metrics;
+ int offset = cit - bitmapFont->metrics;
ci = &bitmapFont->ink_metrics[offset];
COMPUTE_MINMAX(ci);
minbounds->attributes &= ci->attributes;
@@ -210,7 +206,6 @@ Bool
bitmapAddInkMetrics(FontPtr pFont)
{
BitmapFontPtr bitmapFont;
- int i;
bitmapFont = (BitmapFontPtr) pFont->fontPrivate;
bitmapFont->ink_metrics = malloc(bitmapFont->num_chars * sizeof(xCharInfo));
@@ -219,7 +214,7 @@ bitmapAddInkMetrics(FontPtr pFont)
bitmapFont->num_chars, (unsigned long) sizeof(xCharInfo));
return FALSE;
}
- for (i = 0; i < bitmapFont->num_chars; i++)
+ for (int i = 0; i < bitmapFont->num_chars; i++)
FontCharInkMetrics(pFont, &bitmapFont->metrics[i],
&bitmapFont->ink_metrics[i]);
pFont->info.inkMetrics = TRUE;
diff --git a/bufio.c b/bufio.c
index de16961..e0e74b5 100644
--- a/bufio.c
+++ b/bufio.c
@@ -82,18 +82,16 @@ BufFileRawFill(BufFilePtr f)
static int
BufFileRawSkip(BufFilePtr f, int count)
{
- int curoff;
- int fileoff;
- int todo;
+ int curoff = f->bufp - f->buffer;
+ int fileoff = curoff + f->left;
- curoff = f->bufp - f->buffer;
- fileoff = curoff + f->left;
if (curoff + count <= fileoff) {
f->bufp += count;
f->left -= count;
}
else {
- todo = count - (fileoff - curoff);
+ int todo = count - (fileoff - curoff);
+
if (lseek(FileDes(f), todo, 1) == -1) {
if (errno != ESPIPE)
return BUFFILEEOF;
@@ -174,11 +172,10 @@ BufFileOpenWrite(int fd)
int
BufFileRead(BufFilePtr f, char *b, int n)
{
- int c, cnt;
+ int cnt = n;
- cnt = n;
while (cnt--) {
- c = BufFileGet(f);
+ int c = BufFileGet(f);
if (c == BUFFILEEOF)
break;
*b++ = c;
@@ -189,9 +186,8 @@ BufFileRead(BufFilePtr f, char *b, int n)
int
BufFileWrite(BufFilePtr f, char *b, int n)
{
- int cnt;
+ int cnt = n;
- cnt = n;
while (cnt--) {
if (BufFilePut(*b++, f) == BUFFILEEOF)
return BUFFILEEOF;
@@ -202,9 +198,8 @@ BufFileWrite(BufFilePtr f, char *b, int n)
int
BufFileClose(BufFilePtr f, int doClose)
{
- int ret;
+ int ret = (*f->close) (f, doClose);
- ret = (*f->close) (f, doClose);
free(f);
return ret;
}
diff --git a/fontink.c b/fontink.c
index 59c6cd4..abc6d4d 100644
--- a/fontink.c
+++ b/fontink.c
@@ -155,7 +155,6 @@ FontCharInkMetrics(FontPtr pFont, CharInfoPtr pCI, xCharInfo * pInk)
void
FontCharReshape(FontPtr pFont, CharInfoPtr pSrc, CharInfoPtr pDst)
{
- int x, y;
unsigned char *in_line, *out_line;
unsigned char *oldglyph, *newglyph;
int inwidth;
@@ -182,8 +181,8 @@ FontCharReshape(FontPtr pFont, CharInfoPtr pSrc, CharInfoPtr pDst)
in_line += (y_min + pSrc->metrics.ascent) * in_bytes;
out_line += (y_min + pDst->metrics.ascent) * out_bytes;
if (pFont->bit == MSBFirst) {
- for (y = y_min; y < y_max; y++) {
- for (x = x_min; x < x_max; x++) {
+ for (int y = y_min; y < y_max; y++) {
+ for (int x = x_min; x < x_max; x++) {
if (ISBITONMSB(x - pSrc->metrics.leftSideBearing, in_line))
SETBITMSB(x - pDst->metrics.leftSideBearing, out_line);
}
@@ -192,8 +191,8 @@ FontCharReshape(FontPtr pFont, CharInfoPtr pSrc, CharInfoPtr pDst)
}
}
else {
- for (y = y_min; y < y_max; y++) {
- for (x = x_min; x < x_max; x++) {
+ for (int y = y_min; y < y_max; y++) {
+ for (int x = x_min; x < x_max; x++) {
if (ISBITONLSB(x - pSrc->metrics.leftSideBearing, in_line))
SETBITLSB(x - pDst->metrics.leftSideBearing, out_line);
}
diff --git a/pcfwrite.c b/pcfwrite.c
index e01684c..361a5c6 100644
--- a/pcfwrite.c
+++ b/pcfwrite.c
@@ -117,13 +117,11 @@ pcfPutINT8(FontFilePtr file, CARD32 format, int c)
static void
pcfWriteTOC(FontFilePtr file, PCFTablePtr table, int count)
{
- CARD32 version;
- int i;
+ CARD32 version = PCF_FILE_VERSION;
- version = PCF_FILE_VERSION;
pcfPutLSB32(file, version);
pcfPutLSB32(file, count);
- for (i = 0; i < count; i++) {
+ for (int i = 0; i < count; i++) {
pcfPutLSB32(file, table->type);
pcfPutLSB32(file, table->format);
pcfPutLSB32(file, table->size);
@@ -216,7 +214,7 @@ int
pcfWriteFont(FontPtr pFont, FontFilePtr file)
{
PCFTableRec tables[32], *table;
- CARD32 mask, bit;
+ CARD32 mask;
int ntables;
int size;
CARD32 format;
@@ -272,7 +270,7 @@ pcfWriteFont(FontPtr pFont, FontFilePtr file)
ntables = 0;
table = tables;
while (mask) {
- bit = lowbit(mask);
+ CARD32 bit = lowbit(mask);
mask &= ~bit;
table->type = bit;
switch (bit) {
diff --git a/private.c b/private.c
index f9e3e32..ef72740 100644
--- a/private.c
+++ b/private.c
@@ -79,9 +79,9 @@ ResetFontPrivateIndex(void)
Bool
_FontSetNewPrivate(FontPtr pFont, int n, pointer ptr)
{
- pointer *new;
-
if (n > pFont->maxPrivate) {
+ pointer *new;
+
if (pFont->devPrivates && pFont->devPrivates != (pointer) (&pFont[1])) {
new = realloc(pFont->devPrivates, (n + 1) * sizeof(pointer));
if (!new)
diff --git a/utilbitmap.c b/utilbitmap.c
index 5d06124..b0c0249 100644
--- a/utilbitmap.c
+++ b/utilbitmap.c
@@ -88,9 +88,9 @@ BitOrderInvert(unsigned char *buf, int nbytes)
void
TwoByteSwap(unsigned char *buf, int nbytes)
{
- unsigned char c;
-
for (; nbytes > 0; nbytes -= 2, buf += 2) {
+ unsigned char c;
+
c = buf[0];
buf[0] = buf[1];
buf[1] = c;
@@ -103,12 +103,13 @@ TwoByteSwap(unsigned char *buf, int nbytes)
void
FourByteSwap(unsigned char *buf, int nbytes)
{
- unsigned char c;
-
for (; nbytes > 0; nbytes -= 4, buf += 4) {
+ unsigned char c;
+
c = buf[0];
buf[0] = buf[3];
buf[3] = c;
+
c = buf[1];
buf[1] = buf[2];
buf[2] = c;
@@ -124,7 +125,6 @@ RepadBitmap(char *pSrc, char *pDst,
unsigned int srcPad, unsigned int dstPad, int width, int height)
{
int srcWidthBytes, dstWidthBytes;
- int row, col;
char *pTmpSrc, *pTmpDst;
switch (srcPad) {
@@ -165,7 +165,9 @@ RepadBitmap(char *pSrc, char *pDst,
width = dstWidthBytes;
pTmpSrc = pSrc;
pTmpDst = pDst;
- for (row = 0; row < height; row++) {
+ for (int row = 0; row < height; row++) {
+ int col;
+
for (col = 0; col < width; col++)
*pTmpDst++ = *pTmpSrc++;
while (col < dstWidthBytes) {