Skip to content

Commit 592d540

Browse files
committed
Fixed many cppcheck nits. See issue #376.
1 parent 793f749 commit 592d540

8 files changed

Lines changed: 30 additions & 29 deletions

File tree

common/blink.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ static void _redraw_cursor( void)
55
if( SP->cursrow >= 0 && SP->curscol >= 0
66
&& SP->cursrow < SP->lines && SP->curscol < SP->cols)
77
{
8-
chtype *tptr = curscr->_y[SP->cursrow];
8+
const chtype *tptr = curscr->_y[SP->cursrow];
99

1010
if( tptr)
1111
PDC_transform_line_sliced( SP->cursrow, SP->curscol, 1,

common/pdccolor.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -93,18 +93,18 @@ didn't change (new RGB matched the old one), and 1 if the color changed. */
9393

9494
int PDC_set_palette_entry( const int idx, const PACKED_RGB rgb)
9595
{
96-
int rval, i;
96+
int rval;
9797

9898
if( idx >= _palette_size)
9999
{
100-
int new_size = _palette_size;
100+
int i, new_size = _palette_size;
101101
const int initial_palette_size = 8;
102102

103103
if( !new_size)
104104
new_size = initial_palette_size;
105105
while( new_size <= idx)
106106
new_size *= 2;
107-
rgbs = (PACKED_RGB *)realloc( rgbs, new_size * sizeof( PACKED_RGB));
107+
rgbs = (PACKED_RGB *)PDC_realloc_array( rgbs, new_size, sizeof( PACKED_RGB));
108108
assert( rgbs);
109109
if( !rgbs)
110110
return( -1);
@@ -131,12 +131,13 @@ int PDC_set_palette_entry( const int idx, const PACKED_RGB rgb)
131131

132132
static PACKED_RGB intensified_color( PACKED_RGB ival)
133133
{
134-
int rgb, i;
134+
int i;
135135
PACKED_RGB oval = 0;
136136

137137
for( i = 0; i < 3; i++, ival >>= 8)
138138
{
139-
rgb = (int)( ival & 0xff);
139+
int rgb = (int)( ival & 0xff);
140+
140141
if( rgb >= 192)
141142
rgb = 255;
142143
else

demos/xmas.c

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -819,9 +819,6 @@ void reindeer(void)
819819

820820
for (x_pos = 70; x_pos > 62; x_pos--)
821821
{
822-
if (x_pos < 62)
823-
y_pos = 1;
824-
825822
for (looper = 0; looper < 4; looper++)
826823
{
827824
mvwaddch(dotdeer0, y_pos, x_pos, (chtype) '.');

gl/pdckbd.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -250,9 +250,9 @@ static int _process_key_event(void)
250250
strlen(event.text.text));
251251
rval = (key > 0x7f ? -1 : _handle_alt_keys(key));
252252
#endif
253-
if( strchr( "/+*-", rval)) /* may actually be PADSLASH, PADPLUS, */
254-
{ /* etc. Wait 2 ms to see if a PADx */
255-
_stored_key = rval; /* keystroke is coming in. */
253+
if( rval > 0 && strchr( "/+*-", rval)) /* may actually be */
254+
{ /* PADSLASH, PADPLUS, etc. Wait 2 ms to */
255+
_stored_key = rval; /* see if a PADx keystroke is coming in. */
256256
_stored_timestamp = event.text.timestamp;
257257
rval = -1;
258258
}

gl/pdcscrn.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -280,12 +280,14 @@ void PDC_scr_free(void)
280280
int _get_displaynum(void)
281281
{
282282
SDL_Rect size;
283-
int i, xpos, ypos, displays;
283+
int xpos, ypos, displays;
284284

285285
displays = SDL_GetNumVideoDisplays();
286286

287287
if (displays > 1)
288288
{
289+
int i;
290+
289291
SDL_GetGlobalMouseState(&xpos, &ypos);
290292

291293
for (i = 0; i < displays; i++)

pdcurses/attr.c

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -158,8 +158,6 @@ int attroff(chtype attrs)
158158

159159
int wattron(WINDOW *win, chtype attrs)
160160
{
161-
chtype newcolr, oldcolr, newattr, oldattr;
162-
163161
PDC_LOG(("wattron() - called\n"));
164162

165163
assert( win);
@@ -168,10 +166,11 @@ int wattron(WINDOW *win, chtype attrs)
168166

169167
if ((win->_attrs & A_COLOR) && (attrs & A_COLOR))
170168
{
171-
oldcolr = win->_attrs & A_COLOR;
172-
oldattr = win->_attrs ^ oldcolr;
173-
newcolr = attrs & A_COLOR;
174-
newattr = (attrs & A_ATTRIBUTES) ^ newcolr;
169+
const chtype oldcolr = win->_attrs & A_COLOR;
170+
const chtype oldattr = win->_attrs ^ oldcolr;
171+
const chtype newcolr = attrs & A_COLOR;
172+
chtype newattr = (attrs & A_ATTRIBUTES) ^ newcolr;
173+
175174
newattr |= oldattr;
176175
win->_attrs = newattr | newcolr;
177176
}

pdcurses/border.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ border
107107
current background of win, as set by wbkgd(), should by combined with
108108
it. Attributes set explicitly in ch take precedence. */
109109

110-
static chtype _attr_passthru(WINDOW *win, chtype ch)
110+
static chtype _attr_passthru( const WINDOW *win, chtype ch)
111111
{
112112
chtype attr;
113113

pdcurses/color.c

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ static void _init_pair_core(int pair, int fg, int bg);
158158
static void _unlink_color_pair( const int pair_no)
159159
{
160160
PDC_PAIR *p = SP->pairs;
161-
PDC_PAIR *curr = p + pair_no;
161+
const PDC_PAIR *curr = p + pair_no;
162162

163163
p[curr->next].prev = curr->prev;
164164
p[curr->prev].next = curr->next;
@@ -200,7 +200,7 @@ static void _check_hash_tbl( void)
200200
if( SP->pair_hash_tbl_used * 5 / 4 >= SP->pair_hash_tbl_size)
201201
{
202202
int i, n_pairs;
203-
PDC_PAIR *p = SP->pairs;
203+
const PDC_PAIR *p = SP->pairs;
204204

205205
for( i = 1, n_pairs = 0; i < SP->pairs_allocated; i++)
206206
if( p[i].f != UNSET_COLOR_PAIR)
@@ -287,7 +287,7 @@ few cycles by not shifting. */
287287

288288
static void _set_cells_to_refresh_for_pair_change( const int pair)
289289
{
290-
int x, y;
290+
int y;
291291
const chtype mask = ((chtype)pair << PDC_COLOR_SHIFT);
292292

293293
assert( SP->lines);
@@ -296,6 +296,7 @@ static void _set_cells_to_refresh_for_pair_change( const int pair)
296296
for( y = 0; y < SP->lines; y++)
297297
{
298298
chtype *line = curscr->_y[y];
299+
int x;
299300

300301
assert( line);
301302
for( x = 0; x < SP->cols; x++)
@@ -317,14 +318,15 @@ redrawn. */
317318

318319
static void _set_cells_to_refresh_for_attr_change( const chtype attr)
319320
{
320-
int x, y;
321+
int y;
321322

322323
assert( SP->lines);
323324
assert( curscr && curscr->_y);
324325
if( !curscr->_clear)
325326
for( y = 0; y < SP->lines; y++)
326327
{
327328
const chtype *line = curscr->_y[y];
329+
int x;
328330

329331
assert( line);
330332
for( x = 0; x < SP->cols; x++)
@@ -352,8 +354,8 @@ static void _init_pair_core(int pair, int fg, int bg)
352354

353355
while( pair >= new_size)
354356
new_size += new_size;
355-
SP->pairs = (PDC_PAIR *)realloc( SP->pairs,
356-
(new_size + 1) * sizeof( PDC_PAIR));
357+
SP->pairs = (PDC_PAIR *)PDC_realloc_array( SP->pairs,
358+
(new_size + 1), sizeof( PDC_PAIR));
357359
for( i = SP->pairs_allocated + 1; i <= new_size; i++)
358360
{
359361
p = SP->pairs + i;
@@ -476,7 +478,7 @@ bool can_change_color(void)
476478

477479
int extended_pair_content(int pair, int *fg, int *bg)
478480
{
479-
PDC_PAIR *p = SP->pairs + pair;
481+
const PDC_PAIR *p = SP->pairs + pair;
480482

481483
PDC_LOG(("pair_content() - called\n"));
482484

@@ -627,7 +629,7 @@ int find_pair( int fg, int bg)
627629

628630
if( (i = SP->pair_hash_tbl[idx]) > 0)
629631
{
630-
PDC_PAIR *p = SP->pairs;
632+
const PDC_PAIR *p = SP->pairs;
631633

632634
if( p[i].f == fg && p[i].b == bg)
633635
{
@@ -671,7 +673,7 @@ int alloc_pair( int fg, int bg)
671673

672674
int free_pair( int pair)
673675
{
674-
PDC_PAIR *p;
676+
const PDC_PAIR *p;
675677

676678
assert( SP && SP->pairs);
677679
assert( pair >= 1 && pair < SP->pairs_allocated);

0 commit comments

Comments
 (0)