Group :: Sistema/Bibliotecas
RPM: libpopt
Main Changelog Spec Patches Sources Download Gear Bugs e FR Repocop
Patch: popt-20020315-alt-x-alloc.patch
Download
Download
diff -ur popt-20020315~/findme.c popt-20020315/findme.c
--- popt-20020315~/findme.c Fri Mar 15 09:29:44 2002
+++ popt-20020315/findme.c Mon Mar 25 14:12:30 2002
@@ -23,7 +23,7 @@
if (path == NULL) return NULL;
start = pathbuf = alloca(strlen(path) + 1);
- buf = malloc(strlen(path) + strlen(argv0) + sizeof("/"));
+ buf = xmalloc(strlen(path) + strlen(argv0) + sizeof("/"));
if (buf == NULL) return NULL; /* XXX can't happen */
strcpy(pathbuf, path);
@@ -44,7 +44,7 @@
} while (start && *start);
/*@=branchstate@*/
- free(buf);
+ xfree(buf);
return NULL;
}
diff -ur popt-20020315~/popt.c popt-20020315/popt.c
--- popt-20020315~/popt.c Mon Mar 25 14:12:18 2002
+++ popt-20020315/popt.c Mon Mar 25 14:19:26 2002
@@ -149,7 +149,7 @@
poptContext poptGetContext(const char * name, int argc, const char ** argv,
const struct poptOption * options, int flags)
{
- poptContext con = malloc(sizeof(*con));
+ poptContext con = xmalloc(sizeof(*con));
if (con == NULL) return NULL; /* XXX can't happen */
memset(con, 0, sizeof(*con));
@@ -166,7 +166,7 @@
if (!(flags & POPT_CONTEXT_KEEP_FIRST))
con->os->next = 1; /* skip argv[0] */
- con->leftovers = calloc( (argc + 1), sizeof(*con->leftovers) );
+ con->leftovers = xcalloc( (argc + 1), sizeof(*con->leftovers) );
/*@-dependenttrans -assignexpose@*/ /* FIX: W2DO? */
con->options = options;
/*@=dependenttrans =assignexpose@*/
@@ -176,7 +176,7 @@
con->execs = NULL;
con->numExecs = 0;
con->finalArgvAlloced = argc * 2;
- con->finalArgv = calloc( con->finalArgvAlloced, sizeof(*con->finalArgv) );
+ con->finalArgv = xcalloc( con->finalArgvAlloced, sizeof(*con->finalArgv) );
if ( !con->finalArgv ) con->finalArgvAlloced = 0; /* XXX can't happen? */
con->execAbsolute = 1;
con->arg_strip = NULL;
@@ -185,7 +185,7 @@
con->flags |= POPT_CONTEXT_POSIXMEHARDER;
if (name) {
- char * t = malloc(strlen(name) + 1);
+ char * t = xmalloc(strlen(name) + 1);
if (t) con->appName = strcpy(t, name);
}
@@ -276,14 +276,14 @@
time 'round */
if ((con->finalArgvCount + 1) >= (con->finalArgvAlloced)) {
con->finalArgvAlloced += 10;
- con->finalArgv = realloc(con->finalArgv,
+ con->finalArgv = xrealloc(con->finalArgv,
sizeof(*con->finalArgv) * con->finalArgvAlloced);
if ( !con->finalArgv ) con->finalArgvCount = con->finalArgvAlloced = 0; /* XXX can't happen? */
}
i = con->finalArgvCount++;
if (con->finalArgv != NULL) /* XXX can't happen */
- { char *s = malloc((longName ? strlen(longName) : 0) + 3);
+ { char *s = xmalloc((longName ? strlen(longName) : 0) + 3);
if (s != NULL) { /* XXX can't happen */
if (longName)
sprintf(s, "--%s", longName);
@@ -367,7 +367,7 @@
(!con->execAbsolute && strchr(item->argv[0], '/')))
return POPT_ERROR_NOARG;
- argv = malloc(sizeof(*argv) *
+ argv = xmalloc(sizeof(*argv) *
(6 + item->argc + con->numLeftovers + con->finalArgvCount));
if (argv == NULL) return POPT_ERROR_MALLOC; /* XXX can't happen */
@@ -555,7 +555,7 @@
char c;
if (!con) return NULL;
- te = t = malloc(tn);;
+ te = t = xmalloc(tn);
if (t == NULL) return NULL; /* XXX can't happen */
while ((c = *s++) != '\0') {
switch (c) {
@@ -577,7 +577,7 @@
alen = strlen(a);
tn += alen;
*te = '\0';
- t = realloc(t, tn);
+ t = xrealloc(t, tn);
if ( !t ) return NULL; /* XXX can't happen? */
te = t + strlen(t);
strncpy(te, a, alen); te += alen;
@@ -589,7 +589,7 @@
*te++ = c;
}
*te = '\0';
- t = realloc(t, strlen(t) + 1); /* XXX memory leak, hard to plug */
+ t = xrealloc(t, strlen(t) + 1); /* XXX memory leak, hard to plug */
return t;
}
@@ -942,13 +942,13 @@
if ((con->finalArgvCount + 2) >= (con->finalArgvAlloced)) {
con->finalArgvAlloced += 10;
- con->finalArgv = realloc(con->finalArgv,
+ con->finalArgv = xrealloc(con->finalArgv,
sizeof(*con->finalArgv) * con->finalArgvAlloced);
if ( !con->finalArgv ) con->finalArgvCount = con->finalArgvAlloced = 0; /* XXX can't happen? */
}
if (con->finalArgv != NULL)
- { char *s = malloc((opt->longName ? strlen(opt->longName) : 0) + 3);
+ { char *s = xmalloc((opt->longName ? strlen(opt->longName) : 0) + 3);
if (s != NULL) { /* XXX can't happen */
if (opt->longName)
sprintf(s, "%s%s",
@@ -1104,7 +1104,7 @@
/*@notreached@*/ break;
}
- *items = realloc((*items), ((*nitems) + 1) * sizeof(**items));
+ *items = xrealloc((*items), ((*nitems) + 1) * sizeof(**items));
if ((*items) == NULL)
return 1;
diff -ur popt-20020315~/popthelp.c popt-20020315/popthelp.c
--- popt-20020315~/popthelp.c Mon Mar 25 14:12:18 2002
+++ popt-20020315/popthelp.c Mon Mar 25 14:12:30 2002
@@ -120,7 +120,7 @@
/*@*/
{
const char * defstr = D_(translation_domain, "default");
- char * le = malloc(4*lineLength + 1);
+ char * le = xmalloc(4*lineLength + 1);
char * l = le;
if (le == NULL) return NULL; /* XXX can't happen */
@@ -198,7 +198,7 @@
if (opt->longName) nb += strlen(opt->longName);
if (argDescrip) nb += strlen(argDescrip);
- left = malloc(nb);
+ left = xmalloc(nb);
if (left == NULL) return; /* XXX can't happen */
left[0] = '\0';
left[maxLeftCol] = '\0';
@@ -225,7 +225,7 @@
if (opt->argInfo & POPT_ARGFLAG_SHOW_DEFAULT) {
defs = singleOptionDefaultValue(lineLength, opt, translation_domain);
if (defs) {
- char * t = malloc((help ? strlen(help) : 0) +
+ char * t = xmalloc((help ? strlen(help) : 0) +
strlen(defs) + sizeof(" "));
if (t) {
char * te = t;
diff -ur popt-20020315~/poptparse.c popt-20020315/poptparse.c
--- popt-20020315~/poptparse.c Fri Mar 15 09:29:44 2002
+++ popt-20020315/poptparse.c Mon Mar 25 14:12:30 2002
@@ -26,7 +26,7 @@
nb += strlen(argv[i]) + 1;
}
- dst = malloc(nb);
+ dst = xmalloc(nb);
if (dst == NULL) /* XXX can't happen */
return POPT_ERROR_MALLOC;
argv2 = (void *) dst;
@@ -43,7 +43,7 @@
if (argvPtr) {
*argvPtr = argv2;
} else {
- free(argv2);
+ xfree(argv2);
argv2 = NULL;
}
if (argcPtr)
@@ -56,7 +56,7 @@
const char * src;
char quote = '\0';
int argvAlloced = POPT_ARGV_ARRAY_GROW_DELTA;
- const char ** argv = malloc(sizeof(*argv) * argvAlloced);
+ const char ** argv = xmalloc(sizeof(*argv) * argvAlloced);
int argc = 0;
int buflen = strlen(s) + 1;
char * buf = memset(alloca(buflen), 0, buflen);
@@ -83,7 +83,7 @@
buf++, argc++;
if (argc == argvAlloced) {
argvAlloced += POPT_ARGV_ARRAY_GROW_DELTA;
- argv = realloc(argv, sizeof(*argv) * argvAlloced);
+ argv = xrealloc(argv, sizeof(*argv) * argvAlloced);
if (argv == NULL) goto exit;
}
argv[argc] = buf;
diff -ur popt-20020315~/system.h popt-20020315/system.h
--- popt-20020315~/system.h Fri Mar 15 09:29:44 2002
+++ popt-20020315/system.h Mon Mar 25 14:16:38 2002
@@ -1,9 +1,13 @@
+#ifndef __POPT_SYSTEM_H__
+#define __POPT_SYSTEM_H__
+
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <ctype.h>
#include <errno.h>
+#include <error.h>
#include <fcntl.h>
#include <limits.h>
@@ -50,17 +54,54 @@
#define alloca __builtin_alloca
#endif
-/*@-redecl -redef@*/
-/*@mayexit@*/ /*@only@*/ char * xstrdup (const char *str)
- /*@*/;
-/*@=redecl =redef@*/
-
#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)))
+static inline void *xmalloc(size_t size)
+{
+ void *p = malloc(size);
+ if (!p)
+ error(EXIT_FAILURE, errno, "popt: malloc");
+ return p;
+}
+
+static inline void *xcalloc(size_t nmemb, size_t size)
+{
+ void *p = calloc(nmemb, size);
+ if (!p)
+ error(EXIT_FAILURE, errno, "popt: calloc");
+ return p;
+}
+
+static inline void *xrealloc(void *ptr, size_t size)
+{
+ void *p = realloc(ptr, size);
+ if (!p)
+ error(EXIT_FAILURE, errno, "popt: realloc");
+ return p;
+}
+
+static inline char *xstrdup(const char *s)
+{
+ char *r = strdup(s);
+ if (!r)
+ error(EXIT_FAILURE, errno, "popt: strdup");
+ return r;
+}
+
+static inline void xfree(void *ptr)
+{
+ if (ptr)
+ free(ptr);
+ else
+ error(EXIT_SUCCESS, EINVAL, "popt: free");
+}
#else
-#define xstrdup(_str) strdup(_str)
+#define xmalloc(size) malloc(size)
+#define xcalloc(nmemb, size) calloc((nmemb), (size))
+#define xrealloc(ptr, size) realloc((ptr), (size))
+#define xstrdup(s) strdup(s)
+#define xfree(ptr) free(ptr)
#endif /* HAVE_MCHECK_H && defined(__GNUC__) */
#include "popt.h"
+#endif /* __POPT_SYSTEM_H__ */