From 61352c7c3e9856d3ae89e40495661acd8e814cc4 Mon Sep 17 00:00:00 2001 From: Silvan Calarco Date: Fri, 19 Jun 2020 10:44:26 +0200 Subject: [PATCH] Optimization warning fixes --- src/CMakeLists.txt | 2 +- src/changelog.c | 2 +- src/functions.c | 22 ++++++++++---------- src/include/functions.h | 2 +- src/include/reports.h | 9 ++++----- src/reports.c | 45 ++++++++++++++++++++--------------------- src/rpmfunctions.c | 3 +-- 7 files changed, 41 insertions(+), 44 deletions(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 01d5e96..fa43067 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -44,7 +44,7 @@ target_link_libraries(distromatic ${LIBIBERTY} ) target_include_directories(distromatic PUBLIC ${RPM_INCLUDE_DIRS}) -target_compile_options(distromatic PUBLIC -g -Wall -std=gnu11 -pedantic ${RPM_CFLAGS_OTHER}) +target_compile_options(distromatic PUBLIC -O2 -g -Wall -std=gnu11 -pedantic ${RPM_CFLAGS_OTHER}) add_executable(distroquery distroquery.c diff --git a/src/changelog.c b/src/changelog.c index a4b65cd..1eca950 100644 --- a/src/changelog.c +++ b/src/changelog.c @@ -142,7 +142,7 @@ getPackageChangelog(Header h, struct headerSourceList* headersource) newchangelog->time = changelogtime[i]; - strncpy(changelogname, changelogrelease[i], 255); + strcpy(changelogname, changelogrelease[i]); endp = strchr(changelogname, '>'); if (endp) { endp[1] = '\0'; diff --git a/src/functions.c b/src/functions.c index 3155377..3e51957 100644 --- a/src/functions.c +++ b/src/functions.c @@ -164,7 +164,7 @@ struct configTag* read_configuration(const char *confFile) newconfigtag->configdefaults = &configdefaults; if (configdefaults.html_basedir) { - strncpy(buf, configdefaults.html_basedir, PATH_MAX); + strcpy(buf, configdefaults.html_basedir); strncat(buf, newconfigtag->tag, sizeof(buf) - strlen(buf)); strncat(buf, "/", sizeof(buf) - strlen(buf)); newconfigtag->html_dir = (char *) strdup(buf); @@ -318,7 +318,7 @@ struct configTag* read_configuration(const char *confFile) } if (!currconfigtag->repository_source_dir) { - strncpy(buf, currconfigtag->repository_dir, PATH_MAX); + strcpy(buf, currconfigtag->repository_dir); strncat(buf, "/SRPMS.base/", sizeof(buf) - strlen(buf)); currconfigtag->repository_source_dir = (char *) strdup(buf); @@ -426,7 +426,7 @@ void logmsg(int level, const char *msg, ...) { break; } if ((level == LOG_WARNING) || (level == LOG_ERROR)) { - strncpy(oldmsg[curroldmsg++],newmsg,256); + strncpy(oldmsg[curroldmsg++],newmsg,PATH_MAX); if (curroldmsg >= 20) curroldmsg = 0; } } @@ -488,20 +488,20 @@ fprintf_depstable_filtered_var(FILE* f,char* st) { char *humanSize(long long sbytes, sizeString *s) { if (sbytes < 1024) { - snprintf((char *)s, SSSIZE, "%lld B", sbytes); - return (char *)s; + snprintf((char *)s, SSSIZE, "%lld B", sbytes); + return (char *)s; } if ((sbytes / 1024) < 1024) { - snprintf((char *)s, SSSIZE, "%.2f KB", sbytes / 1024.0); - return (char*)s; + snprintf((char *)s, SSSIZE, "%.2f KB", sbytes / 1024.0); + return (char*)s; } if ((sbytes / 1024 / 1024 ) < 1024) { - snprintf((char *)s, SSSIZE, "%.2f MB", sbytes / 1024.0 / 1024.0); - return (char*)s; + snprintf((char *)s, SSSIZE, "%.2f MB", sbytes / 1024.0 / 1024.0); + return (char*)s; } if ((sbytes / 1024 / 1024 / 1024 ) < 1024) { - snprintf((char *)s, SSSIZE, "%.2f GB", sbytes / 1024.0 / 1024.0 / 1024.0); - return (char*)s; + snprintf((char *)s, SSSIZE, "%.2f GB", sbytes / 1024.0 / 1024.0 / 1024.0); + return (char*)s; } snprintf((char *)s, SSSIZE, "%.2f TB", sbytes / 1024.0 / 1024.0 / 1024.0 / 1024.0); return (char*)s; diff --git a/src/include/functions.h b/src/include/functions.h index 1a50128..3b301e3 100644 --- a/src/include/functions.h +++ b/src/include/functions.h @@ -11,7 +11,7 @@ #include #define HDSIZE 16 -#define SSSIZE 16 +#define SSSIZE 24 typedef char humanDate[HDSIZE]; typedef char sizeString[SSSIZE]; diff --git a/src/include/reports.h b/src/include/reports.h index 3d9afb7..3afd7c2 100644 --- a/src/include/reports.h +++ b/src/include/reports.h @@ -26,14 +26,13 @@ int cleanHTMLFiles(struct configTag *ct); int generateHTMLFiles(struct configTag *configtag,int arch); int generateHTML_SRPMSFiles(struct configTag *configtag); int generateHTMLMainIndex(struct configTag *configtag); -char *groupdirname(char *group,char *dest,unsigned int max); int write_RPM_HTML(struct configTag *ct,FILE *fout, struct headerList *currheaderlist); int print_contentslist(struct configTag *ct, int arch); int print_datatables(struct configTag *ct, int arch); -char *ftname(struct fileTree* ft, char* buf, unsigned int bufsize); -void print_contents_subtree(FILE *f, - struct fileTree* ft, - struct configTag* ct, +char *ftname(struct fileTree* ft, char* buf); +void print_contents_subtree(FILE *f, + struct fileTree* ft, + struct configTag* ct, char* buf, int bufsize); int generatePkgList(struct configTag *ct, int arch); int generateSrcPkgList(struct configTag *ct); diff --git a/src/reports.c b/src/reports.c index acffd84..3d4a8f3 100644 --- a/src/reports.c +++ b/src/reports.c @@ -41,13 +41,13 @@ #define HTMLOLDSTATS_NUM 400 #define RSSSTATS_NUM 20 -char *groupdirname(char *group,char *dest,unsigned int max) +char *groupdirname(char *group,char *dest) { - strncpy(dest,group,max); + strcpy(dest,group); unsigned int i=0; - while (dest[i] && ihtml_dir, - groupdirname(configtag->stats.headersourcelistvec[i]->group,buffer,PATH_MAX)); + groupdirname(configtag->stats.headersourcelistvec[i]->group,buffer)); if (stat(outfile,&buf)) { if (mkdir(outfile,S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH)) { @@ -484,7 +484,7 @@ generateStats(struct configTag *configtag,int arch) "%s (%d)
\n", configtag->configdefaults->url_prefix, configtag->tag, - groupdirname(configtag->stats.headersourcelistvec[i-1]->group,buffer,PATH_MAX), + groupdirname(configtag->stats.headersourcelistvec[i-1]->group,buffer), (configtag->stats.headersourcelistvec)[i-1]->group, pkgnum); pkgnum=0; @@ -497,7 +497,7 @@ generateStats(struct configTag *configtag,int arch) fclose(groupout); } - strncpy(outfile, configtag->html_dir, PATH_MAX); + strcpy(outfile, configtag->html_dir); strncat(outfile, "_recent.inc", sizeof(outfile) - strlen(outfile)); if ((htmlout = fopen(outfile, "w")) == NULL) { perror(outfile); @@ -513,7 +513,7 @@ generateStats(struct configTag *configtag,int arch) fprintf(htmlout, "Recent builds:
\n"); }*/ - strncpy(outfile, configtag->html_dir, PATH_MAX); + strcpy(outfile, configtag->html_dir); strncat(outfile, "_oldest.inc", sizeof(outfile) - strlen(outfile)); if ((htmloldout = fopen(outfile, "w")) == NULL) { perror(outfile); @@ -524,7 +524,7 @@ generateStats(struct configTag *configtag,int arch) fprintf(htmloldout, "Oldest builds:
\n"); }*/ - strncpy(rssfile, configtag->html_dir, PATH_MAX); + strcpy(rssfile, configtag->html_dir); strncat(rssfile, "recent.rss", sizeof(rssfile) - strlen(rssfile)); if ((rssout = fopen(rssfile, "w")) == NULL) { perror(rssfile); @@ -651,7 +651,7 @@ generateStats(struct configTag *configtag,int arch) } else { /* remove final slashes from download_prefix as required by apt */ - strncpy(buffer, configtag->download_dir, PATH_MAX); + strcpy(buffer, configtag->download_dir); i=strlen(buffer); while ((i > 0) && (buffer[i-1] == '/' )) { @@ -690,7 +690,7 @@ generateStats(struct configTag *configtag,int arch) return 1; } else { /* remove final slashes from download_prefix as required by apt */ - strncpy(buffer, configtag->download_dir, PATH_MAX); + strcpy(buffer, configtag->download_dir); i=strlen(buffer); while ((i > 0) && (buffer[i-1] == '/' )) { @@ -753,7 +753,7 @@ generateHTMLMainIndex(struct configTag *configtag) return 2; } - strncpy(indexfile, configtag->configdefaults->html_basedir, PATH_MAX); + strcpy(indexfile, configtag->configdefaults->html_basedir); strncat(indexfile, "_index.inc", sizeof(indexfile) - strlen(indexfile)); if ((fout = fopen(indexfile, "w")) == NULL) { @@ -789,7 +789,7 @@ generateHTMLMainIndex(struct configTag *configtag) configtag->description); /* remove final slashes from download_prefix as required by apt */ - strncpy(buffer, configtag->download_dir, PATH_MAX); + strcpy(buffer, configtag->download_dir); i=strlen(buffer); while ((i > 0) && (buffer[i-1] == '/' )) { buffer[i-1]='\0'; @@ -987,7 +987,7 @@ generateHTML_SRPMSFiles(struct configTag *configtag) "Group:%s\n", configtag->configdefaults->url_prefix, configtag->tag, - groupdirname(currheadersourcelist->group, buffer2, PATH_MAX), + groupdirname(currheadersourcelist->group, buffer2), htmlclean(currheadersourcelist->group,buffer,PATH_MAX)); fprintf(fout, @@ -1096,7 +1096,7 @@ generateHTML_SRPMSFiles(struct configTag *configtag) fprintf(findexout[idx],"%s: %s",currheadersourcelist->name,htmlclean(currheadersourcelist->summary,buffer,PATH_MAX)); st=strstr(currheadersourcelist->url,"://"); if (st) { - strncpy(buffer,st+3,PATH_MAX); + strcpy(buffer,st+3); st=strchr(buffer,'/'); if (st) st[0]='\0'; fprintf(findexout[idx], @@ -1346,7 +1346,7 @@ cleanHTMLFiles(struct configTag *ct) while (currheadersourcelist) { snprintf(dir, PATH_MAX, "%sgroups/%s", ct->html_dir, - groupdirname(currheadersourcelist->group,uf,PATH_MAX)); + groupdirname(currheadersourcelist->group,uf)); if (!stat(dir,&buf)) { logmsg(LOG_DEBUG,"removing directory %s",dir); @@ -1363,7 +1363,7 @@ cleanHTMLFiles(struct configTag *ct) /* legacy: clean old group dirs */ snprintf(dir, PATH_MAX, "%s%s", ct->html_dir, - groupdirname(currheadersourcelist->group,uf,PATH_MAX)); + groupdirname(currheadersourcelist->group,uf)); if (!stat(dir,&buf)) { logmsg(LOG_DEBUG,"removing legacy directory %s",dir); @@ -1696,8 +1696,7 @@ generateHTMLFiles(struct configTag *ct, int arch) fprintf(fout, "Filenames:"); for (i = 0; i < currheaderlist->filenamecount; i++) { - ftname((currheaderlist->file)[i], - buffer, PATH_MAX); + ftname((currheaderlist->file)[i], buffer); fprintf(fout, "/%s ",buffer); } @@ -1710,19 +1709,19 @@ generateHTMLFiles(struct configTag *ct, int arch) return 0; } -char *ftname(struct fileTree* ft, char* buf, unsigned int bufsize) { +char *ftname(struct fileTree* ft, char* buf) { buf[0]='\0'; int l; if (ft) { - strncpy(buf,ft->name,bufsize); + strcpy(buf,ft->name); ft=ft->parent; } while (ft) { l=strlen(ft->name); - if (strlen(buf)+l+1 <= bufsize) { + if (strlen(buf)+l+1 <= PATH_MAX) { memmove(buf+l+1,buf,strlen(buf)+1); memcpy(buf,ft->name,l); buf[l]='/'; @@ -1747,7 +1746,7 @@ void print_contents_subtree(FILE *f, ((ft->provider[k]) && (ft->provider[k]->sourceheader) && (ft->provider[k]->altrepository == ct->repository_level))) { - ftname(ft,buf,bufsize); + ftname(ft,buf); if ((j=strlen(buf)) < 60) { for (i=(60-j)/8; i>0; i--) strncat(buf, "\t", bufsize - strlen(buf)); while (strlen(buf) < 60) strncat(buf, " ", bufsize - strlen(buf)); diff --git a/src/rpmfunctions.c b/src/rpmfunctions.c index 7c8324e..8f7c659 100644 --- a/src/rpmfunctions.c +++ b/src/rpmfunctions.c @@ -147,7 +147,7 @@ headerGetStringEntry(Header h, const int tag) char ** headerGetStringArrayEntry(Header h, const int tag, int* count) { - char **st; + char **st = NULL; #if RPM_VERSION_MAJOR >= 0x050000 HE_t he = memset(alloca(sizeof(*he)), 0, sizeof(*he)); @@ -158,7 +158,6 @@ headerGetStringArrayEntry(Header h, const int tag, int* count) st = dupnargv(he->p.ptr, he->c); } else { *count = 0; - st = NULL; } he->p.ptr = _free(he->p.ptr); #else