Skip to content

Commit

Permalink
fix cppcheck findings
Browse files Browse the repository at this point in the history
  • Loading branch information
vergoh committed Sep 5, 2024
1 parent 4e495b0 commit cc205e5
Show file tree
Hide file tree
Showing 11 changed files with 31 additions and 29 deletions.
8 changes: 4 additions & 4 deletions src/daemon.c
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ unsigned int addinterfaces(DSTATE *s)
void detectboot(DSTATE *s)
{
char buffer[32];
char *btime_buffer;
const char *btime_buffer;
uint64_t current_btime, db_btime;

current_btime = getbtime();
Expand Down Expand Up @@ -359,7 +359,7 @@ void preparedatabase(DSTATE *s)
unsigned int importlegacydbs(void)
{
DIR *dir;
struct dirent *di;
const struct dirent *di;
unsigned int importcount = 0;

if ((dir = opendir(cfg.dbdir)) == NULL) {
Expand Down Expand Up @@ -787,7 +787,7 @@ void cleanremovedinterfaces(DSTATE *s)

void rescandatabaseforinterfaces(DSTATE *s)
{
short interface_already_monitored = 0;
short interface_already_monitored;
uint64_t dbifcount = s->dbifcount;
datacache *iterator = NULL;
iflist *dbifl = NULL, *dbifl_iterator = NULL;
Expand Down Expand Up @@ -1076,7 +1076,7 @@ short getcurrenthour(void)
{
int ret = 0;
time_t current;
struct tm *stm;
const struct tm *stm;
char buffer[4];

current = time(NULL);
Expand Down
2 changes: 1 addition & 1 deletion src/dbaccess.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ int insertlegacydata(DATA *data, const char *iface)
{
int i, year;
time_t yeartime;
struct tm *stm;
const struct tm *stm;
uint64_t rx, tx;

if (!db_begintransaction()) {
Expand Down
2 changes: 1 addition & 1 deletion src/dbjson.c
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ void jsoninterfaceinfo(const interfaceinfo *ifaceinfo)

void jsondate(const time_t *date, const int type)
{
struct tm *d;
const struct tm *d;

d = localtime(date);

Expand Down
14 changes: 7 additions & 7 deletions src/dbshow.c
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ void showdb(const char *interface, int qmode, const char *databegin, const char

void showsummary(const interfaceinfo *ifaceinfo, const int shortmode)
{
struct tm *d;
const struct tm *d;
char datebuff[DATEBUFFLEN];
char todaystr[DATEBUFFLEN], yesterdaystr[DATEBUFFLEN];
char fieldseparator[8];
Expand Down Expand Up @@ -303,11 +303,11 @@ void showlist(const interfaceinfo *ifaceinfo, const char *listname, const char *
ListType listtype = LT_None;
int offset = 0, i = 1;
int estimatevisible = 0;
struct tm *d;
const struct tm *d;
time_t current;
char datebuff[DATEBUFFLEN], daybuff[DATEBUFFLEN];
char titlename[16], colname[8], stampformat[64];
uint64_t e_rx = 0, e_tx = 0, e_secs = 0;
uint64_t e_rx = 0, e_tx = 0, e_secs;
dbdatalist *datalist = NULL, *datalist_i = NULL;
dbdatalistinfo datainfo;

Expand Down Expand Up @@ -584,7 +584,7 @@ void showlist(const interfaceinfo *ifaceinfo, const char *listname, const char *

void showoneline(const interfaceinfo *ifaceinfo)
{
struct tm *d;
const struct tm *d;
char daytemp[DATEBUFFLEN];
uint64_t div;
dbdatalist *datalist = NULL;
Expand Down Expand Up @@ -688,7 +688,7 @@ void showhours(const interfaceinfo *ifaceinfo)
uint64_t max = 1;
char matrix[HGLINES][81]; /* width is one over 80 so that snprintf can write the end char */
char unit[4];
struct tm *d;
const struct tm *d;
dbdatalist *datalist = NULL, *datalist_i = NULL;
dbdatalistinfo datainfo;
HOURDATA hourdata[24];
Expand Down Expand Up @@ -841,7 +841,7 @@ void showhours(const interfaceinfo *ifaceinfo)
for (i = 0; i <= 7; i++) {
s = (int)tmax + i + 1;
for (j = 0; j < 3; j++) {
printf("%02d %" DECCONV "10.*f %" DECCONV "10.*f", ((unsigned int)s + (j * 8)) % 24,
printf("%02u %" DECCONV "10.*f %" DECCONV "10.*f", ((unsigned int)s + (j * 8)) % 24,
declen, (double)hourdata[((unsigned int)s + (j * 8)) % 24].rx / (double)div,
declen, (double)hourdata[((unsigned int)s + (j * 8)) % 24].tx / (double)div);

Expand Down Expand Up @@ -869,7 +869,7 @@ void showhours(const interfaceinfo *ifaceinfo)

void show95thpercentile(const interfaceinfo *ifaceinfo)
{
struct tm *d;
const struct tm *d;
char datebuff[DATEBUFFLEN];
percentiledata pdata;

Expand Down
2 changes: 1 addition & 1 deletion src/dbxml.c
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ void xmlpercentile(const interfaceinfo *ifaceinfo)

void xmldate(const time_t *date, const int type)
{
struct tm *d;
const struct tm *d;

d = localtime(date);

Expand Down
5 changes: 3 additions & 2 deletions src/fs.c
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,8 @@ int mkpath(const char *dir, const mode_t mode)
void preparevnstatdir(const char *dir, const char *user, const char *group)
{
size_t i, len, lastslash = 0;
char *path, *base;
char *path;
const char *base;

if (dir == NULL) {
return;
Expand Down Expand Up @@ -164,7 +165,7 @@ void updatedirowner(const char *dir, const char *user, const char *group)
void updatedirownerid(const char *dir, const uid_t uid, const gid_t gid)
{
DIR *d;
struct dirent *di;
const struct dirent *di;
struct stat statbuf;
char entryname[512];
int dir_fd, file_fd;
Expand Down
4 changes: 2 additions & 2 deletions src/id.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

uid_t getuser(const char *user)
{
struct passwd *pw;
const struct passwd *pw;
uid_t uid;

if (!strlen(user)) {
Expand Down Expand Up @@ -32,7 +32,7 @@ uid_t getuser(const char *user)

gid_t getgroup(const char *group)
{
struct group *gr;
const struct group *gr;
gid_t gid;

if (!strlen(group)) {
Expand Down
5 changes: 3 additions & 2 deletions src/ifinfo.c
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ int getiflist_linux(iflist **ifl, const int getspeed, const int validate)
char interface[MAXIFLEN];
FILE *fp;
DIR *dp;
struct dirent *di;
const struct dirent *di;
char procline[512];
uint32_t bwlimit = 0;

Expand Down Expand Up @@ -218,7 +218,8 @@ int getiflist_bsd(iflist **ifl, const int getspeed, const int validate)
int readproc(const char *iface)
{
FILE *fp;
char temp[4][64], procline[512], *proclineptr, ifaceid[MAXIFLEN + 1];
char temp[4][64], procline[512], ifaceid[MAXIFLEN + 1];
const char *proclineptr;
int check;

if ((fp = fopen(PROCNETDEV, "r")) == NULL) {
Expand Down
14 changes: 7 additions & 7 deletions src/image.c
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ int drawhours(IMAGECONTENT *ic, const int xpos, const int ypos, const int israte
double ratediv;
uint64_t max = 1, scaleunit = 0;
char buffer[32];
struct tm *d;
const struct tm *d;
dbdatalist *datalist = NULL, *datalist_i = NULL;
dbdatalistinfo datainfo;
HOURDATA hourdata[24];
Expand Down Expand Up @@ -315,10 +315,10 @@ void drawlist(IMAGECONTENT *ic, const char *listname)
int width, height, headermod, i = 1, rowcount = 0;
int estimateavailable = 0, estimatevisible = 0;
int32_t limit;
uint64_t e_rx = 0, e_tx = 0, e_secs = 0;
uint64_t e_rx = 0, e_tx = 0, e_secs;
char buffer[512], datebuff[16], daybuff[16];
char stampformat[64], titlename[16], colname[8];
struct tm *d;
const struct tm *d;
time_t current;
dbdatalist *datalist = NULL, *datalist_i = NULL;
dbdatalistinfo datainfo;
Expand Down Expand Up @@ -703,7 +703,7 @@ void drawsummary(IMAGECONTENT *ic, const int layout, const int israte)

void drawsummary_alltime(IMAGECONTENT *ic, const int x, const int y)
{
struct tm *d;
const struct tm *d;
char buffer[512], datebuff[16], daytemp[32];
gdFontPtr titlefont;

Expand Down Expand Up @@ -736,7 +736,7 @@ void drawsummary_digest(IMAGECONTENT *ic, const int x, const int y, const char *
double rxp, txp, mod;
char buffer[512], datebuff[16], daytemp[32];
time_t yesterday;
struct tm *d = NULL;
const struct tm *d = NULL;
dbdatalist *datalist = NULL;
dbdatalist *data_current = NULL, *data_previous = NULL;
dbdatalistinfo datainfo;
Expand Down Expand Up @@ -932,7 +932,7 @@ int drawfiveminutes(IMAGECONTENT *ic, const int xpos, const int ypos, const int
time_t timestamp;
double ratediv, e;
char buffer[32];
struct tm *d;
const struct tm *d;
dbdatalist *datalist = NULL, *datalist_i = NULL;
dbdatalistinfo datainfo;
gdFontPtr font;
Expand Down Expand Up @@ -1142,7 +1142,7 @@ void drawpercentile(IMAGECONTENT *ic, const int mode, const int xpos, const int
int i, l, x = xpos, y = ypos, s = 0, step = 0, prev = 0, last = 0, color;
uint64_t scaleunit, max, percentile;
double ratediv, percentileratediv;
struct tm *d;
const struct tm *d;
time_t current;
char datebuff[DATEBUFFLEN];
dbdatalist *datalist = NULL, *datalist_i = NULL;
Expand Down
2 changes: 1 addition & 1 deletion src/image_support.c
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ void colorinitcheck(const char *color, const int value, const char *cfgtext, con

void layoutinit(IMAGECONTENT *ic, const char *title, const int width, const int height)
{
struct tm *d;
const struct tm *d;
char datestring[64], buffer[512];
gdFontPtr datefont;

Expand Down
2 changes: 1 addition & 1 deletion src/percentile.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ int getpercentiledata(percentiledata *pdata, const char *iface, const uint64_t u
{
uint32_t entry = 0, entrylimit;
uint64_t *rxdata, *txdata, *sumdata;
struct tm *d;
const struct tm *d;
char datebuff[DATEBUFFLEN];
dbdatalist *datalist = NULL, *datalist_i = NULL;
dbdatalistinfo datainfo;
Expand Down

0 comments on commit cc205e5

Please sign in to comment.