Skip to content

Commit

Permalink
fix clang and cppcheck findings
Browse files Browse the repository at this point in the history
  • Loading branch information
vergoh committed Sep 6, 2024
1 parent cc205e5 commit ebd20dc
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 50 deletions.
2 changes: 1 addition & 1 deletion src/clicommon.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ void showdbiflist(const int mode)
}

if (mode == 2) {
dbifcount = db_getinterfacecount();
dbifcount = (int)db_getinterfacecount();
printf("%d\n", dbifcount);
db_close();
return;
Expand Down
34 changes: 17 additions & 17 deletions src/dbjson.c
Original file line number Diff line number Diff line change
Expand Up @@ -137,15 +137,15 @@ void jsonpercentile(const interfaceinfo *ifaceinfo)
printf("\"seen\":%" PRIu32 ",", pdata.count);
printf("\"expected\":%" PRIu32 ",", pdata.countexpectation);
printf("\"missing\":%" PRIu32 ",", pdata.countexpectation - pdata.count);
printf("\"coverage_percentage\":%0.1f", (float)pdata.count / (float)pdata.countexpectation * 100.0);
printf("\"coverage_percentage\":%0.1f", pdata.count / (double)pdata.countexpectation * 100.0);
printf("},");

jsonpercentileminavgmax(&pdata);

printf("\"95th_percentile\":{");
printf("\"rx_bytes_per_second\":%" PRIu64 ",", (uint64_t)(pdata.rxpercentile / (double)300));
printf("\"tx_bytes_per_second\":%" PRIu64 ",", (uint64_t)(pdata.txpercentile / (double)300));
printf("\"total_bytes_per_second\":%" PRIu64 "", (uint64_t)(pdata.sumpercentile / (double)300));
printf("\"rx_bytes_per_second\":%" PRIu64 ",", (uint64_t)((double)pdata.rxpercentile / (double)300));
printf("\"tx_bytes_per_second\":%" PRIu64 ",", (uint64_t)((double)pdata.txpercentile / (double)300));
printf("\"total_bytes_per_second\":%" PRIu64 "", (uint64_t)((double)pdata.sumpercentile / (double)300));
printf("}");

printf("}");
Expand All @@ -154,21 +154,21 @@ void jsonpercentile(const interfaceinfo *ifaceinfo)
void jsonpercentileminavgmax(const percentiledata *pdata)
{
printf("\"minimum\":{");
printf("\"rx_bytes_per_second\":%" PRIu64 ",", (uint64_t)(pdata->minrx / (double)300));
printf("\"tx_bytes_per_second\":%" PRIu64 ",", (uint64_t)(pdata->mintx / (double)300));
printf("\"total_bytes_per_second\":%" PRIu64 "", (uint64_t)(pdata->min / (double)300));
printf("\"rx_bytes_per_second\":%" PRIu64 ",", (uint64_t)((double)pdata->minrx / (double)300));
printf("\"tx_bytes_per_second\":%" PRIu64 ",", (uint64_t)((double)pdata->mintx / (double)300));
printf("\"total_bytes_per_second\":%" PRIu64 "", (uint64_t)((double)pdata->min / (double)300));
printf("},");

printf("\"average\":{");
printf("\"rx_bytes_per_second\":%" PRIu64 ",", (uint64_t)(pdata->sumrx / (double)(pdata->count * 300)));
printf("\"tx_bytes_per_second\":%" PRIu64 ",", (uint64_t)(pdata->sumtx / (double)(pdata->count * 300)));
printf("\"total_bytes_per_second\":%" PRIu64 "", (uint64_t)((pdata->sumrx + pdata->sumtx) / (double)(pdata->count * 300)));
printf("\"rx_bytes_per_second\":%" PRIu64 ",", (uint64_t)((double)pdata->sumrx / (double)(pdata->count * 300)));
printf("\"tx_bytes_per_second\":%" PRIu64 ",", (uint64_t)((double)pdata->sumtx / (double)(pdata->count * 300)));
printf("\"total_bytes_per_second\":%" PRIu64 "", (uint64_t)(((double)pdata->sumrx + (double)pdata->sumtx) / (double)(pdata->count * 300)));
printf("},");

printf("\"maximum\":{");
printf("\"rx_bytes_per_second\":%" PRIu64 ",", (uint64_t)(pdata->maxrx / (double)300));
printf("\"tx_bytes_per_second\":%" PRIu64 ",", (uint64_t)(pdata->maxtx / (double)300));
printf("\"total_bytes_per_second\":%" PRIu64 "", (uint64_t)(pdata->max / (double)300));
printf("\"rx_bytes_per_second\":%" PRIu64 ",", (uint64_t)((double)pdata->maxrx / (double)300));
printf("\"tx_bytes_per_second\":%" PRIu64 ",", (uint64_t)((double)pdata->maxtx / (double)300));
printf("\"total_bytes_per_second\":%" PRIu64 "", (uint64_t)((double)pdata->max / (double)300));
printf("},");
}

Expand Down Expand Up @@ -313,16 +313,16 @@ void jsonpercentilealert(const alertdata *adata, const AlertCondition condition,
printf("\"seen\":%" PRIu32 ",", adata->pdata.count);
printf("\"expected\":%" PRIu32 ",", adata->pdata.countexpectation);
printf("\"missing\":%" PRIu32 ",", adata->pdata.countexpectation - adata->pdata.count);
printf("\"coverage_percentage\":%0.1f,", (float)adata->pdata.count / (float)adata->pdata.countexpectation * 100.0);
printf("\"coverage_percentage\":%0.1f,", adata->pdata.count / (double)adata->pdata.countexpectation * 100.0);
if (condition == AC_RX) {
printf("\"over_limit\":%" PRIu32 ",", adata->pdata.countrxoveruserlimit);
printf("\"over_limit_percentage\":%0.1f", (float)adata->pdata.countrxoveruserlimit / (float)adata->pdata.count * 100.0);
printf("\"over_limit_percentage\":%0.1f", adata->pdata.countrxoveruserlimit / (double)adata->pdata.count * 100.0);
} else if (condition == AC_TX) {
printf("\"over_limit\":%" PRIu32 ",", adata->pdata.counttxoveruserlimit);
printf("\"over_limit_percentage\":%0.1f", (float)adata->pdata.counttxoveruserlimit / (float)adata->pdata.count * 100.0);
printf("\"over_limit_percentage\":%0.1f", adata->pdata.counttxoveruserlimit / (double)adata->pdata.count * 100.0);
} else if (condition == AC_Total) {
printf("\"over_limit\":%" PRIu32 ",", adata->pdata.countsumoveruserlimit);
printf("\"over_limit_percentage\":%0.1f", (float)adata->pdata.countsumoveruserlimit / (float)adata->pdata.count * 100.0);
printf("\"over_limit_percentage\":%0.1f", adata->pdata.countsumoveruserlimit / (double)adata->pdata.count * 100.0);
}
printf("}");

Expand Down
16 changes: 8 additions & 8 deletions src/dbshow.c
Original file line number Diff line number Diff line change
Expand Up @@ -912,7 +912,7 @@ void show95thpercentile(const interfaceinfo *ifaceinfo)
if (pdata.count == pdata.countexpectation) {
printf(", 100%% coverage)");
} else {
printf(", %0.1f%% coverage)", (float)pdata.count / (float)pdata.countexpectation * 100.0);
printf(", %0.1f%% coverage)", pdata.count / (double)pdata.countexpectation * 100.0);
}
printf("\n\n");

Expand Down Expand Up @@ -1059,7 +1059,7 @@ int showalert(const char *interface, const AlertOutput output, const AlertExit a
if (type != AT_Percentile) {
adata.used = adata.datalist->rx;
} else {
adata.used = (uint64_t)(adata.pdata.rxpercentile / (double)300);
adata.used = (uint64_t)((double)adata.pdata.rxpercentile / (double)300);
}
snprintf(adata.conditionname, 16, "rx");
if (type != AT_Percentile && cfg.estimatevisible) {
Expand All @@ -1071,7 +1071,7 @@ int showalert(const char *interface, const AlertOutput output, const AlertExit a
if (type != AT_Percentile) {
adata.used = adata.datalist->tx;
} else {
adata.used = (uint64_t)(adata.pdata.txpercentile / (double)300);
adata.used = (uint64_t)((double)adata.pdata.txpercentile / (double)300);
}
snprintf(adata.conditionname, 16, "tx");
if (type != AT_Percentile && cfg.estimatevisible) {
Expand All @@ -1083,7 +1083,7 @@ int showalert(const char *interface, const AlertOutput output, const AlertExit a
if (type != AT_Percentile) {
adata.used = adata.datalist->rx + adata.datalist->tx;
} else {
adata.used = (uint64_t)(adata.pdata.sumpercentile / (double)300);
adata.used = (uint64_t)((double)adata.pdata.sumpercentile / (double)300);
}
snprintf(adata.conditionname, 16, "total");
if (type != AT_Percentile && cfg.estimatevisible) {
Expand Down Expand Up @@ -1309,17 +1309,17 @@ void alertoutput(const alertdata *adata, const AlertOutput output, const AlertTy

snprintf(linebuffer, 128, "%" PRIu32 " entries", adata->pdata.count);
if (condition == AC_RX) {
snprintf(buffer, 32, ", %" PRIu32 " (%0.1f%%) over limit", adata->pdata.countrxoveruserlimit, (float)adata->pdata.countrxoveruserlimit / (float)adata->pdata.count * 100.0);
snprintf(buffer, 32, ", %" PRIu32 " (%0.1f%%) over limit", adata->pdata.countrxoveruserlimit, adata->pdata.countrxoveruserlimit / (double)adata->pdata.count * 100.0);
} else if (condition == AC_TX) {
snprintf(buffer, 32, ", %" PRIu32 " (%0.1f%%) over limit", adata->pdata.counttxoveruserlimit, (float)adata->pdata.counttxoveruserlimit / (float)adata->pdata.count * 100.0);
snprintf(buffer, 32, ", %" PRIu32 " (%0.1f%%) over limit", adata->pdata.counttxoveruserlimit, adata->pdata.counttxoveruserlimit / (double)adata->pdata.count * 100.0);
} else if (condition == AC_Total) {
snprintf(buffer, 32, ", %" PRIu32 " (%0.1f%%) over limit", adata->pdata.countsumoveruserlimit, (float)adata->pdata.countsumoveruserlimit / (float)adata->pdata.count * 100.0);
snprintf(buffer, 32, ", %" PRIu32 " (%0.1f%%) over limit", adata->pdata.countsumoveruserlimit, adata->pdata.countsumoveruserlimit / (double)adata->pdata.count * 100.0);
}
strncat(linebuffer, buffer, 32);
if (adata->pdata.count == adata->pdata.countexpectation) {
snprintf(buffer, 32, ", 100%% coverage");
} else {
snprintf(buffer, 32, ", %0.1f%% coverage", (float)adata->pdata.count / (float)adata->pdata.countexpectation * 100.0);
snprintf(buffer, 32, ", %0.1f%% coverage", adata->pdata.count / (double)adata->pdata.countexpectation * 100.0);
}
strncat(linebuffer, buffer, 32);
printf("%*s%s\n", (int)(5 + (61 - strlen(linebuffer)) / 2), " ", linebuffer);
Expand Down
24 changes: 12 additions & 12 deletions src/dbxml.c
Original file line number Diff line number Diff line change
Expand Up @@ -129,27 +129,27 @@ void xmlpercentile(const interfaceinfo *ifaceinfo)
printf(" <entries><seen>%" PRIu32 "</seen><expected>%" PRIu32 "</expected><missing>%" PRIu32 "</missing></entries>\n", pdata.count, pdata.countexpectation, pdata.countexpectation-pdata.count);

printf(" <minimum>");
printf("<rx_bytes_per_second>%" PRIu64 "</rx_bytes_per_second>", (uint64_t)(pdata.minrx / (double)300));
printf("<tx_bytes_per_second>%" PRIu64 "</tx_bytes_per_second>", (uint64_t)(pdata.mintx / (double)300));
printf("<total_bytes_per_second>%" PRIu64 "</total_bytes_per_second>", (uint64_t)(pdata.min / (double)300));
printf("<rx_bytes_per_second>%" PRIu64 "</rx_bytes_per_second>", (uint64_t)((double)pdata.minrx / (double)300));
printf("<tx_bytes_per_second>%" PRIu64 "</tx_bytes_per_second>", (uint64_t)((double)pdata.mintx / (double)300));
printf("<total_bytes_per_second>%" PRIu64 "</total_bytes_per_second>", (uint64_t)((double)pdata.min / (double)300));
printf("</minimum>\n");

printf(" <average>");
printf("<rx_bytes_per_second>%" PRIu64 "</rx_bytes_per_second>", (uint64_t)(pdata.sumrx / (double)(pdata.count * 300)));
printf("<tx_bytes_per_second>%" PRIu64 "</tx_bytes_per_second>", (uint64_t)(pdata.sumtx / (double)(pdata.count * 300)));
printf("<total_bytes_per_second>%" PRIu64 "</total_bytes_per_second>", (uint64_t)(pdata.sumrx + pdata.sumtx / (double)(pdata.count * 300)));
printf("<rx_bytes_per_second>%" PRIu64 "</rx_bytes_per_second>", (uint64_t)((double)pdata.sumrx / (double)(pdata.count * 300)));
printf("<tx_bytes_per_second>%" PRIu64 "</tx_bytes_per_second>", (uint64_t)((double)pdata.sumtx / (double)(pdata.count * 300)));
printf("<total_bytes_per_second>%" PRIu64 "</total_bytes_per_second>", (uint64_t)((double)pdata.sumrx + (double)pdata.sumtx / (double)(pdata.count * 300)));
printf("</average>\n");

printf(" <maximum>");
printf("<rx_bytes_per_second>%" PRIu64 "</rx_bytes_per_second>", (uint64_t)(pdata.maxrx / (double)300));
printf("<tx_bytes_per_second>%" PRIu64 "</tx_bytes_per_second>", (uint64_t)(pdata.maxtx / (double)300));
printf("<total_bytes_per_second>%" PRIu64 "</total_bytes_per_second>", (uint64_t)(pdata.max / (double)300));
printf("<rx_bytes_per_second>%" PRIu64 "</rx_bytes_per_second>", (uint64_t)((double)pdata.maxrx / (double)300));
printf("<tx_bytes_per_second>%" PRIu64 "</tx_bytes_per_second>", (uint64_t)((double)pdata.maxtx / (double)300));
printf("<total_bytes_per_second>%" PRIu64 "</total_bytes_per_second>", (uint64_t)((double)pdata.max / (double)300));
printf("</maximum>\n");

printf(" <95th_percentile>");
printf("<rx_bytes_per_second>%" PRIu64 "</rx_bytes_per_second>", (uint64_t)(pdata.rxpercentile / (double)300));
printf("<tx_bytes_per_second>%" PRIu64 "</tx_bytes_per_second>", (uint64_t)(pdata.txpercentile / (double)300));
printf("<total_bytes_per_second>%" PRIu64 "</total_bytes_per_second>", (uint64_t)(pdata.sumpercentile / (double)300));
printf("<rx_bytes_per_second>%" PRIu64 "</rx_bytes_per_second>", (uint64_t)((double)pdata.rxpercentile / (double)300));
printf("<tx_bytes_per_second>%" PRIu64 "</tx_bytes_per_second>", (uint64_t)((double)pdata.txpercentile / (double)300));
printf("<total_bytes_per_second>%" PRIu64 "</total_bytes_per_second>", (uint64_t)((double)pdata.sumpercentile / (double)300));
printf("</95th_percentile>\n");

printf(" </bandwidth>\n");
Expand Down
6 changes: 3 additions & 3 deletions src/image.c
Original file line number Diff line number Diff line change
Expand Up @@ -738,7 +738,7 @@ void drawsummary_digest(IMAGECONTENT *ic, const int x, const int y, const char *
time_t yesterday;
const struct tm *d = NULL;
dbdatalist *datalist = NULL;
dbdatalist *data_current = NULL, *data_previous = NULL;
const dbdatalist *data_current = NULL, *data_previous = NULL;
dbdatalistinfo datainfo;
gdFontPtr titlefont;

Expand Down Expand Up @@ -1304,9 +1304,9 @@ void drawpercentile(IMAGECONTENT *ic, const int mode, const int xpos, const int
printf("s: %d\n", s);
printf("l: %d\n", l);
printf("h: %d\n", height);
printf("p: %" PRIu64 "\n", (uint64_t)(percentile / percentileratediv));
printf("p: %" PRIu64 "\n", (uint64_t)((double)percentile / percentileratediv));
printf("max: %" PRIu64 "\n", max);
printf("max rate: %s\n", gettrafficrate(max * ratediv, 3600, 0));
printf("max rate: %s\n", gettrafficrate((uint64_t)((double)max * ratediv), 3600, 0));
printf("per rate: %s\n", gettrafficrate(percentile, 300, 0));
}

Expand Down
6 changes: 3 additions & 3 deletions src/percentile.c
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ int getpercentiledata(percentiledata *pdata, const char *iface, const uint64_t u
pdata->maxtx = datainfo.maxtx;
pdata->max = datainfo.max;

entrylimit = lrint(datainfo.count * (float)0.95) - 1;
entrylimit = (uint32_t)lrint(datainfo.count * (double)0.95) - 1;

if (debug) {
printf("Entry expectation: %" PRIu32 "\n", pdata->countexpectation);
Expand Down Expand Up @@ -134,9 +134,9 @@ int getpercentiledata(percentiledata *pdata, const char *iface, const uint64_t u

int compare_uint64_t(const void *a, const void *b)
{
if (*(uint64_t *)a < *(uint64_t *)b) {
if (*(const uint64_t *)a < *(const uint64_t *)b) {
return -1;
} else if (*(uint64_t *)a > *(uint64_t *)b) {
} else if (*(const uint64_t *)a > *(const uint64_t *)b) {
return 1;
}
return 0;
Expand Down
12 changes: 6 additions & 6 deletions tests/percentile_tests.c
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,8 @@ END_TEST

START_TEST(getpercentiledata_can_provide_data_with_many_entries)
{
int ret, i;
uint64_t entry;
int ret;
uint64_t entry, i;
percentiledata pdata;

entry = get_timestamp(2001, 1, 1, 0, 0);
Expand Down Expand Up @@ -199,8 +199,8 @@ END_TEST

START_TEST(getpercentiledata_can_provide_data_with_many_entries_and_order_does_not_matter)
{
int ret, i;
uint64_t entry;
int ret;
uint64_t entry, i;
percentiledata pdata;

entry = get_timestamp(2001, 1, 1, 0, 0);
Expand Down Expand Up @@ -252,8 +252,8 @@ END_TEST

START_TEST(getpercentiledata_can_check_limit)
{
int ret, i;
uint64_t entry;
int ret;
uint64_t entry, i;
percentiledata pdata;

entry = get_timestamp(2001, 1, 1, 0, 0);
Expand Down

0 comments on commit ebd20dc

Please sign in to comment.