|
|
93924e |
From 48641275c0cd018441685f2d3145038017f1ea42 Mon Sep 17 00:00:00 2001
|
|
|
93924e |
From: Kamil Dudka <kdudka@redhat.com>
|
|
|
93924e |
Date: Tue, 6 Nov 2018 16:31:32 +0100
|
|
|
93924e |
Subject: [PATCH] tree: fix programming mistakes detected by static analysis
|
|
|
93924e |
|
|
|
93924e |
---
|
|
|
93924e |
color.c | 6 +++---
|
|
|
93924e |
html.c | 5 +++--
|
|
|
93924e |
json.c | 11 +++++------
|
|
|
93924e |
tree.c | 2 +-
|
|
|
93924e |
unix.c | 5 +++--
|
|
|
93924e |
xml.c | 11 +++++------
|
|
|
93924e |
6 files changed, 20 insertions(+), 20 deletions(-)
|
|
|
93924e |
|
|
|
93924e |
diff --git a/color.c b/color.c
|
|
|
93924e |
index b4ef54e..04425dc 100644
|
|
|
93924e |
--- a/color.c
|
|
|
93924e |
+++ b/color.c
|
|
|
93924e |
@@ -235,8 +235,8 @@ int cmd(char *s)
|
|
|
93924e |
|
|
|
93924e |
for(i=0;cmds[i].cmdnum;i++)
|
|
|
93924e |
if (!strcmp(cmds[i].cmd,s)) return cmds[i].cmdnum;
|
|
|
93924e |
- if (s[0] == '*') return DOT_EXTENSION;
|
|
|
93924e |
- return ERROR;
|
|
|
93924e |
+ if (s[0] == '*') return DOT_EXTENSION;
|
|
|
93924e |
+ return ERROR;
|
|
|
93924e |
}
|
|
|
93924e |
|
|
|
93924e |
int color(u_short mode, char *name, bool orphan, bool islink)
|
|
|
93924e |
@@ -489,7 +489,7 @@ void initlinedraw(int flag)
|
|
|
93924e |
for(linedraw=cstable;linedraw->name;++linedraw)
|
|
|
93924e |
for(s=linedraw->name;*s;++s)
|
|
|
93924e |
fprintf(stderr," %s\n",*s);
|
|
|
93924e |
- return;
|
|
|
93924e |
+ return;
|
|
|
93924e |
}
|
|
|
93924e |
if (charset) {
|
|
|
93924e |
for(linedraw=cstable;linedraw->name;++linedraw)
|
|
|
93924e |
diff --git a/html.c b/html.c
|
|
|
93924e |
index 75e2ed1..35fb525 100644
|
|
|
93924e |
--- a/html.c
|
|
|
93924e |
+++ b/html.c
|
|
|
93924e |
@@ -220,7 +220,7 @@ off_t html_listdir(char *d, int *dt, int *ft, u_long lev, dev_t dev)
|
|
|
93924e |
if (*(*dir)->lnk == '/')
|
|
|
93924e |
listdir((*dir)->lnk,dt,ft,lev+1,dev);
|
|
|
93924e |
else {
|
|
|
93924e |
- if (strlen(d)+strlen((*dir)->lnk)+2 > pathsize) path=xrealloc(path,pathsize=(strlen(d)+strlen((*dir)->name)+1024));
|
|
|
93924e |
+ if (strlen(d)+strlen((*dir)->lnk)+2 > pathsize) path=xrealloc(path,pathsize=(strlen(d)+strlen((*dir)->lnk)+1024));
|
|
|
93924e |
if (fflag && !strcmp(d,"/")) sprintf(path,"%s%s",d,(*dir)->lnk);
|
|
|
93924e |
else sprintf(path,"%s/%s",d,(*dir)->lnk);
|
|
|
93924e |
listdir(path,dt,ft,lev+1,dev);
|
|
|
93924e |
@@ -253,7 +253,7 @@ off_t html_rlistdir(char *d, int *dt, int *ft, u_long lev, dev_t dev)
|
|
|
93924e |
{
|
|
|
93924e |
struct _info **dir;
|
|
|
93924e |
off_t size = 0;
|
|
|
93924e |
- char *err;
|
|
|
93924e |
+ char *err = NULL;
|
|
|
93924e |
|
|
|
93924e |
dir = getfulltree(d, lev, dev, &size, &err;;
|
|
|
93924e |
|
|
|
93924e |
@@ -261,6 +261,7 @@ off_t html_rlistdir(char *d, int *dt, int *ft, u_long lev, dev_t dev)
|
|
|
93924e |
|
|
|
93924e |
htmlr_listdir(dir, d, dt, ft, lev);
|
|
|
93924e |
|
|
|
93924e |
+ free(err);
|
|
|
93924e |
return size;
|
|
|
93924e |
}
|
|
|
93924e |
|
|
|
93924e |
diff --git a/json.c b/json.c
|
|
|
93924e |
index 4b15e0d..8c71324 100644
|
|
|
93924e |
--- a/json.c
|
|
|
93924e |
+++ b/json.c
|
|
|
93924e |
@@ -97,8 +97,7 @@ off_t json_listdir(char *d, int *dt, int *ft, u_long lev, dev_t dev)
|
|
|
93924e |
while(*dir) {
|
|
|
93924e |
if (!noindent) json_indent(lev);
|
|
|
93924e |
|
|
|
93924e |
- if ((*dir)->lnk) mt = (*dir)->mode & S_IFMT;
|
|
|
93924e |
- else mt = (*dir)->mode & S_IFMT;
|
|
|
93924e |
+ mt = (*dir)->mode & S_IFMT;
|
|
|
93924e |
for(t=0;ifmt[t];t++)
|
|
|
93924e |
if (ifmt[t] == mt) break;
|
|
|
93924e |
fprintf(outfile,"{\"type\":\"%s\"", ftype[t]);
|
|
|
93924e |
@@ -140,7 +139,7 @@ off_t json_listdir(char *d, int *dt, int *ft, u_long lev, dev_t dev)
|
|
|
93924e |
if (*(*dir)->lnk == '/')
|
|
|
93924e |
listdir((*dir)->lnk,dt,ft,lev+1,dev);
|
|
|
93924e |
else {
|
|
|
93924e |
- if (strlen(d)+strlen((*dir)->lnk)+2 > pathsize) path=xrealloc(path,pathsize=(strlen(d)+strlen((*dir)->name)+1024));
|
|
|
93924e |
+ if (strlen(d)+strlen((*dir)->lnk)+2 > pathsize) path=xrealloc(path,pathsize=(strlen(d)+strlen((*dir)->lnk)+1024));
|
|
|
93924e |
if (fflag && !strcmp(d,"/")) sprintf(path,"%s%s",d,(*dir)->lnk);
|
|
|
93924e |
else sprintf(path,"%s/%s",d,(*dir)->lnk);
|
|
|
93924e |
listdir(path,dt,ft,lev+1,dev);
|
|
|
93924e |
@@ -180,7 +179,7 @@ off_t json_rlistdir(char *d, int *dt, int *ft, u_long lev, dev_t dev)
|
|
|
93924e |
{
|
|
|
93924e |
struct _info **dir;
|
|
|
93924e |
off_t size = 0;
|
|
|
93924e |
- char *err;
|
|
|
93924e |
+ char *err = NULL;
|
|
|
93924e |
|
|
|
93924e |
dir = getfulltree(d, lev, dev, &size, &err;;
|
|
|
93924e |
|
|
|
93924e |
@@ -188,6 +187,7 @@ off_t json_rlistdir(char *d, int *dt, int *ft, u_long lev, dev_t dev)
|
|
|
93924e |
|
|
|
93924e |
jsonr_listdir(dir, d, dt, ft, lev);
|
|
|
93924e |
|
|
|
93924e |
+ free(err);
|
|
|
93924e |
return size;
|
|
|
93924e |
}
|
|
|
93924e |
|
|
|
93924e |
@@ -210,8 +210,7 @@ void jsonr_listdir(struct _info **dir, char *d, int *dt, int *ft, u_long lev)
|
|
|
93924e |
while(*dir) {
|
|
|
93924e |
if (!noindent) json_indent(lev);
|
|
|
93924e |
|
|
|
93924e |
- if ((*dir)->lnk) mt = (*dir)->mode & S_IFMT;
|
|
|
93924e |
- else mt = (*dir)->mode & S_IFMT;
|
|
|
93924e |
+ mt = (*dir)->mode & S_IFMT;
|
|
|
93924e |
for(t=0;ifmt[t];t++)
|
|
|
93924e |
if (ifmt[t] == mt) break;
|
|
|
93924e |
fprintf(outfile,"{\"type\":\"%s\"", ftype[t]);
|
|
|
93924e |
diff --git a/tree.c b/tree.c
|
|
|
93924e |
index 03140fe..73dd101 100644
|
|
|
93924e |
--- a/tree.c
|
|
|
93924e |
+++ b/tree.c
|
|
|
93924e |
@@ -851,7 +851,7 @@ struct _info **getfulltree(char *d, u_long lev, dev_t dev, off_t *size, char **e
|
|
|
93924e |
if (*(*dir)->lnk == '/')
|
|
|
93924e |
(*dir)->child = getfulltree((*dir)->lnk,lev+1,dev,&((*dir)->size),&((*dir)->err));
|
|
|
93924e |
else {
|
|
|
93924e |
- if (strlen(d)+strlen((*dir)->lnk)+2 > pathsize) path=xrealloc(path,pathsize=(strlen(d)+strlen((*dir)->name)+1024));
|
|
|
93924e |
+ if (strlen(d)+strlen((*dir)->lnk)+2 > pathsize) path=xrealloc(path,pathsize=(strlen(d)+strlen((*dir)->lnk)+1024));
|
|
|
93924e |
if (fflag && !strcmp(d,"/")) sprintf(path,"%s%s",d,(*dir)->lnk);
|
|
|
93924e |
else sprintf(path,"%s/%s",d,(*dir)->lnk);
|
|
|
93924e |
(*dir)->child = getfulltree(path,lev+1,dev,&((*dir)->size),&((*dir)->err));
|
|
|
93924e |
diff --git a/unix.c b/unix.c
|
|
|
93924e |
index ca5f76f..9476307 100644
|
|
|
93924e |
--- a/unix.c
|
|
|
93924e |
+++ b/unix.c
|
|
|
93924e |
@@ -128,7 +128,7 @@ off_t unix_listdir(char *d, int *dt, int *ft, u_long lev, dev_t dev)
|
|
|
93924e |
if (*(*dir)->lnk == '/')
|
|
|
93924e |
listdir((*dir)->lnk,dt,ft,lev+1,dev);
|
|
|
93924e |
else {
|
|
|
93924e |
- if (strlen(d)+strlen((*dir)->lnk)+2 > pathsize) path=xrealloc(path,pathsize=(strlen(d)+strlen((*dir)->name)+1024));
|
|
|
93924e |
+ if (strlen(d)+strlen((*dir)->lnk)+2 > pathsize) path=xrealloc(path,pathsize=(strlen(d)+strlen((*dir)->lnk)+1024));
|
|
|
93924e |
if (fflag && !strcmp(d,"/")) sprintf(path,"%s%s",d,(*dir)->lnk);
|
|
|
93924e |
else sprintf(path,"%s/%s",d,(*dir)->lnk);
|
|
|
93924e |
listdir(path,dt,ft,lev+1,dev);
|
|
|
93924e |
@@ -161,7 +161,7 @@ off_t unix_rlistdir(char *d, int *dt, int *ft, u_long lev, dev_t dev)
|
|
|
93924e |
{
|
|
|
93924e |
struct _info **dir;
|
|
|
93924e |
off_t size = 0;
|
|
|
93924e |
- char *err;
|
|
|
93924e |
+ char *err = NULL;
|
|
|
93924e |
|
|
|
93924e |
dir = getfulltree(d, lev, dev, &size, &err;;
|
|
|
93924e |
|
|
|
93924e |
@@ -169,6 +169,7 @@ off_t unix_rlistdir(char *d, int *dt, int *ft, u_long lev, dev_t dev)
|
|
|
93924e |
|
|
|
93924e |
r_listdir(dir, d, dt, ft, lev);
|
|
|
93924e |
|
|
|
93924e |
+ free(err);
|
|
|
93924e |
return size;
|
|
|
93924e |
}
|
|
|
93924e |
|
|
|
93924e |
diff --git a/xml.c b/xml.c
|
|
|
93924e |
index 32f3c0c..512eed7 100644
|
|
|
93924e |
--- a/xml.c
|
|
|
93924e |
+++ b/xml.c
|
|
|
93924e |
@@ -105,8 +105,7 @@ off_t xml_listdir(char *d, int *dt, int *ft, u_long lev, dev_t dev)
|
|
|
93924e |
while(*dir) {
|
|
|
93924e |
if (!noindent) xml_indent(lev);
|
|
|
93924e |
|
|
|
93924e |
- if ((*dir)->lnk) mt = (*dir)->mode & S_IFMT;
|
|
|
93924e |
- else mt = (*dir)->mode & S_IFMT;
|
|
|
93924e |
+ mt = (*dir)->mode & S_IFMT;
|
|
|
93924e |
for(t=0;ifmt[t];t++)
|
|
|
93924e |
if (ifmt[t] == mt) break;
|
|
|
93924e |
fprintf(outfile,"<%s", ftype[t]);
|
|
|
93924e |
@@ -144,7 +143,7 @@ off_t xml_listdir(char *d, int *dt, int *ft, u_long lev, dev_t dev)
|
|
|
93924e |
if (*(*dir)->lnk == '/')
|
|
|
93924e |
listdir((*dir)->lnk,dt,ft,lev+1,dev);
|
|
|
93924e |
else {
|
|
|
93924e |
- if (strlen(d)+strlen((*dir)->lnk)+2 > pathsize) path=xrealloc(path,pathsize=(strlen(d)+strlen((*dir)->name)+1024));
|
|
|
93924e |
+ if (strlen(d)+strlen((*dir)->lnk)+2 > pathsize) path=xrealloc(path,pathsize=(strlen(d)+strlen((*dir)->lnk)+1024));
|
|
|
93924e |
if (fflag && !strcmp(d,"/")) sprintf(path,"%s%s",d,(*dir)->lnk);
|
|
|
93924e |
else sprintf(path,"%s/%s",d,(*dir)->lnk);
|
|
|
93924e |
listdir(path,dt,ft,lev+1,dev);
|
|
|
93924e |
@@ -180,7 +179,7 @@ off_t xml_rlistdir(char *d, int *dt, int *ft, u_long lev, dev_t dev)
|
|
|
93924e |
{
|
|
|
93924e |
struct _info **dir;
|
|
|
93924e |
off_t size = 0;
|
|
|
93924e |
- char *err;
|
|
|
93924e |
+ char *err = NULL;
|
|
|
93924e |
|
|
|
93924e |
dir = getfulltree(d, lev, dev, &size, &err;;
|
|
|
93924e |
|
|
|
93924e |
@@ -188,6 +187,7 @@ off_t xml_rlistdir(char *d, int *dt, int *ft, u_long lev, dev_t dev)
|
|
|
93924e |
|
|
|
93924e |
xmlr_listdir(dir, d, dt, ft, lev);
|
|
|
93924e |
|
|
|
93924e |
+ free(err);
|
|
|
93924e |
return size;
|
|
|
93924e |
}
|
|
|
93924e |
|
|
|
93924e |
@@ -210,8 +210,7 @@ void xmlr_listdir(struct _info **dir, char *d, int *dt, int *ft, u_long lev)
|
|
|
93924e |
while(*dir) {
|
|
|
93924e |
if (!noindent) xml_indent(lev);
|
|
|
93924e |
|
|
|
93924e |
- if ((*dir)->lnk) mt = (*dir)->mode & S_IFMT;
|
|
|
93924e |
- else mt = (*dir)->mode & S_IFMT;
|
|
|
93924e |
+ mt = (*dir)->mode & S_IFMT;
|
|
|
93924e |
for(t=0;ifmt[t];t++)
|
|
|
93924e |
if (ifmt[t] == mt) break;
|
|
|
93924e |
fprintf(outfile,"<%s", ftype[t]);
|
|
|
93924e |
--
|
|
|
93924e |
2.17.2
|
|
|
93924e |
|