From d1a5cef88a7340caf881c5a7b1689bcaf37f06c4 Mon Sep 17 00:00:00 2001 From: jbj Date: Thu, 21 Oct 1999 18:20:12 +0000 Subject: [PATCH] lclint annotations. CVS patchset: 3391 CVS date: 1999/10/21 18:20:12 --- popt/Makefile.am | 5 +++++ popt/popt.c | 53 +++++++++++++++++++++++++++++------------------------ popt/popt.h | 33 +++++++++++++++++---------------- popt/poptconfig.c | 5 +++-- popt/popthelp.c | 33 ++++++++++++++++++--------------- popt/poptint.h | 31 ++++++++++++++++--------------- popt/poptparse.c | 3 ++- 7 files changed, 90 insertions(+), 73 deletions(-) diff --git a/popt/Makefile.am b/popt/Makefile.am index 7c187ad..ec8480d 100644 --- a/popt/Makefile.am +++ b/popt/Makefile.am @@ -18,8 +18,13 @@ test1_LDADD = $(lib_LTLIBRARIES) include_HEADERS = popt.h lib_LTLIBRARIES = libpopt.la libpopt_la_SOURCES = popt.c findme.c poptparse.c poptconfig.c popthelp.c + man_MANS = popt.3 +.PHONY: lclint +lclint: + lclint ${DEFS} ${INCLUDES} ${libpopt_la_SOURCES} + CVSTAG = $(PACKAGE)-$(subst .,_,$(VERSION)) .PHONY: archive diff --git a/popt/popt.c b/popt/popt.c index 9808ac3..9075899 100644 --- a/popt/popt.c +++ b/popt/popt.c @@ -73,10 +73,10 @@ poptContext poptGetContext(const char * name, int argc, char ** argv, if (!(flags & POPT_CONTEXT_KEEP_FIRST)) con->os->next = 1; /* skip argv[0] */ - con->leftovers = malloc(sizeof(char *) * (argc + 1)); + con->leftovers = calloc( (argc + 1), sizeof(char *) ); con->options = options; - con->finalArgv = malloc(sizeof(*con->finalArgv) * (argc * 2)); con->finalArgvAlloced = argc * 2; + con->finalArgv = calloc( con->finalArgvAlloced, sizeof(*con->finalArgv) ); con->flags = flags; con->execAbsolute = 1; @@ -129,7 +129,7 @@ static int handleExec(poptContext con, char * longName, char shortName) { if (con->flags & POPT_CONTEXT_NO_EXEC) return 1; - if (!con->doExec) { + if (con->doExec == NULL) { con->doExec = con->execs + i; return 1; } @@ -156,7 +156,7 @@ static int handleExec(poptContext con, char * longName, char shortName) { /* Only one of longName, shortName may be set at a time */ static int handleAlias(poptContext con, const char * longName, char shortName, - const char * nextCharArg) { + /*@keep@*/ const char * nextCharArg) { int i; if (con->os->currAlias && con->os->currAlias->longName && longName && @@ -187,7 +187,8 @@ static int handleAlias(poptContext con, const char * longName, char shortName, con->os++; con->os->next = 0; con->os->stuffed = 0; - con->os->nextArg = con->os->nextCharArg = NULL; + con->os->nextArg = NULL; + con->os->nextCharArg = NULL; con->os->currAlias = con->aliases + i; con->os->argc = con->os->currAlias->argc; con->os->argv = con->os->currAlias->argv; @@ -249,12 +250,12 @@ static void execCommand(poptContext con) { execvp(argv[0], (char *const *)argv); } -static const struct poptOption * findOption(const struct poptOption * table, - const char * longName, - char shortName, - poptCallbackType * callback, - const void ** callbackData, - int singleDash) { +/*@observer@*/ static const struct poptOption * +findOption(const struct poptOption * table, const char * longName, + char shortName, + /*@out@*/ poptCallbackType * callback, /*@out@*/ const void ** callbackData, + int singleDash) +{ const struct poptOption * opt = table; const struct poptOption * opt2; const struct poptOption * cb = NULL; @@ -306,8 +307,8 @@ int poptGetNextOpt(poptContext con) { const struct poptOption * opt = NULL; int done = 0; int i; - poptCallbackType cb; - const void * cbData; + poptCallbackType cb = NULL; + const void * cbData = NULL; int singleDash; while (!done) { @@ -438,7 +439,7 @@ int poptGetNextOpt(poptContext con) { default: fprintf(stdout, POPT_("option type (%d) not implemented in popt\n"), opt->argInfo & POPT_ARG_MASK); - exit(1); + exit(EXIT_FAILURE); } } } @@ -521,7 +522,9 @@ void poptFreeContext(poptContext con) { free(con); } -int poptAddAlias(poptContext con, struct poptAlias newAlias, int flags) { +int poptAddAlias(poptContext con, struct poptAlias newAlias, + /*@unused@*/ int flags) +{ int aliasNum = con->numAliases++; struct poptAlias * alias; @@ -533,12 +536,12 @@ int poptAddAlias(poptContext con, struct poptAlias newAlias, int flags) { sizeof(newAlias) * con->numAliases); alias = con->aliases + aliasNum; - *alias = newAlias; - if (alias->longName) - alias->longName = strcpy(malloc(strlen(alias->longName) + 1), - alias->longName); - else - alias->longName = NULL; + alias->longName = (newAlias->longName) + ? strcpy(malloc(strlen(newAlias->longName) + 1), newAlias->longName) + : NULL; + alias->shortName = newAlias->shortName; + alias->argc = newAlias->argc; + alias->argv = newAlias->argv; return 0; } @@ -560,7 +563,7 @@ const char * poptBadOption(poptContext con, int flags) { #define POPT_ERROR_BADQUOTE -15 /* only from poptParseArgString() */ #define POPT_ERROR_ERRNO -16 /* only from poptParseArgString() */ -const char * poptStrerror(const int error) { +const char *const poptStrerror(const int error) { switch (error) { case POPT_ERROR_NOARG: return POPT_("missing argument"); @@ -587,11 +590,13 @@ int poptStuffArgs(poptContext con, const char ** argv) { if ((con->os - con->optionStack) == POPT_OPTION_DEPTH) return POPT_ERROR_OPTSTOODEEP; - for (i = 0; argv[i]; i++); + for (i = 0; argv[i]; i++) + ; con->os++; con->os->next = 0; - con->os->nextArg = con->os->nextCharArg = NULL; + con->os->nextArg = NULL; + con->os->nextCharArg = NULL; con->os->currAlias = NULL; con->os->argc = i; con->os->argv = argv; diff --git a/popt/popt.h b/popt/popt.h index 2d9ea8c..459dea7 100644 --- a/popt/popt.h +++ b/popt/popt.h @@ -55,17 +55,17 @@ struct poptOption { /*@observer@*/ /*@null@*/ const char * longName; /* may be NULL */ char shortName; /* may be '\0' */ int argInfo; - /*@dependent@*/ /*@null@*/ void * arg; /* depends on argInfo */ + /*@shared@*/ /*@null@*/ void * arg; /* depends on argInfo */ int val; /* 0 means don't return, just update flag */ - /*@null@*/ const char * descrip; /* description for autohelp -- may be NULL */ - /*@null@*/ const char * argDescrip; /* argument description for autohelp */ + /*@shared@*/ /*@null@*/ const char * descrip; /* description for autohelp -- may be NULL */ + /*@shared@*/ /*@null@*/ const char * argDescrip; /* argument description for autohelp */ }; struct poptAlias { - /*@null@*/ const char * longName; /* may be NULL */ + /*@owned@*/ /*@null@*/ const char * longName; /* may be NULL */ char shortName; /* may be '\0' */ int argc; - const char ** argv; /* must be free()able */ + /*@owned@*/ const char ** argv; /* must be free()able */ }; extern struct poptOption poptHelpOptions[]; @@ -85,22 +85,23 @@ typedef void (*poptCallbackType)(poptContext con, const struct poptOption * opt, const char * arg, const void * data); -poptContext poptGetContext(const char * name, int argc, char ** argv, - const struct poptOption * options, int flags); +/*@only@*/ poptContext poptGetContext(/*@keep@*/ const char * name, + int argc, /*@keep@*/ char ** argv, + /*@keep@*/ const struct poptOption * options, int flags); void poptResetContext(poptContext con); /* returns 'val' element, -1 on last item, POPT_ERROR_* on error */ int poptGetNextOpt(poptContext con); /* returns NULL if no argument is available */ -char * poptGetOptArg(poptContext con); +/*@observer@*/ /*@null@*/ char * poptGetOptArg(poptContext con); /* returns NULL if no more options are available */ -char * poptGetArg(poptContext con); -const char * poptPeekArg(poptContext con); -const char ** poptGetArgs(poptContext con); +/*@observer@*/ /*@null@*/ char * poptGetArg(poptContext con); +/*@observer@*/ /*@null@*/ const char * poptPeekArg(poptContext con); +/*@observer@*/ /*@null@*/ const char ** poptGetArgs(poptContext con); /* returns the option which caused the most recent error */ -const char * poptBadOption(poptContext con, int flags); -void poptFreeContext(poptContext con); -int poptStuffArgs(poptContext con, const char ** argv); +/*@observer@*/ const char * poptBadOption(poptContext con, int flags); +void poptFreeContext( /*@only@*/ poptContext con); +int poptStuffArgs(poptContext con, /*@keep@*/ const char ** argv); int poptAddAlias(poptContext con, struct poptAlias alias, int flags); int poptReadConfigFile(poptContext con, const char * fn); /* like above, but reads /etc/popt and $HOME/.popt along with environment @@ -110,12 +111,12 @@ int poptReadDefaultConfig(poptContext con, int useEnv); the same as " and both may include \ quotes */ int poptParseArgvString(const char * s, /*@out@*/ int * argcPtr, /*@out@*/ char *** argvPtr); -const char * poptStrerror(const int error); +/*@observer@*/ const char *const poptStrerror(const int error); void poptSetExecPath(poptContext con, const char * path, int allowAbsolute); void poptPrintHelp(poptContext con, FILE * f, int flags); void poptPrintUsage(poptContext con, FILE * f, int flags); void poptSetOtherOptionHelp(poptContext con, const char * text); -const char * poptGetInvocationName(poptContext con); +/*@observer@*/ const char * poptGetInvocationName(poptContext con); #ifdef __cplusplus } diff --git a/popt/poptconfig.c b/popt/poptconfig.c index 9d9b495..5f7ec8d 100644 --- a/popt/poptconfig.c +++ b/popt/poptconfig.c @@ -84,7 +84,7 @@ int poptReadConfigFile(poptContext con, const char * fn) { } fileLength = lseek(fd, 0, SEEK_END); - lseek(fd, 0, 0); + (void) lseek(fd, 0, 0); file = alloca(fileLength + 1); if (read(fd, file, fileLength) != fileLength) { @@ -122,13 +122,14 @@ int poptReadConfigFile(poptContext con, const char * fn) { break; default: *dst++ = *chptr++; + break; } } return 0; } -int poptReadDefaultConfig(poptContext con, int useEnv) { +int poptReadDefaultConfig(poptContext con, /*@unused@*/ int useEnv) { char * fn, * home; int rc; diff --git a/popt/popthelp.c b/popt/popthelp.c index 05570bb..4ebe621 100644 --- a/popt/popthelp.c +++ b/popt/popthelp.c @@ -20,9 +20,10 @@ #include "popt.h" #include "poptint.h" -static void displayArgs(poptContext con, enum poptCallbackReason foo, - struct poptOption * key, - const char * arg, void * data) { +static void displayArgs(poptContext con, + /*@unused@*/ enum poptCallbackReason foo, + struct poptOption * key, + /*@unused@*/ const char * arg, /*@unused@*/ void * data) { if (key->shortName== '?') poptPrintHelp(con, stdout, 0); else @@ -31,14 +32,14 @@ static void displayArgs(poptContext con, enum poptCallbackReason foo, } struct poptOption poptHelpOptions[] = { - { NULL, '\0', POPT_ARG_CALLBACK, (void *)&displayArgs, '\0', NULL }, - { "help", '?', 0, NULL, '?', N_("Show this help message") }, - { "usage", '\0', 0, NULL, 'u', N_("Display brief usage message") }, - { NULL, '\0', 0, NULL, 0 } + { NULL, '\0', POPT_ARG_CALLBACK, (void *)&displayArgs, '\0', NULL, NULL }, + { "help", '?', 0, NULL, '?', N_("Show this help message"), NULL }, + { "usage", '\0', 0, NULL, 'u', N_("Display brief usage message"), NULL }, + { NULL, '\0', 0, NULL, 0, NULL, NULL } } ; -static const char * +/*@observer@*/ /*@null@*/ static const char *const getTableTranslationDomain(const struct poptOption *table) { const struct poptOption *opt; @@ -53,8 +54,9 @@ getTableTranslationDomain(const struct poptOption *table) return NULL; } -static const char * getArgDescrip(const struct poptOption * opt, - const char *translation_domain) { +/*@observer@*/ /*@null@*/ static const char *const +getArgDescrip(const struct poptOption * opt, const char *translation_domain) +{ if (!(opt->argInfo & POPT_ARG_MASK)) return NULL; if (opt == (poptHelpOptions + 1) || opt == (poptHelpOptions + 2)) @@ -193,7 +195,7 @@ static int showHelpIntro(poptContext con, FILE * f) { return len; } -void poptPrintHelp(poptContext con, FILE * f, int flags) { +void poptPrintHelp(poptContext con, FILE * f, /*@unused@*/ int flags) { int leftColWidth; showHelpIntro(con, f); @@ -210,7 +212,7 @@ static int singleOptionUsage(FILE * f, int cursor, const struct poptOption * opt, const char *translation_domain) { int len = 3; - char shortStr[2]; + char shortStr[2] = { '\0', '\0' }; const char * item = shortStr; const char * argDescrip = getArgDescrip(opt, translation_domain); @@ -268,9 +270,10 @@ static int showShortOptions(const struct poptOption * opt, FILE * f, char s[300]; /* this is larger then the ascii set, so it should do just fine */ - if (!str) { + s[0] = '\0'; + if (str == NULL) { + memset(s, 0, sizeof(s)); str = s; - memset(str, 0, sizeof(s)); } while (opt->longName || opt->shortName || opt->arg) { @@ -289,7 +292,7 @@ static int showShortOptions(const struct poptOption * opt, FILE * f, return strlen(s) + 4; } -void poptPrintUsage(poptContext con, FILE * f, int flags) { +void poptPrintUsage(poptContext con, FILE * f, /*@unused@*/ int flags) { int cursor; cursor = showHelpIntro(con, f); diff --git a/popt/poptint.h b/popt/poptint.h index 62cc60a..4cab19f 100644 --- a/popt/poptint.h +++ b/popt/poptint.h @@ -7,11 +7,11 @@ struct optionStackEntry { int argc; - const char ** argv; + /*@keep@*/ const char ** argv; int next; - const char * nextArg; - const char * nextCharArg; - struct poptAlias * currAlias; + /*@keep@*/ const char * nextArg; + /*@keep@*/ const char * nextCharArg; + /*@dependent@*/ struct poptAlias * currAlias; int stuffed; }; @@ -22,25 +22,26 @@ struct execEntry { }; struct poptContext_s { - struct optionStackEntry optionStack[POPT_OPTION_DEPTH], * os; - const char ** leftovers; + struct optionStackEntry optionStack[POPT_OPTION_DEPTH]; + /*@dependent@*/ struct optionStackEntry * os; + /*@owned@*/ const char ** leftovers; int numLeftovers; int nextLeftover; - const struct poptOption * options; + /*@keep@*/ const struct poptOption * options; int restLeftover; - const char * appName; - struct poptAlias * aliases; + /*@owned@*/ const char * appName; + /*@owned@*/ struct poptAlias * aliases; int numAliases; int flags; struct execEntry * execs; int numExecs; - const char ** finalArgv; + /*@owned@*/ const char ** finalArgv; int finalArgvCount; int finalArgvAlloced; - struct execEntry * doExec; - const char * execPath; + /*@dependent@*/ struct execEntry * doExec; + /*@owned@*/ const char * execPath; int execAbsolute; - const char * otherHelp; + /*@owned@*/ const char * otherHelp; }; #define xfree(_a) free((void *)_a) @@ -49,13 +50,13 @@ struct poptContext_s { #include #endif -#ifdef HAVE_GETTEXT +#if defined(HAVE_GETTEXT) && !defined(__LCLINT__) #define _(foo) gettext(foo) #else #define _(foo) (foo) #endif -#ifdef HAVE_DGETTEXT +#if defined(HAVE_DGETTEXT) && !defined(__LCLINT__) #define D_(dom, str) dgettext(dom, str) #define POPT_(foo) D_("popt", foo) #else diff --git a/popt/poptparse.c b/popt/poptparse.c index c64ce0f..0d318f4 100644 --- a/popt/poptparse.c +++ b/popt/poptparse.c @@ -81,9 +81,10 @@ int poptParseArgvString(const char * s, int * argcPtr, char *** argvPtr) { free(argv); return POPT_ERROR_BADQUOTE; } - /* fallthrough */ + /*@fallthrough@*/ default: *buf++ = *src; + break; } src++; -- 2.7.4