From 3ccd8f96a228f292d2ce6a2607718014bb07c4e2 Mon Sep 17 00:00:00 2001 From: jbj Date: Mon, 4 Jun 2001 13:55:58 +0000 Subject: lclint fiddles. --- popt.c | 4 ++-- popt.h | 76 +++++++++++++++++++++++++++++++++++++++++++++----------------- popthelp.c | 22 +++++++++--------- poptint.h | 6 ++--- system.h | 2 +- 5 files changed, 72 insertions(+), 38 deletions(-) diff --git a/popt.c b/popt.c index 548cbd8..8c42f90 100644 --- a/popt.c +++ b/popt.c @@ -477,7 +477,7 @@ findOption(const struct poptOption * opt, /*@null@*/ const char * longName, } static const char * findNextArg(/*@special@*/ poptContext con, - unsigned argx, int delete) + unsigned argx, int delete_arg) /*@uses con->optionStack, con->os, con->os->next, con->os->argb, con->os->argc, con->os->argv @*/ { @@ -495,7 +495,7 @@ static const char * findNextArg(/*@special@*/ poptContext con, if (*os->argv[i] == '-') continue; if (--argx > 0) continue; arg = os->argv[i]; - if (delete) { + if (delete_arg) { if (os->argb == NULL) os->argb = PBM_ALLOC(os->argc); if (os->argb != NULL) /* XXX can't happen */ PBM_SET(i, os->argb); diff --git a/popt.h b/popt.h index b74f7d8..52819f5 100644 --- a/popt.h +++ b/popt.h @@ -142,7 +142,9 @@ typedef /*@abstract@*/ struct poptContext_s * poptContext; /** \ingroup popt */ #ifndef __cplusplus +/*@-typeuse@*/ typedef struct poptOption * poptOption; +/*@=typeuse@*/ #endif enum poptCallbackReason { POPT_CALLBACK_REASON_PRE, @@ -161,7 +163,8 @@ typedef void (*poptCallbackType) (poptContext con, enum poptCallbackReason reason, /*@null@*/ const struct poptOption * opt, /*@null@*/ const char * arg, - /*@null@*/ const void * data); + /*@null@*/ const void * data) + /*@*/; /** \ingroup popt * Initialize popt context. @@ -176,61 +179,73 @@ typedef void (*poptCallbackType) (poptContext con, /*@dependent@*/ /*@keep@*/ const char * name, int argc, /*@dependent@*/ /*@keep@*/ const char ** argv, /*@dependent@*/ /*@keep@*/ const struct poptOption * options, - int flags); + int flags) + /*@*/; /** \ingroup popt * Reinitialize popt context. * @param con context */ -void poptResetContext(/*@null@*/poptContext con); +void poptResetContext(/*@null@*/poptContext con) + /*@modifies con @*/; /** \ingroup popt * Return value of next option found. * @param con context * @return next option val, -1 on last item, POPT_ERROR_* on error */ -int poptGetNextOpt(/*@null@*/poptContext con); -/* returns NULL if no argument is available */ +int poptGetNextOpt(/*@null@*/poptContext con) + /*@modifies con @*/; +/*@-redecl@*/ /** \ingroup popt + * Return next option argument (if any). * @param con context + * @return option argument, NULL if no more options are available */ -/*@observer@*/ /*@null@*/ const char * poptGetOptArg(/*@null@*/poptContext con); +/*@observer@*/ /*@null@*/ const char * poptGetOptArg(/*@null@*/poptContext con) + /*@modifies con @*/; /** \ingroup popt * Return current option's argument. * @param con context * @return option argument, NULL if no more options are available */ -/*@observer@*/ /*@null@*/ const char * poptGetArg(/*@null@*/poptContext con); +/*@observer@*/ /*@null@*/ const char * poptGetArg(/*@null@*/poptContext con) + /*@modifies con @*/; /** \ingroup popt - * Peek at current option's argument. + * Peek at current option's argument. * @param con context * @return option argument */ -/*@observer@*/ /*@null@*/ const char * poptPeekArg(/*@null@*/poptContext con); +/*@observer@*/ /*@null@*/ const char * poptPeekArg(/*@null@*/poptContext con) + /*@*/; /** \ingroup popt * Return remaining arguments. * @param con context * @return argument array, terminated with NULL */ -/*@observer@*/ /*@null@*/ const char ** poptGetArgs(/*@null@*/poptContext con); +/*@observer@*/ /*@null@*/ const char ** poptGetArgs(/*@null@*/poptContext con) + /*@modifies con @*/; /** \ingroup popt * Return the option which caused the most recent error. * @param con context * @return offending option */ -/*@observer@*/ const char * poptBadOption(/*@null@*/poptContext con, int flags); +/*@observer@*/ const char * poptBadOption(/*@null@*/poptContext con, int flags) + /*@*/; +/*@=redecl@*/ /** \ingroup popt * Destroy context. * @param con context - * @return NULL + * @return NULL always */ -/*@null@*/ poptContext poptFreeContext( /*@only@*/ /*@null@*/ poptContext con); +/*@null@*/ poptContext poptFreeContext( /*@only@*/ /*@null@*/ poptContext con) + /*@modifies con @*/; /** \ingroup popt * Add arguments to context. @@ -238,7 +253,8 @@ int poptGetNextOpt(/*@null@*/poptContext con); * @param argv argument array, NULL terminated * @return 0 on success, POPT_ERROR_OPTSTOODEEP on failure */ -int poptStuffArgs(poptContext con, /*@keep@*/ const char ** argv); +int poptStuffArgs(poptContext con, /*@keep@*/ const char ** argv) + /*@modifies con @*/; /** \ingroup popt * Add alias to context. @@ -248,7 +264,8 @@ int poptStuffArgs(poptContext con, /*@keep@*/ const char ** argv); * @param flags (unused) * @return 0 always */ -int poptAddAlias(poptContext con, struct poptAlias alias, int flags); +int poptAddAlias(poptContext con, struct poptAlias alias, int flags) + /*@modifies con @*/; /** \ingroup popt * Read configuration file. @@ -306,8 +323,10 @@ int poptParseArgvString(const char * s, * @param error popt error * @return error string */ +/*@-redecl@*/ /*@observer@*/ const char *const poptStrerror(const int error) /*@*/; +/*@=redecl@*/ /** \ingroup popt * Limit search for executables. @@ -315,7 +334,8 @@ int poptParseArgvString(const char * s, * @param path single path to search for executables * @param allowAbsolute absolute paths only? */ -void poptSetExecPath(poptContext con, const char * path, int allowAbsolute); +void poptSetExecPath(poptContext con, const char * path, int allowAbsolute) + /*@modifies con @*/; /** \ingroup popt * Print detailed description of options. @@ -323,7 +343,8 @@ void poptSetExecPath(poptContext con, const char * path, int allowAbsolute); * @param f ouput file handle * @param flags (unused) */ -void poptPrintHelp(poptContext con, FILE * f, /*@unused@*/ int flags); +void poptPrintHelp(poptContext con, FILE * f, /*@unused@*/ int flags) + /*@modifies *f @*/; /** \ingroup popt * Print terse description of options. @@ -331,27 +352,40 @@ void poptPrintHelp(poptContext con, FILE * f, /*@unused@*/ int flags); * @param f ouput file handle * @param flags (unused) */ -void poptPrintUsage(poptContext con, FILE * f, /*@unused@*/ int flags); +void poptPrintUsage(poptContext con, FILE * f, /*@unused@*/ int flags) + /*@modifies *f @*/; /** \ingroup popt * Provide text to replace default "[OPTION...]" in help/usage output. * @param con context * @param text replacement text */ -void poptSetOtherOptionHelp(poptContext con, const char * text); +/*@-fcnuse@*/ +void poptSetOtherOptionHelp(poptContext con, const char * text) + /*@modifies con @*/; +/*@=fcnuse@*/ /** \ingroup popt * Return argv[0] from context. * @param con context + * @return argv[0] */ -/*@observer@*/ const char * poptGetInvocationName(poptContext con); +/*@-redecl -fcnuse@*/ +/*@observer@*/ const char * poptGetInvocationName(poptContext con) + /*@*/; +/*@=redecl =fcnuse@*/ /** \ingroup popt * Shuffle argv pointers to remove stripped args, returns new argc. * @param con context + * @param argc no. of args + * @param argv arg vector * @return new argc */ -int poptStrippedArgv(poptContext con, int argc, char ** argv); +/*@-fcnuse@*/ +int poptStrippedArgv(poptContext con, int argc, char ** argv) + /*@modifies *argv @*/; +/*@=fcnuse@*/ #ifdef __cplusplus } diff --git a/popthelp.c b/popthelp.c index 086cd43..62822fa 100644 --- a/popthelp.c +++ b/popthelp.c @@ -180,30 +180,30 @@ static int maxArgWidth(const struct poptOption * opt, /*@null@*/ const char * translation_domain) { int max = 0; - int this = 0; + int len = 0; const char * s; if (opt != NULL) while (opt->longName || opt->shortName || opt->arg) { if ((opt->argInfo & POPT_ARG_MASK) == POPT_ARG_INCLUDE_TABLE) { if (opt->arg) /* XXX program error */ - this = maxArgWidth(opt->arg, translation_domain); - if (this > max) max = this; + len = maxArgWidth(opt->arg, translation_domain); + if (len > max) max = len; } else if (!(opt->argInfo & POPT_ARGFLAG_DOC_HIDDEN)) { - this = sizeof(" ")-1; - if (opt->shortName != '\0') this += sizeof("-X")-1; - if (opt->shortName != '\0' && opt->longName) this += sizeof(", ")-1; + len = sizeof(" ")-1; + if (opt->shortName != '\0') len += sizeof("-X")-1; + if (opt->shortName != '\0' && opt->longName) len += sizeof(", ")-1; if (opt->longName) { - this += ((opt->argInfo & POPT_ARGFLAG_ONEDASH) + len += ((opt->argInfo & POPT_ARGFLAG_ONEDASH) ? sizeof("-")-1 : sizeof("--")-1); - this += strlen(opt->longName); + len += strlen(opt->longName); } s = getArgDescrip(opt, translation_domain); if (s) - this += sizeof("=")-1 + strlen(s); - if (opt->argInfo & POPT_ARGFLAG_OPTIONAL) this += sizeof("[]")-1; - if (this > max) max = this; + len += sizeof("=")-1 + strlen(s); + if (opt->argInfo & POPT_ARGFLAG_OPTIONAL) len += sizeof("[]")-1; + if (len > max) max = len; } opt++; diff --git a/poptint.h b/poptint.h index 3a3ee9b..59841e0 100644 --- a/poptint.h +++ b/poptint.h @@ -11,11 +11,11 @@ /** * Wrapper to free(3), hides const compilation noise, permit NULL, return NULL. - * @param this memory to free + * @param p memory to free * @retval NULL always */ -/*@unused@*/ static inline /*@null@*/ void * _free(/*@only@*/ /*@null@*/ const void * this) { - if (this != NULL) free((void *)this); +/*@unused@*/ static inline /*@null@*/ void * _free(/*@only@*/ /*@null@*/ const void * p) { + if (p != NULL) free((void *)p); return NULL; } diff --git a/system.h b/system.h index 8015c64..2ff7588 100644 --- a/system.h +++ b/system.h @@ -42,9 +42,9 @@ char *alloca (); #define alloca __builtin_alloca #endif +#if !defined(__LCLINT__) /*@only@*/ char * xstrdup (const char *str); -#if !defined(__LCLINT__) #if HAVE_MCHECK_H && defined(__GNUC__) #define vmefail() (fprintf(stderr, "virtual memory exhausted.\n"), exit(EXIT_FAILURE), NULL) #define xstrdup(_str) (strcpy((malloc(strlen(_str)+1) ? : vmefail()), (_str))) -- cgit v1.2.1