Commit 61352c7c3e9856d3ae89e40495661acd8e814cc4

Authored by Silvan Calarco
1 parent b14c9271cf
Exists in master

Optimization warning fixes

Showing 7 changed files with 41 additions and 44 deletions Side-by-side Diff

... ... @@ -44,7 +44,7 @@
44 44 ${LIBIBERTY}
45 45 )
46 46 target_include_directories(distromatic PUBLIC ${RPM_INCLUDE_DIRS})
47   -target_compile_options(distromatic PUBLIC -g -Wall -std=gnu11 -pedantic ${RPM_CFLAGS_OTHER})
  47 +target_compile_options(distromatic PUBLIC -O2 -g -Wall -std=gnu11 -pedantic ${RPM_CFLAGS_OTHER})
48 48  
49 49 add_executable(distroquery
50 50 distroquery.c
... ... @@ -142,7 +142,7 @@
142 142  
143 143 newchangelog->time = changelogtime[i];
144 144  
145   - strncpy(changelogname, changelogrelease[i], 255);
  145 + strcpy(changelogname, changelogrelease[i]);
146 146 endp = strchr(changelogname, '>');
147 147 if (endp) {
148 148 endp[1] = '\0';
... ... @@ -164,7 +164,7 @@
164 164 newconfigtag->configdefaults = &configdefaults;
165 165  
166 166 if (configdefaults.html_basedir) {
167   - strncpy(buf, configdefaults.html_basedir, PATH_MAX);
  167 + strcpy(buf, configdefaults.html_basedir);
168 168 strncat(buf, newconfigtag->tag, sizeof(buf) - strlen(buf));
169 169 strncat(buf, "/", sizeof(buf) - strlen(buf));
170 170 newconfigtag->html_dir = (char *) strdup(buf);
... ... @@ -318,7 +318,7 @@
318 318 }
319 319  
320 320 if (!currconfigtag->repository_source_dir) {
321   - strncpy(buf, currconfigtag->repository_dir, PATH_MAX);
  321 + strcpy(buf, currconfigtag->repository_dir);
322 322 strncat(buf, "/SRPMS.base/", sizeof(buf) - strlen(buf));
323 323 currconfigtag->repository_source_dir =
324 324 (char *) strdup(buf);
... ... @@ -426,7 +426,7 @@
426 426 break;
427 427 }
428 428 if ((level == LOG_WARNING) || (level == LOG_ERROR)) {
429   - strncpy(oldmsg[curroldmsg++],newmsg,256);
  429 + strncpy(oldmsg[curroldmsg++],newmsg,PATH_MAX);
430 430 if (curroldmsg >= 20) curroldmsg = 0;
431 431 }
432 432 }
433 433  
434 434  
435 435  
... ... @@ -488,20 +488,20 @@
488 488 char *humanSize(long long sbytes, sizeString *s) {
489 489  
490 490 if (sbytes < 1024) {
491   - snprintf((char *)s, SSSIZE, "%lld B", sbytes);
492   - return (char *)s;
  491 + snprintf((char *)s, SSSIZE, "%lld B", sbytes);
  492 + return (char *)s;
493 493 }
494 494 if ((sbytes / 1024) < 1024) {
495   - snprintf((char *)s, SSSIZE, "%.2f KB", sbytes / 1024.0);
496   - return (char*)s;
  495 + snprintf((char *)s, SSSIZE, "%.2f KB", sbytes / 1024.0);
  496 + return (char*)s;
497 497 }
498 498 if ((sbytes / 1024 / 1024 ) < 1024) {
499   - snprintf((char *)s, SSSIZE, "%.2f MB", sbytes / 1024.0 / 1024.0);
500   - return (char*)s;
  499 + snprintf((char *)s, SSSIZE, "%.2f MB", sbytes / 1024.0 / 1024.0);
  500 + return (char*)s;
501 501 }
502 502 if ((sbytes / 1024 / 1024 / 1024 ) < 1024) {
503   - snprintf((char *)s, SSSIZE, "%.2f GB", sbytes / 1024.0 / 1024.0 / 1024.0);
504   - return (char*)s;
  503 + snprintf((char *)s, SSSIZE, "%.2f GB", sbytes / 1024.0 / 1024.0 / 1024.0);
  504 + return (char*)s;
505 505 }
506 506 snprintf((char *)s, SSSIZE, "%.2f TB", sbytes / 1024.0 / 1024.0 / 1024.0 / 1024.0);
507 507 return (char*)s;
src/include/functions.h
... ... @@ -11,7 +11,7 @@
11 11 #include <dirent.h>
12 12  
13 13 #define HDSIZE 16
14   -#define SSSIZE 16
  14 +#define SSSIZE 24
15 15  
16 16 typedef char humanDate[HDSIZE];
17 17 typedef char sizeString[SSSIZE];
src/include/reports.h
... ... @@ -26,14 +26,13 @@
26 26 int generateHTMLFiles(struct configTag *configtag,int arch);
27 27 int generateHTML_SRPMSFiles(struct configTag *configtag);
28 28 int generateHTMLMainIndex(struct configTag *configtag);
29   -char *groupdirname(char *group,char *dest,unsigned int max);
30 29 int write_RPM_HTML(struct configTag *ct,FILE *fout, struct headerList *currheaderlist);
31 30 int print_contentslist(struct configTag *ct, int arch);
32 31 int print_datatables(struct configTag *ct, int arch);
33   -char *ftname(struct fileTree* ft, char* buf, unsigned int bufsize);
34   -void print_contents_subtree(FILE *f,
35   - struct fileTree* ft,
36   - struct configTag* ct,
  32 +char *ftname(struct fileTree* ft, char* buf);
  33 +void print_contents_subtree(FILE *f,
  34 + struct fileTree* ft,
  35 + struct configTag* ct,
37 36 char* buf, int bufsize);
38 37 int generatePkgList(struct configTag *ct, int arch);
39 38 int generateSrcPkgList(struct configTag *ct);
... ... @@ -41,13 +41,13 @@
41 41 #define HTMLOLDSTATS_NUM 400
42 42 #define RSSSTATS_NUM 20
43 43  
44   -char *groupdirname(char *group,char *dest,unsigned int max)
  44 +char *groupdirname(char *group,char *dest)
45 45 {
46   - strncpy(dest,group,max);
  46 + strcpy(dest,group);
47 47  
48 48 unsigned int i=0;
49 49  
50   - while (dest[i] && i<max) {
  50 + while (dest[i] && i<PATH_MAX) {
51 51 switch (dest[i]) {
52 52 case '/': dest[i]=':'; break;
53 53 case ' ': dest[i]='_'; break;
54 54  
... ... @@ -439,9 +439,9 @@
439 439  
440 440 if (pkgnum==0) {
441 441  
442   - snprintf(outfile, PATH_MAX, "%sgroups/%s",
  442 + sprintf(outfile, "%sgroups/%s",
443 443 configtag->html_dir,
444   - groupdirname(configtag->stats.headersourcelistvec[i]->group,buffer,PATH_MAX));
  444 + groupdirname(configtag->stats.headersourcelistvec[i]->group,buffer));
445 445  
446 446 if (stat(outfile,&buf)) {
447 447 if (mkdir(outfile,S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH)) {
... ... @@ -484,7 +484,7 @@
484 484 "<a href=\"%stag=%s&amp;group=%s\">%s <b>(%d)</b></a><br>\n",
485 485 configtag->configdefaults->url_prefix,
486 486 configtag->tag,
487   - groupdirname(configtag->stats.headersourcelistvec[i-1]->group,buffer,PATH_MAX),
  487 + groupdirname(configtag->stats.headersourcelistvec[i-1]->group,buffer),
488 488 (configtag->stats.headersourcelistvec)[i-1]->group,
489 489 pkgnum);
490 490 pkgnum=0;
... ... @@ -497,7 +497,7 @@
497 497 fclose(groupout);
498 498 }
499 499  
500   - strncpy(outfile, configtag->html_dir, PATH_MAX);
  500 + strcpy(outfile, configtag->html_dir);
501 501 strncat(outfile, "_recent.inc", sizeof(outfile) - strlen(outfile));
502 502 if ((htmlout = fopen(outfile, "w")) == NULL) {
503 503 perror(outfile);
... ... @@ -513,7 +513,7 @@
513 513 fprintf(htmlout, "Recent builds:<br>\n");
514 514 }*/
515 515  
516   - strncpy(outfile, configtag->html_dir, PATH_MAX);
  516 + strcpy(outfile, configtag->html_dir);
517 517 strncat(outfile, "_oldest.inc", sizeof(outfile) - strlen(outfile));
518 518 if ((htmloldout = fopen(outfile, "w")) == NULL) {
519 519 perror(outfile);
... ... @@ -524,7 +524,7 @@
524 524 fprintf(htmloldout, "Oldest builds:<br>\n");
525 525 }*/
526 526  
527   - strncpy(rssfile, configtag->html_dir, PATH_MAX);
  527 + strcpy(rssfile, configtag->html_dir);
528 528 strncat(rssfile, "recent.rss", sizeof(rssfile) - strlen(rssfile));
529 529 if ((rssout = fopen(rssfile, "w")) == NULL) {
530 530 perror(rssfile);
... ... @@ -651,7 +651,7 @@
651 651 } else {
652 652  
653 653 /* remove final slashes from download_prefix as required by apt */
654   - strncpy(buffer, configtag->download_dir, PATH_MAX);
  654 + strcpy(buffer, configtag->download_dir);
655 655  
656 656 i=strlen(buffer);
657 657 while ((i > 0) && (buffer[i-1] == '/' )) {
... ... @@ -690,7 +690,7 @@
690 690 return 1;
691 691 } else {
692 692 /* remove final slashes from download_prefix as required by apt */
693   - strncpy(buffer, configtag->download_dir, PATH_MAX);
  693 + strcpy(buffer, configtag->download_dir);
694 694  
695 695 i=strlen(buffer);
696 696 while ((i > 0) && (buffer[i-1] == '/' )) {
... ... @@ -753,7 +753,7 @@
753 753 return 2;
754 754 }
755 755  
756   - strncpy(indexfile, configtag->configdefaults->html_basedir, PATH_MAX);
  756 + strcpy(indexfile, configtag->configdefaults->html_basedir);
757 757 strncat(indexfile, "_index.inc", sizeof(indexfile) - strlen(indexfile));
758 758  
759 759 if ((fout = fopen(indexfile, "w")) == NULL) {
... ... @@ -789,7 +789,7 @@
789 789 configtag->description);
790 790  
791 791 /* remove final slashes from download_prefix as required by apt */
792   - strncpy(buffer, configtag->download_dir, PATH_MAX);
  792 + strcpy(buffer, configtag->download_dir);
793 793 i=strlen(buffer);
794 794 while ((i > 0) && (buffer[i-1] == '/' )) {
795 795 buffer[i-1]='\0';
... ... @@ -987,7 +987,7 @@
987 987 "<tr><td>Group:</td><td><a href=\"%stag=%s&amp;group=%s\">%s</a></td></tr>\n",
988 988 configtag->configdefaults->url_prefix,
989 989 configtag->tag,
990   - groupdirname(currheadersourcelist->group, buffer2, PATH_MAX),
  990 + groupdirname(currheadersourcelist->group, buffer2),
991 991 htmlclean(currheadersourcelist->group,buffer,PATH_MAX));
992 992  
993 993 fprintf(fout,
... ... @@ -1096,7 +1096,7 @@
1096 1096 fprintf(findexout[idx],"</td><td><b>%s</b>: <i>%s</i>",currheadersourcelist->name,htmlclean(currheadersourcelist->summary,buffer,PATH_MAX));
1097 1097 st=strstr(currheadersourcelist->url,"://");
1098 1098 if (st) {
1099   - strncpy(buffer,st+3,PATH_MAX);
  1099 + strcpy(buffer,st+3);
1100 1100 st=strchr(buffer,'/');
1101 1101 if (st) st[0]='\0';
1102 1102 fprintf(findexout[idx],
... ... @@ -1346,7 +1346,7 @@
1346 1346 while (currheadersourcelist) {
1347 1347 snprintf(dir, PATH_MAX, "%sgroups/%s",
1348 1348 ct->html_dir,
1349   - groupdirname(currheadersourcelist->group,uf,PATH_MAX));
  1349 + groupdirname(currheadersourcelist->group,uf));
1350 1350  
1351 1351 if (!stat(dir,&buf)) {
1352 1352 logmsg(LOG_DEBUG,"removing directory %s",dir);
... ... @@ -1363,7 +1363,7 @@
1363 1363 /* legacy: clean old group dirs */
1364 1364 snprintf(dir, PATH_MAX, "%s%s",
1365 1365 ct->html_dir,
1366   - groupdirname(currheadersourcelist->group,uf,PATH_MAX));
  1366 + groupdirname(currheadersourcelist->group,uf));
1367 1367  
1368 1368 if (!stat(dir,&buf)) {
1369 1369 logmsg(LOG_DEBUG,"removing legacy directory %s",dir);
... ... @@ -1696,8 +1696,7 @@
1696 1696 fprintf(fout,
1697 1697 "<tr><td>Filenames:</td><td><font size=\"-1\">");
1698 1698 for (i = 0; i < currheaderlist->filenamecount; i++) {
1699   - ftname((currheaderlist->file)[i],
1700   - buffer, PATH_MAX);
  1699 + ftname((currheaderlist->file)[i], buffer);
1701 1700  
1702 1701 fprintf(fout, "/%s ",buffer);
1703 1702 }
1704 1703  
1705 1704  
... ... @@ -1710,19 +1709,19 @@
1710 1709 return 0;
1711 1710 }
1712 1711  
1713   -char *ftname(struct fileTree* ft, char* buf, unsigned int bufsize) {
  1712 +char *ftname(struct fileTree* ft, char* buf) {
1714 1713  
1715 1714 buf[0]='\0';
1716 1715 int l;
1717 1716  
1718 1717 if (ft) {
1719   - strncpy(buf,ft->name,bufsize);
  1718 + strcpy(buf,ft->name);
1720 1719 ft=ft->parent;
1721 1720 }
1722 1721  
1723 1722 while (ft) {
1724 1723 l=strlen(ft->name);
1725   - if (strlen(buf)+l+1 <= bufsize) {
  1724 + if (strlen(buf)+l+1 <= PATH_MAX) {
1726 1725 memmove(buf+l+1,buf,strlen(buf)+1);
1727 1726 memcpy(buf,ft->name,l);
1728 1727 buf[l]='/';
... ... @@ -1747,7 +1746,7 @@
1747 1746 ((ft->provider[k]) &&
1748 1747 (ft->provider[k]->sourceheader) &&
1749 1748 (ft->provider[k]->altrepository == ct->repository_level))) {
1750   - ftname(ft,buf,bufsize);
  1749 + ftname(ft,buf);
1751 1750 if ((j=strlen(buf)) < 60) {
1752 1751 for (i=(60-j)/8; i>0; i--) strncat(buf, "\t", bufsize - strlen(buf));
1753 1752 while (strlen(buf) < 60) strncat(buf, " ", bufsize - strlen(buf));
... ... @@ -147,7 +147,7 @@
147 147 char **
148 148 headerGetStringArrayEntry(Header h, const int tag, int* count)
149 149 {
150   - char **st;
  150 + char **st = NULL;
151 151  
152 152 #if RPM_VERSION_MAJOR >= 0x050000
153 153 HE_t he = memset(alloca(sizeof(*he)), 0, sizeof(*he));
... ... @@ -158,7 +158,6 @@
158 158 st = dupnargv(he->p.ptr, he->c);
159 159 } else {
160 160 *count = 0;
161   - st = NULL;
162 161 }
163 162 he->p.ptr = _free(he->p.ptr);
164 163 #else