Skip to content

Commit

Permalink
clear all warnings from cppcheck static code analysis
Browse files Browse the repository at this point in the history
obtained with: cppcheck --enable=warning --force --inconclusive --quiet ~/firejail/src
  • Loading branch information
smitsohu committed Aug 11, 2018
1 parent a535609 commit f6d6204
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 17 deletions.
2 changes: 1 addition & 1 deletion src/firejail/join.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ static void extract_x11_display(pid_t pid) {
if (!fp)
return;

if (1 != fscanf(fp, "%d", &display)) {
if (1 != fscanf(fp, "%u", &display)) {
fprintf(stderr, "Error: cannot read X11 display file\n");
fclose(fp);
return;
Expand Down
3 changes: 0 additions & 3 deletions src/firejail/profile.c
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,6 @@ void profile_add_ignore(const char *str) {
fprintf(stderr, "Error: invalid ignore option\n");
exit(1);
}
char *ptr = strdup(str);
if (!ptr)
errExit("strdup");

// find an empty entry in profile_ignore array
int i;
Expand Down
4 changes: 2 additions & 2 deletions src/firejail/sandbox.c
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ static int monitor_application(pid_t app_pid) {
}
while(rv != monitored_pid);
if (arg_debug)
printf("Sandbox monitor: waitpid %u retval %d status %d\n", monitored_pid, rv, status);
printf("Sandbox monitor: waitpid %d retval %d status %d\n", monitored_pid, rv, status);
if (rv == -1) { // we can get here if we have processes joining the sandbox (ECHILD)
if (arg_debug)
perror("waitpid");
Expand Down Expand Up @@ -294,7 +294,7 @@ static int monitor_application(pid_t app_pid) {
closedir(dir);

if (monitored_pid != 0 && arg_debug)
printf("Sandbox monitor: monitoring %u\n", monitored_pid);
printf("Sandbox monitor: monitoring %d\n", monitored_pid);
}

// return the latest exit status.
Expand Down
2 changes: 1 addition & 1 deletion src/firemon/arp.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ static void print_arp(const char *fname) {
char mac[64];
char mask[64];
char device[64];
int rv = sscanf(start, "%s %s %s %s %s %s\n", ip, type, flags, mac, mask, device);
int rv = sscanf(start, "%63s %63s %63s %63s %63s %63s\n", ip, type, flags, mac, mask, device);
if (rv != 6)
continue;

Expand Down
6 changes: 3 additions & 3 deletions src/firemon/route.c
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ static void print_route(const char *fname) {
char use[64];
char metric[64];
char mask[64];
int rv = sscanf(start, "%s %s %s %s %s %s %s %s\n", ifname, destination, gateway, flags, refcnt, use, metric, mask);
int rv = sscanf(start, "%63s %63s %63s %63s %63s %63s %63s %63s\n", ifname, destination, gateway, flags, refcnt, use, metric, mask);
if (rv != 8)
continue;

Expand All @@ -161,15 +161,15 @@ static void print_route(const char *fname) {

// printf("#%s# #%s# #%s# #%s# #%s# #%s# #%s# #%s#\n", ifname, destination, gateway, flags, refcnt, use, metric, mask);
if (gw != 0)
printf(" %u.%u.%u.%u/%u via %u.%u.%u.%u, dev %s, metric %s\n",
printf(" %d.%d.%d.%d/%u via %d.%d.%d.%d, dev %s, metric %s\n",
PRINT_IP(destip), mask2bits(destmask),
PRINT_IP(gw),
ifname,
metric);
else { // this is an interface
IfList *ifentry = list_find(destip, destmask);
if (ifentry) {
printf(" %u.%u.%u.%u/%u, dev %s, scope link src %d.%d.%d.%d\n",
printf(" %d.%d.%d.%d/%u, dev %s, scope link src %d.%d.%d.%d\n",
PRINT_IP(destip), mask2bits(destmask),
ifname,
PRINT_IP(ifentry->ip));
Expand Down
2 changes: 1 addition & 1 deletion src/fnetfilter/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ for (i = 0; i < argcnt; i++)
else {
// parsing
int index = 0;
int rv = sscanf(ptr, "$ARG%u", &index) ;
int rv = sscanf(ptr, "$ARG%d", &index) ;
if (rv != 1) {
fprintf(stderr, "Error fnetfilter: invalid template argument on line %d\n", line);
exit(1);
Expand Down
15 changes: 9 additions & 6 deletions src/libtracelog/libtracelog.c
Original file line number Diff line number Diff line change
Expand Up @@ -64,16 +64,17 @@ static inline uint32_t hash(const char *str) {
}

static void storage_add(const char *str) {
#ifdef DEBUG
printf("add %s\n", str);
#endif
if (!str) {
#ifdef DEBUG
printf("null pointer passed to storage_add\n");
#endif
return;
}

#ifdef DEBUG
printf("add %s\n", str);
#endif

ListElem *ptr = malloc(sizeof(ListElem));
if (!ptr) {
fprintf(stderr, "Error: cannot allocate memory\n");
Expand All @@ -96,15 +97,17 @@ static void storage_add(const char *str) {
static char* cwd = NULL;

static char *storage_find(const char *str) {
#ifdef DEBUG
printf("storage find %s\n", str);
#endif
if (!str) {
#ifdef DEBUG
printf("null pointer passed to storage_find\n");
#endif
return NULL;
}

#ifdef DEBUG
printf("storage find %s\n", str);
#endif

const char *tofind = str;
int allocated = 0;

Expand Down

0 comments on commit f6d6204

Please sign in to comment.