Skip to content

Commit fd48ecf

Browse files
committed
Merge pull request #43 from opsengine/cppcheck
fix cppcheck warnings
2 parents fbed9dd + 37f6159 commit fd48ecf

File tree

4 files changed

+10
-10
lines changed

4 files changed

+10
-10
lines changed

src/cpulimit.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ static void increase_priority() {
147147

148148
/* Get the number of CPUs */
149149
static int get_ncpu() {
150-
int ncpu = -1;
150+
int ncpu;
151151
#ifdef _SC_NPROCESSORS_ONLN
152152
ncpu = sysconf(_SC_NPROCESSORS_ONLN);
153153
#elif defined __APPLE__
@@ -156,6 +156,8 @@ static int get_ncpu() {
156156
sysctl(mib, 2, &ncpu, &len, NULL, 0);
157157
#elif defined _GNU_SOURCE
158158
ncpu = get_nprocs();
159+
#else
160+
ncpu = -1;
159161
#endif
160162
return ncpu;
161163
}

src/list.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,6 @@ void delete_node(struct list *l,struct list_node *node) {
6666
}
6767
l->count--;
6868
free(node);
69-
node = NULL;
7069
}
7170

7271
void destroy_node(struct list *l,struct list_node *node) {
@@ -75,7 +74,7 @@ void destroy_node(struct list *l,struct list_node *node) {
7574
delete_node(l,node);
7675
}
7776

78-
int is_EMPTYLIST_list(struct list *l) {
77+
int is_empty_list(struct list *l) {
7978
return (l->count==0?TRUE:FALSE);
8079
}
8180

@@ -123,8 +122,8 @@ void *locate_elem(struct list *l,void *elem) {
123122
}
124123

125124
void clear_list(struct list *l) {
126-
struct list_node *tmp;
127125
while(l->first!=EMPTYLIST) {
126+
struct list_node *tmp;
128127
tmp=l->first;
129128
l->first=l->first->next;
130129
free(tmp);
@@ -135,8 +134,8 @@ void clear_list(struct list *l) {
135134
}
136135

137136
void destroy_list(struct list *l) {
138-
struct list_node *tmp;
139137
while(l->first!=EMPTYLIST) {
138+
struct list_node *tmp;
140139
tmp=l->first;
141140
l->first=l->first->next;
142141
free(tmp->data);

src/memrchr.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,9 @@ memrchr(s, c, n)
2626
int c;
2727
size_t n;
2828
{
29-
const unsigned char *cp;
30-
3129
if (n != 0) {
32-
cp = (unsigned char *)s + n;
30+
const unsigned char *cp;
31+
cp = (unsigned char *)s + n;
3332
do {
3433
if (*(--cp) == (unsigned char)c)
3534
return((void *)cp);

src/process_iterator_linux.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323

2424
static int get_boot_time()
2525
{
26-
int uptime;
26+
int uptime = 0;
2727
FILE *fp = fopen ("/proc/uptime", "r");
2828
if (fp != NULL)
2929
{
@@ -103,7 +103,7 @@ static int read_process_info(pid_t pid, struct process *p)
103103
return -1;
104104
}
105105
fclose(fd);
106-
sscanf(buffer, "%s", p->command);
106+
strcpy(p->command, buffer);
107107
return 0;
108108
}
109109

0 commit comments

Comments
 (0)