aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAngelo Marletta <angelo.marletta@gmail.com>2015-02-17 01:04:25 -0800
committerAngelo Marletta <angelo.marletta@gmail.com>2015-02-17 01:04:25 -0800
commitfd48ecf5a123ddaf5dd02d7928f975db719975bb (patch)
tree7164753f2c3889cf29a21fab166a052f073a38de
parentfbed9dd0ba1e849ebc07f512903996879096df2d (diff)
parent37f61593b40aa98b465692d9a40c6ac03264a29a (diff)
downloadcpulimit-fd48ecf5a123ddaf5dd02d7928f975db719975bb.tar.gz
Merge pull request #43 from opsengine/cppcheck
fix cppcheck warnings
-rw-r--r--src/cpulimit.c4
-rw-r--r--src/list.c7
-rw-r--r--src/memrchr.c5
-rw-r--r--src/process_iterator_linux.c4
4 files changed, 10 insertions, 10 deletions
diff --git a/src/cpulimit.c b/src/cpulimit.c
index 9b25b87..dc61c3b 100644
--- a/src/cpulimit.c
+++ b/src/cpulimit.c
@@ -147,7 +147,7 @@ static void increase_priority() {
/* Get the number of CPUs */
static int get_ncpu() {
- int ncpu = -1;
+ int ncpu;
#ifdef _SC_NPROCESSORS_ONLN
ncpu = sysconf(_SC_NPROCESSORS_ONLN);
#elif defined __APPLE__
@@ -156,6 +156,8 @@ static int get_ncpu() {
sysctl(mib, 2, &ncpu, &len, NULL, 0);
#elif defined _GNU_SOURCE
ncpu = get_nprocs();
+#else
+ ncpu = -1;
#endif
return ncpu;
}
diff --git a/src/list.c b/src/list.c
index a1c20a3..2a78358 100644
--- a/src/list.c
+++ b/src/list.c
@@ -66,7 +66,6 @@ void delete_node(struct list *l,struct list_node *node) {
}
l->count--;
free(node);
- node = NULL;
}
void destroy_node(struct list *l,struct list_node *node) {
@@ -75,7 +74,7 @@ void destroy_node(struct list *l,struct list_node *node) {
delete_node(l,node);
}
-int is_EMPTYLIST_list(struct list *l) {
+int is_empty_list(struct list *l) {
return (l->count==0?TRUE:FALSE);
}
@@ -123,8 +122,8 @@ void *locate_elem(struct list *l,void *elem) {
}
void clear_list(struct list *l) {
- struct list_node *tmp;
while(l->first!=EMPTYLIST) {
+ struct list_node *tmp;
tmp=l->first;
l->first=l->first->next;
free(tmp);
@@ -135,8 +134,8 @@ void clear_list(struct list *l) {
}
void destroy_list(struct list *l) {
- struct list_node *tmp;
while(l->first!=EMPTYLIST) {
+ struct list_node *tmp;
tmp=l->first;
l->first=l->first->next;
free(tmp->data);
diff --git a/src/memrchr.c b/src/memrchr.c
index ba788f5..1f37870 100644
--- a/src/memrchr.c
+++ b/src/memrchr.c
@@ -26,10 +26,9 @@ memrchr(s, c, n)
int c;
size_t n;
{
- const unsigned char *cp;
-
if (n != 0) {
- cp = (unsigned char *)s + n;
+ const unsigned char *cp;
+ cp = (unsigned char *)s + n;
do {
if (*(--cp) == (unsigned char)c)
return((void *)cp);
diff --git a/src/process_iterator_linux.c b/src/process_iterator_linux.c
index 43c2771..c8cdd07 100644
--- a/src/process_iterator_linux.c
+++ b/src/process_iterator_linux.c
@@ -23,7 +23,7 @@
static int get_boot_time()
{
- int uptime;
+ int uptime = 0;
FILE *fp = fopen ("/proc/uptime", "r");
if (fp != NULL)
{
@@ -103,7 +103,7 @@ static int read_process_info(pid_t pid, struct process *p)
return -1;
}
fclose(fd);
- sscanf(buffer, "%s", p->command);
+ strcpy(p->command, buffer);
return 0;
}
Un proyecto texto-plano.xyz