RPM Package Manager, CVS Repository
http://rpm5.org/cvs/
____________________________________________________________________________
Server: rpm5.org Name: Jeff Johnson
Root: /v/rpm/cvs Email: jbj@rpm5.org
Module: popt Date: 04-Nov-2007 16:57:20
Branch: HEAD Handle: 2007110415572000
Modified files:
popt .splintrc CHANGES popt.c popt.h poptconfig.c
popthelp.c poptint.c poptint.h system.h
Log:
- jbj: rescuscitate the splint annotations.
Summary:
Revision Changes Path
1.8 +13 -43 popt/.splintrc
1.29 +1 -0 popt/CHANGES
1.105 +2 -0 popt/popt.c
1.61 +2 -2 popt/popt.h
1.34 +17 -7 popt/poptconfig.c
1.69 +26 -17 popt/popthelp.c
1.10 +44 -33 popt/poptint.c
1.26 +36 -2 popt/poptint.h
1.12 +25 -2 popt/system.h
____________________________________________________________________________
patch -p0 <<'@@ .'
Index: popt/.splintrc
============================================================================
$ cvs diff -u -r1.7 -r1.8 .splintrc
--- popt/.splintrc 4 Nov 2007 13:51:28 -0000 1.7
+++ popt/.splintrc 4 Nov 2007 15:57:20 -0000 1.8
@@ -17,58 +17,28 @@
-bitwisesigned
-branchstate
--compdef
--globuse
--internalglobs
--modnomods
--modobserveruncon
--mods
--moduncon
--modunconnomods
--mustmod
--noeffectuncon
--nullderef
--nullpass
--nullptrarith
--nullret
--nullstate
--protoparammatch
--retalias
--retvalint
--retvalother
--sizeoftype
--type
--unrecog
-
--temptrans
-
-+charint
--exportvar
-+matchanyintegral
--varuse
# --- +partial artifacts
# --- not-yet at strict level
-elseifcomplete # 18
--exportfcn # 25
--ifblock # 202
--namechecks # 206
--ptrarith # 43
+-exportfcn # 29
+-ifblock # 251
+-namechecks # 111
+-ptrarith # 47
--mustdefine # 10
--shiftimplementation # 120
+-mustdefine # 12
-sys-dir-errors
--strictops # 16
--whileblock # 10
+-strictops # 24
+-whileblock # 15
# --- not-yet at checks level
--mustfree # 52
--predboolptr # 62
--usedef # 1
+-mustfree # 38
+-predboolptr # 82
+-usedef # 7
# --- not-yet at standard level
--boolops # 112
--predboolint # 38
-+ignorequals # 17
+-boolops # 127
+-predboolint # 42
++ignorequals # 30
@@ .
patch -p0 <<'@@ .'
Index: popt/CHANGES
============================================================================
$ cvs diff -u -r1.28 -r1.29 CHANGES
--- popt/CHANGES 4 Nov 2007 13:51:28 -0000 1.28
+++ popt/CHANGES 4 Nov 2007 15:57:20 -0000 1.29
@@ -1,4 +1,5 @@
1.12 -> 1.13:
+ - jbj: rescuscitate the splint annotations.
- jbj: change sizeof to use the type implicitly, rather than explicitly.
- jbj: remove incorrect casts, changing to size_t where needed.
- jbj: remove unused STD_VFPRINTF macro.
@@ .
patch -p0 <<'@@ .'
Index: popt/popt.c
============================================================================
$ cvs diff -u -r1.104 -r1.105 popt.c
--- popt/popt.c 4 Nov 2007 13:15:32 -0000 1.104
+++ popt/popt.c 4 Nov 2007 15:57:20 -0000 1.105
@@ -446,7 +446,9 @@
}
#endif
+/*@-nullstate@*/
rc = execvp(argv[0], (char *const *)argv);
+/*@=nullstate@*/
exit:
if (argv) {
@@ .
patch -p0 <<'@@ .'
Index: popt/popt.h
============================================================================
$ cvs diff -u -r1.60 -r1.61 popt.h
--- popt/popt.h 14 Aug 2007 14:42:33 -0000 1.60
+++ popt/popt.h 4 Nov 2007 15:57:20 -0000 1.61
@@ -486,7 +486,7 @@
*/
void poptPrintHelp(poptContext con, FILE * fp, /*@unused@*/ int flags)
/*@globals fileSystem @*/
- /*@modifies *fp, fileSystem @*/;
+ /*@modifies fp, fileSystem @*/;
/** \ingroup popt
* Print terse description of options.
@@ -496,7 +496,7 @@
*/
void poptPrintUsage(poptContext con, FILE * fp, /*@unused@*/ int flags)
/*@globals fileSystem @*/
- /*@modifies *fp, fileSystem @*/;
+ /*@modifies fp, fileSystem @*/;
/** \ingroup popt
* Provide text to replace default "[OPTION...]" in help/usage output.
@@ .
patch -p0 <<'@@ .'
Index: popt/poptconfig.c
============================================================================
$ cvs diff -u -r1.33 -r1.34 poptconfig.c
--- popt/poptconfig.c 4 Nov 2007 13:15:32 -0000 1.33
+++ popt/poptconfig.c 4 Nov 2007 15:57:20 -0000 1.34
@@ -115,10 +115,12 @@
}
file = malloc(fileLength + 1);
- if (read(fd, (char *)file, fileLength) != fileLength) {
+ if (file == NULL || read(fd, (char *)file, fileLength) != fileLength) {
rc = errno;
(void) close(fd);
errno = rc;
+ if (file)
+ free(file);
return POPT_ERROR_ERRNO;
}
if (close(fd) == -1) {
@@ -127,6 +129,8 @@
}
dst = buf = malloc(fileLength + 1);
+ if (dst == NULL)
+ return POPT_ERROR_ERRNO;
chptr = file;
end = (file + fileLength);
@@ -182,9 +186,9 @@
rc = poptReadConfigFile(con, _popt_etc);
if (rc) return rc;
- stat("/etc/popt.d", &s);
- if(S_ISDIR(s.st_mode)) {
+ if (!stat("/etc/popt.d", &s) && S_ISDIR(s.st_mode)) {
glob_t g;
+/*@-moduncon -nullpass -type @*/ /* FIX: annotations for glob/globfree */
if (!glob("/etc/popt.d/*", 0, NULL, &g)) {
int i;
for (i=0; i<g.gl_pathc; i++) {
@@ -198,16 +202,22 @@
rc = poptReadConfigFile(con, f);
if (rc) return rc;
}
+/*@-noeffectuncon@*/
globfree(&g);
+/*@=noeffectuncon@*/
}
+/*@=moduncon =nullpass =type @*/
}
if ((home = getenv("HOME"))) {
fn = malloc(strlen(home) + 20);
- strcpy(fn, home);
- strcat(fn, "/.popt");
- rc = poptReadConfigFile(con, fn);
- free(fn);
+ if (fn != NULL) {
+ strcpy(fn, home);
+ strcat(fn, "/.popt");
+ rc = poptReadConfigFile(con, fn);
+ free(fn);
+ } else
+ rc = POPT_ERROR_ERRNO;
if (rc) return rc;
}
@@ .
patch -p0 <<'@@ .'
Index: popt/popthelp.c
============================================================================
$ cvs diff -u -r1.68 -r1.69 popthelp.c
--- popt/popthelp.c 4 Nov 2007 13:18:27 -0000 1.68
+++ popt/popthelp.c 4 Nov 2007 15:57:20 -0000 1.69
@@ -115,8 +115,9 @@
struct winsize ws;
int fdno = fileno(fp ? fp : stdout);
+ memset(&ws, 0, sizeof(ws));
if (fdno >= 0 && !ioctl(fdno, TIOCGWINSZ, &ws)
- && ws.ws_col > maxcols && ws.ws_col < 256)
+ && (size_t)ws.ws_col > maxcols && ws.ws_col < 256)
maxcols = ws.ws_col - 1;
#endif
return maxcols;
@@ -268,7 +269,7 @@
const struct poptOption * opt,
/*@null@*/ const char * translation_domain)
/*@globals fileSystem @*/
- /*@modifies *fp, fileSystem @*/
+ /*@modifies fp, fileSystem @*/
{
size_t maxLeftCol = columns->cur;
size_t indentLength = maxLeftCol + 5;
@@ -280,6 +281,7 @@
char * left;
size_t nb = maxLeftCol + 1;
int displaypad = 0;
+ int xx;
/* Make sure there's more than enough room in target buffer. */
if (opt->longName) nb += strlen(opt->longName);
@@ -404,9 +406,9 @@
}
if (help)
- POPT_fprintf(fp," %-*s ", (int)(maxLeftCol+displaypad), left);
+ xx = POPT_fprintf(fp," %-*s ", (int)(maxLeftCol+displaypad), left);
else {
- POPT_fprintf(fp," %s\n", left);
+ xx = POPT_fprintf(fp," %s\n", left);
goto out;
}
@@ -430,14 +432,14 @@
sprintf(format, "%%.%ds\n%%%ds", (int) (ch - help), (int) indentLength);
/*@-formatconst@*/
- POPT_fprintf(fp, format, help, " ");
+ xx = POPT_fprintf(fp, format, help, " ");
/*@=formatconst@*/
help = ch;
while (_isspaceptr(help) && *help) help++;
helpLength = strlen(help);
}
- if (helpLength) POPT_fprintf(fp, "%s\n", help);
+ if (helpLength) xx = POPT_fprintf(fp, "%s\n", help);
help = NULL;
out:
@@ -519,7 +521,7 @@
columns_t columns,
/*@null@*/ const char * translation_domain)
/*@globals fileSystem @*/
- /*@modifies *fp, fileSystem @*/
+ /*@modifies fp, fileSystem @*/
{
poptItem item;
int i;
@@ -547,10 +549,11 @@
columns_t columns,
/*@null@*/ const char * translation_domain)
/*@globals fileSystem @*/
- /*@modifies *fp, fileSystem @*/
+ /*@modifies fp, columns->cur, fileSystem @*/
{
const struct poptOption * opt;
const char *sub_transdom;
+ int xx;
if (table == poptAliasOptions) {
itemHelp(fp, con->aliases, con->numAliases, columns, NULL);
@@ -574,7 +577,7 @@
sub_transdom = translation_domain;
if (opt->descrip)
- POPT_fprintf(fp, "\n%s\n", D_(sub_transdom, opt->descrip));
+ xx = POPT_fprintf(fp, "\n%s\n", D_(sub_transdom, opt->descrip));
singleTableHelp(con, fp, opt->arg, columns, sub_transdom);
}
@@ -634,7 +637,7 @@
const struct poptOption * opt,
/*@null@*/ const char *translation_domain)
/*@globals fileSystem @*/
- /*@modifies *fp, fileSystem @*/
+ /*@modifies fp, columns->cur, fileSystem @*/
{
size_t len = (size_t)4;
char shortStr[2] = { '\0', '\0' };
@@ -712,7 +715,7 @@
/*@null@*/ poptItem item, int nitems,
/*@null@*/ const char * translation_domain)
/*@globals fileSystem @*/
- /*@modifies *fp, fileSystem @*/
+ /*@modifies fp, columns->cur, fileSystem @*/
{
int i;
@@ -737,6 +740,7 @@
typedef struct poptDone_s {
int nopts;
int maxopts;
+/*@null@*/
const void ** opts;
} * poptDone;
@@ -755,7 +759,7 @@
/*@null@*/ const char * translation_domain,
/*@null@*/ poptDone done)
/*@globals fileSystem @*/
- /*@modifies *fp, done, fileSystem @*/
+ /*@modifies fp, columns->cur, done, fileSystem @*/
{
if (opt != NULL)
for (; (opt->longName || opt->shortName || opt->arg) ; opt++) {
@@ -763,7 +767,8 @@
translation_domain = (const char *)opt->arg;
} else if ((opt->argInfo & POPT_ARG_MASK) == POPT_ARG_INCLUDE_TABLE) {
if (done) {
- int i = 0;
+ int i;
+ if (done->opts != NULL)
for (i = 0; i < done->nopts; i++) {
const void * that = done->opts[i];
if (that == NULL || that != opt->arg)
@@ -773,7 +778,7 @@
/* Skip if this table has already been processed. */
if (opt->arg == NULL || i < done->nopts)
continue;
- if (done->nopts < done->maxopts)
+ if (done->opts != NULL && done->nopts < done->maxopts)
done->opts[done->nopts++] = (const void *) opt->arg;
}
columns->cur = singleTableUsage(con, fp, columns, opt->arg,
@@ -798,7 +803,7 @@
static size_t showShortOptions(const struct poptOption * opt, FILE * fp,
/*@null@*/ char * str)
/*@globals fileSystem @*/
- /*@modifies *str, *fp, fileSystem @*/
+ /*@modifies str, *fp, fileSystem @*/
/*@requires maxRead(str) >= 0 @*/
{
/* bufsize larger then the ascii set, lazy allocation on top level call. */
@@ -823,8 +828,10 @@
fprintf(fp, " [-%s]", s);
len = strlen(s) + sizeof(" [-]")-1;
}
+/*@-temptrans@*/ /* LCL: local s, not str arg, is being freed. */
if (s != str)
free(s);
+/*@=temptrans@*/
return len;
}
@@ -842,7 +849,8 @@
columns->max = maxColumnWidth(fp);
done->opts = calloc(1, columns->cur);
/*@-keeptrans@*/
- done->opts[done->nopts++] = (const void *) con->options;
+ if (done->opts != NULL)
+ done->opts[done->nopts++] = (const void *) con->options;
/*@=keeptrans@*/
columns->cur = showHelpIntro(con, fp);
@@ -858,7 +866,8 @@
}
fprintf(fp, "\n");
- free(done->opts);
+ if (done->opts != NULL)
+ free(done->opts);
free(columns);
}
}
@@ .
patch -p0 <<'@@ .'
Index: popt/poptint.c
============================================================================
$ cvs diff -u -r1.9 -r1.10 poptint.c
--- popt/poptint.c 4 Nov 2007 13:51:28 -0000 1.9
+++ popt/poptint.c 4 Nov 2007 15:57:20 -0000 1.10
@@ -1,48 +1,44 @@
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-
-#include <stdio.h>
-#include <stdarg.h>
-#include <errno.h>
-#ifdef HAVE_ICONV
-#include <iconv.h>
-#endif
-#ifdef HAVE_LANGINFO_H
-#include <langinfo.h>
-#endif
-
#include "system.h"
+#include <stdarg.h>
#include "poptint.h"
#ifdef HAVE_ICONV
-static char *
-strdup_locale_from_utf8 (char *buffer)
+static /*@only@*/ /*@null@*/ char *
+strdup_locale_from_utf8 (/*@null@*/ char *buffer)
+ /*@*/
{
char *codeset = NULL;
- char *pout = NULL, *dest_str;
+ char *dest_str;
iconv_t fd;
- size_t ib, ob, dest_size;
- int done, is_error;
- size_t err, used;
- if (!buffer)
+ if (buffer == NULL)
return NULL;
#ifdef HAVE_LANGINFO_H
+/*@-type@*/
codeset = nl_langinfo (CODESET);
+/*@=type@*/
#endif
if (codeset && strcmp(codeset, "UTF-8")
&& (fd = iconv_open(codeset, "UTF-8")) != (iconv_t)-1)
{
char *pin = buffer;
+ char *pout = NULL;
+ size_t ib, ob, dest_size;
+ int done;
+ int is_error;
+ size_t err;
char *shift_pin = NULL;
+ int xx;
err = iconv(fd, NULL, &ib, &pout, &ob);
dest_size = ob = ib = strlen(buffer);
dest_str = pout = malloc((dest_size + 1) * sizeof(*dest_str));
+ if (dest_str)
+ *dest_str = '\0';
done = is_error = 0;
+ if (pout != NULL)
while (!done && !is_error) {
err = iconv(fd, &pin, &ib, &pout, &ob);
@@ -52,12 +48,16 @@
done = 1;
/*@switchbreak@*/ break;
case E2BIG:
- used = pout - dest_str;
+ { size_t used = pout - dest_str;
dest_size *= 2;
dest_str = realloc(dest_str, (dest_size + 1) * sizeof(*dest_str));
+ if (dest_str == NULL) {
+ is_error = 1;
+ continue;
+ }
pout = dest_str + used;
ob = dest_size - used;
- /*@switchbreak@*/ break;
+ } /*@switchbreak@*/ break;
case EILSEQ:
is_error = 1;
/*@switchbreak@*/ break;
@@ -66,7 +66,7 @@
/*@switchbreak@*/ break;
}
} else {
- if (!shift_pin) {
+ if (shift_pin == NULL) {
shift_pin = pin;
pin = NULL;
ib = 0;
@@ -75,42 +75,51 @@
}
}
}
- iconv_close(fd);
- *pout = '\0';
- dest_str = strdup(dest_str);
+ xx = iconv_close(fd);
+ if (pout)
+ *pout = '\0';
+ if (dest_str != NULL)
+ dest_str = xstrdup(dest_str);
} else {
- dest_str = strdup(buffer);
+ dest_str = xstrdup(buffer);
}
return dest_str;
}
#endif
-static char *
+/*@-mustmod@*/ /* LCL: can't see the ap modification. */
+static /*@only@*/ /*@null@*/ char *
strdup_vprintf (const char *format, va_list ap)
+ /*@modifies ap @*/
{
- char *buffer = NULL;
+ char *buffer;
char c;
va_list apc;
+ int xx;
+/*@-noeffectuncon -unrecog @*/
va_copy(apc, ap); /* XXX linux amd64/ppc needs a copy. */
+/*@=noeffectuncon =unrecog @*/
buffer = calloc(sizeof(*buffer), vsnprintf (&c, 1, format, ap) + 1);
- vsprintf(buffer, format, apc);
+ if (buffer != NULL)
+ xx = vsprintf(buffer, format, apc);
va_end(apc);
return buffer;
}
+/*@=mustmod@*/
char *
POPT_prev_char (const char *str)
{
- char *p = (char*)str;
+ char *p = (char *)str;
while (1) {
p--;
- if ((*p & 0xc0) != 0x80)
+ if ((*p & 0xc0) != (char)0x80)
return (char *)p;
}
}
@@ -128,6 +137,8 @@
va_start (args, format);
buffer = strdup_vprintf(format, args);
va_end (args);
+ if (buffer == NULL)
+ return retval;
#ifdef HAVE_ICONV
locale_str = strdup_locale_from_utf8(buffer);
@@ .
patch -p0 <<'@@ .'
Index: popt/poptint.h
============================================================================
$ cvs diff -u -r1.25 -r1.26 poptint.h
--- popt/poptint.h 15 Jun 2007 12:49:56 -0000 1.25
+++ popt/poptint.h 4 Nov 2007 15:57:20 -0000 1.26
@@ -114,7 +114,41 @@
#define N_(foo) foo
-int POPT_fprintf (FILE* steam, const char *format, ...);
-char *POPT_prev_char (const char *str);
+#ifdef HAVE_ICONV
+#include <iconv.h>
+#if defined(__LCLINT__)
+/*@-declundef -incondefs @*/
+extern /*@only@*/ iconv_t iconv_open(const char *__tocode, const char *__fromcode)
+ /*@*/;
+
+extern size_t iconv(iconv_t __cd, /*@null@*/ char ** __inbuf,
+ /*@out@*/ size_t * __inbytesleft,
+ /*@out@*/ char ** __outbuf,
+ /*@out@*/ size_t * __outbytesleft)
+ /*@modifies __cd,
+ *__inbuf, *__inbytesleft, *__outbuf, *__outbytesleft @*/;
+
+extern int iconv_close(/*@only@*/ iconv_t __cd)
+ /*@modifies __cd @*/;
+/*@=declundef =incondefs @*/
+#endif
+#endif
+
+#ifdef HAVE_LANGINFO_H
+#include <langinfo.h>
+#if defined(__LCLINT__)
+/*@-declundef -incondefs @*/
+extern char *nl_langinfo (nl_item __item)
+ /*@*/;
+/*@=declundef =incondefs @*/
+#endif
+#endif
+
+int POPT_fprintf (FILE* stream, const char *format, ...)
+ /*@globals fileSystem @*/
+ /*@modifies stream, fileSystem @*/;
+
+char *POPT_prev_char (/*@returned@*/ const char *str)
+ /*@*/;
#endif
@@ .
patch -p0 <<'@@ .'
Index: popt/system.h
============================================================================
$ cvs diff -u -r1.11 -r1.12 system.h
--- popt/system.h 3 Nov 2007 22:50:33 -0000 1.11
+++ popt/system.h 4 Nov 2007 15:57:20 -0000 1.12
@@ -42,16 +42,39 @@
#include <libc.h>
#endif
-/*@-redecl -redef@*/
+/*@-incondefs@*/
+/*@mayexit@*/ /*@only@*/ /*@out@*/ /*@unused@*/
+void * xmalloc (size_t size)
+ /*@globals errno @*/
+ /*@ensures maxSet(result) == (size - 1) @*/
+ /*@modifies errno @*/;
+
+/*@mayexit@*/ /*@only@*/ /*@unused@*/
+void * xcalloc (size_t nmemb, size_t size)
+ /*@ensures maxSet(result) == (nmemb - 1) @*/
+ /*@*/;
+
+/*@mayexit@*/ /*@only@*/ /*@unused@*/
+void * xrealloc (/*@null@*/ /*@only@*/ void * ptr, size_t size)
+ /*@ensures maxSet(result) == (size - 1) @*/
+ /*@modifies *ptr @*/;
+
/*@mayexit@*/ /*@only@*/ /*@unused@*/
char * xstrdup (const char *str)
/*@*/;
-/*@=redecl =redef@*/
+/*@=incondefs@*/
+/* Memory allocation via macro defs to get meaningful locations from mtrace() */
#if defined(HAVE_MCHECK_H) && defined(__GNUC__)
#define vmefail() (fprintf(stderr, "virtual memory exhausted.\n"), exit(EXIT_FAILURE), NULL)
+#define xmalloc(_size) (malloc(_size) ? : vmefail())
+#define xcalloc(_nmemb, _size) (calloc((_nmemb), (_size)) ? : vmefail())
+#define xrealloc(_ptr, _size) (realloc((_ptr), (_size)) ? : vmefail())
#define xstrdup(_str) (strcpy((malloc(strlen(_str)+1) ? : vmefail()), (_str)))
#else
+#define xmalloc(_size) malloc(_size)
+#define xcalloc(_nmemb, _size) calloc((_nmemb), (_size))
+#define xrealloc(_ptr, _size) realloc((_ptr), (_size))
#define xstrdup(_str) strdup(_str)
#endif /* defined(HAVE_MCHECK_H) && defined(__GNUC__) */
@@ .
Received on Sun Nov 4 16:57:20 2007