diff options
author | jbj <jbj> | 2015-05-13 13:09:27 +0000 |
---|---|---|
committer | jbj <jbj> | 2015-05-13 13:09:27 +0000 |
commit | 32d47de85df1a4d2a5467b0ca5a0d9e007ca000c (patch) | |
tree | eddac16bf72e46102691fe3183dba367c3b6ce57 | |
parent | f59b34478bd4e00fada2dbc5b2299f7a0c4d1631 (diff) | |
download | libpopt-32d47de85df1a4d2a5467b0ca5a0d9e007ca000c.tar.gz |
- cppcheck: annotate/fix warnings.
- resurrect make distcheck.
-rw-r--r-- | Makefile.am | 42 | ||||
-rwxr-xr-x | configure.ac | 8 | ||||
-rw-r--r-- | lookup3.c | 6 | ||||
-rw-r--r-- | popt.c | 23 | ||||
-rw-r--r-- | popthelp.c | 3 | ||||
-rw-r--r-- | poptparse.c | 5 | ||||
-rw-r--r-- | test3.c | 3 | ||||
-rwxr-xr-x | testit.sh | 8 |
8 files changed, 63 insertions, 35 deletions
diff --git a/Makefile.am b/Makefile.am index d170fad..c5c44ea 100644 --- a/Makefile.am +++ b/Makefile.am @@ -71,24 +71,27 @@ CLEANFILES = configmake.h configmake.h-t EXTRA_DIST = lookup3.c autogen.sh CHANGES \ footer_no_timestamp.html libpopt.vers README-prereq \ - $(TESTS) test-poptrc \ popt.xcodeproj/project.pbxproj \ - popt.ps Doxyfile test3-data/01.answer \ - test3-data/01.input \ - test3-data/02.answer \ - test3-data/02.input \ - test3-data/03.answer \ - test3-data/03.input \ - Makefile.mingw \ - config.h.mingw + popt.ps Doxyfile \ + Makefile.mingw config.h.mingw + +dist_noinst_SCRIPTS = \ + autogen.sh \ + testit.sh +dist_noinst_DATA = \ + test-poptrc \ + test3-data/01.answer \ + test3-data/01.input \ + test3-data/02.answer \ + test3-data/02.input \ + test3-data/03.answer \ + test3-data/03.input SUBDIRS = po . auto - noinst_HEADERS = poptint.h system.h check_PROGRAMS = test1 test2 tdict test3 - check_SCRIPTS = $(TESTS) @@ -109,7 +112,7 @@ test2_LDADD = $(top_builddir)/$(usrlib_LTLIBRARIES) tdict_LDADD = $(top_builddir)/$(usrlib_LTLIBRARIES) test3_LDADD = $(top_builddir)/$(usrlib_LTLIBRARIES) -TESTS_ENVIRONMENT = top_srcdir=$(top_srcdir) MUDFLAP_OPTIONS="$(MUDFLAP_OPTIONS)" testpoptrc="$(top_srcdir)/test-poptrc" PATH=.:../src:$$PATH \ +TESTS_ENVIRONMENT = top_srcdir=$(top_srcdir) MUDFLAP_OPTIONS="$(MUDFLAP_OPTIONS)" testpoptrc="test-poptrc" PATH=.:../src:$$PATH \ valgrind_environment="$(VALGRIND_ENVIRONMENT)" @@ -159,16 +162,25 @@ endif if HAVE_MCCABE mccabe: $(MCCABE) $(libpopt_la_SOURCES) | sort -n -r | head -n 10 - endif if HAVE_CPPCHECK cppcheck: - $(CPPCHECK) -I. -I$(includedir) --inline-suppr --enable=all $(libpopt_la_SOURCES) + $(CPPCHECK) -q --force --inline-suppr \ + --template="{file},{line},{severity},{id},{message}" \ + -UNOTYET -UNOTNOW -UNOTNEEDED -UDYING -UDEAD -UREFERENCE \ + -U__cplusplus -U__LCLINT__ -USWIG \ + -U_JLU3_SELFTEST \ + -U _WIN64 \ + -U __NeXT \ + -DHAVE_CONFIG_H \ + -DPOPT_fprintf=fprintf \ + --enable=warning,style,performance,portability,information,unusedFunction,missingInclude \ + $(AM_CPPFLAGS) -I$(includedir) \ + $(libpopt_la_SOURCES) test1.c test2.c test3.c tdict.c endif - if DOXYGEN_ENABLE doxygen: Doxyfile rm -rf doxygen diff --git a/configure.ac b/configure.ac index ba70368..1ac9dbc 100755 --- a/configure.ac +++ b/configure.ac @@ -6,6 +6,14 @@ AC_INIT([popt],[1.17.DEVEL],[popt-devel@rpm5.org]) AC_CONFIG_SRCDIR([lookup3.c]) AC_CONFIG_HEADERS([config.h]) +AC_CONFIG_LINKS([testit.sh:testit.sh]) +AC_CONFIG_LINKS([test-poptrc:test-poptrc]) +AC_CONFIG_LINKS([test3-data/01.answer:test3-data/01.answer]) +AC_CONFIG_LINKS([test3-data/01.input:test3-data/01.input]) +AC_CONFIG_LINKS([test3-data/02.answer:test3-data/02.answer]) +AC_CONFIG_LINKS([test3-data/02.input:test3-data/02.input]) +AC_CONFIG_LINKS([test3-data/03.answer:test3-data/03.answer]) +AC_CONFIG_LINKS([test3-data/03.input:test3-data/03.input]) AC_CONFIG_MACRO_DIR([m4]) # Must come before AM_INIT_AUTOMAKE. @@ -847,7 +847,7 @@ static void driver2(void) printf("Some bit didn't change: "); printf("%.8x %.8x %.8x %.8x %.8x %.8x ", e[0],f[0],g[0],h[0],x[0],y[0]); - printf("i %d j %d m %d len %d\n", i, j, m, hlen); + printf("i %u j %u m %u len %d\n", i, j, m, hlen); } if (z == MAXPAIR) goto done; } @@ -855,7 +855,7 @@ static void driver2(void) } done: if (z < MAXPAIR) { - printf("Mix success %2d bytes %2d initvals ",i,m); + printf("Mix success %2u bytes %2u initvals ",i,m); printf("required %d trials\n", z/2); } } @@ -931,7 +931,7 @@ static void driver3(void) x = jlu32l(m, b, len); y = jlu32l(m, b, len); if ((ref != x) || (ref != y)) - printf("alignment error: %.8x %.8x %.8x %d %d\n",ref,x,y, h, i); + printf("alignment error: %.8x %.8x %.8x %u %u\n",ref,x,y, h, i); } } } @@ -285,13 +285,13 @@ static int handleExec(/*@special@*/ poptContext con, con->av, con->nav, con->ac @*/ /*@modifies con @*/ { - poptItem item; int i; - if (con->execs == NULL || con->numExecs <= 0) + if (con->execs == NULL || con->numExecs == 0) return 0; for (i = con->numExecs - 1; i >= 0; i--) { + poptItem item; item = con->execs + i; if (longName && !(item->option.longName && !strcmp(longName, item->option.longName))) @@ -697,6 +697,7 @@ static const char * findNextArg(/*@special@*/ poptContext con, const char * arg; do { + // cppcheck-suppress variableScope int i; arg = NULL; while (os->next == os->argc && os > con->optionStack) os--; @@ -1030,9 +1031,11 @@ static long long poptCalculator(long long arg0, unsigned argInfo, long long arg1 /*@null@*/ const char * expr, int * rcp) { int ixmax = 20; /* XXX overkill */ +// cppcheck-suppress obsoleteFunctionsalloca poptStack_t stk = (poptStack_t) memset((poptStack_t)alloca(ixmax*sizeof(*stk)), 0, (ixmax*sizeof(*stk))); int ix = 0; size_t nt = 64; /* XXX overkill */ +// cppcheck-suppress obsoleteFunctionsalloca char * t = (char*) alloca(nt); char * te = t; const char * s; @@ -1041,7 +1044,6 @@ const char * s; int i; const char ** av = NULL; int ac = 0; -/* cppcheck-suppress unreadVariable */ int xx; stk[ix++] = arg0; @@ -1766,20 +1768,21 @@ poptItem poptFreeItems(/*@only@*/ /*@null@*/ poptItem items, int nitems) { if (items != NULL) { poptItem item = items; - int i; while (--nitems >= 0) { -/*@-modobserver -observertrans -dependenttrans@*/ - item->option.longName = _free(item->option.longName); - item->option.descrip = _free(item->option.descrip); - item->option.argDescrip = _free(item->option.argDescrip); -/*@=modobserver =observertrans =dependenttrans@*/ #if !defined(SUPPORT_CONTIGUOUS_ARGV) + int i; for (i = 0; item->argv[i]; i++) item->argv[i] = _free(item->argv[i]); #endif item->argv = _free(item->argv); +/*@-modobserver -observertrans -dependenttrans@*/ + item->option.longName = _free(item->option.longName); + item->option.descrip = _free(item->option.descrip); + item->option.argDescrip = _free(item->option.argDescrip); +/*@=modobserver =observertrans =dependenttrans@*/ item++; } + // cppcheck-suppress uselessAssignmentPtrArg items = _free(items); } return NULL; @@ -1836,11 +1839,13 @@ int poptAddItem(poptContext con, poptItem newItem, int flags) case 1: items = &con->execs; nitems = &con->numExecs; + // cppcheck-suppress memleakOnRealloc *items = (poptItem) xrealloc(*items, ((*nitems) + 1) * sizeof(**items)); break; case 0: items = &con->aliases; naliases = &con->numAliases; + // cppcheck-suppress memleakOnRealloc *items = (poptItem) xrealloc(*items, ((*naliases) + 1) * sizeof(**items)); break; default: @@ -55,6 +55,7 @@ static void displayArgs(poptContext con, poptPrintUsage(con, stdout, 0); #if !defined(__LCLINT__) /* XXX keep both splint & valgrind happy */ + // cppcheck-suppress uselessAssignmentPtrArg con = poptFreeContext(con); #endif exit(0); @@ -484,7 +485,6 @@ assert(t); /* XXX can't happen */ helpLength = strlen(help); while (helpLength > lineLength) { const char * ch; - char format[16]; ch = help + lineLength - 1; while (ch > help && !_isspaceptr(ch)) @@ -500,6 +500,7 @@ assert(t); /* XXX can't happen */ */ { char * fmthelp = xstrdup(help); if (fmthelp) { + char format[16]; fmthelp[ch - help] = '\0'; sprintf(format, "%%s\n%%%ds", (int) indentLength); /*@-formatconst@*/ diff --git a/poptparse.c b/poptparse.c index 0b6650a..819d30b 100644 --- a/poptparse.c +++ b/poptparse.c @@ -25,6 +25,7 @@ static const char ** poptArgvFree(/*@only@*/ const char ** av) av[i] = _free(av[i]); } #endif + // cppcheck-suppress uselessAssignmentPtrArg av = _free(av); return NULL; } @@ -170,7 +171,8 @@ int poptConfigFileToString(FILE *fp, char ** argstrp, /*@unused@*/ UNUSED(int flags)) { size_t nline = 8192; /* XXX configurable? */ - char * line = (char*) alloca(nline); + // cppcheck-suppress obsoleteFunctionsalloca + char * line = (char *) alloca(nline); char * argstr; char * q; char * x; @@ -178,6 +180,7 @@ int poptConfigFileToString(FILE *fp, char ** argstrp, size_t argvlen = 0; size_t maxargvlen = (size_t)480; + // cppcheck-suppress nullPointer if (argstrp) *argstrp = NULL; @@ -4,7 +4,8 @@ #include <string.h> #include <popt.h> -int main (int argc, char **argv) { +int main (int argc, char **argv) +{ char *out; int newargc, j, f, ret; const char **newargv; @@ -82,8 +82,6 @@ run_diff() { } builddir=$(pwd) -#srcdir=$builddir -cd ${srcdir} test1=${builddir}/test1 echo "Running tests in $builddir" @@ -567,9 +565,9 @@ fi # Begin test3 test ################### -run_diff test3 "test3 - 1" $srcdir/test3-data/01.input $srcdir/test3-data/01.answer -run_diff test3 "test3 - 2" $srcdir/test3-data/02.input $srcdir/test3-data/02.answer -run_diff test3 "test3 - 3" $srcdir/test3-data/03.input $srcdir/test3-data/03.answer +run_diff test3 "test3 - 1" ./test3-data/01.input ./test3-data/01.answer +run_diff test3 "test3 - 2" ./test3-data/02.input ./test3-data/02.answer +run_diff test3 "test3 - 3" ./test3-data/03.input ./test3-data/03.answer ################### # End test3 test |