summaryrefslogtreecommitdiff
path: root/src/lib-popt
diff options
context:
space:
mode:
authorTimo Sirainen <cras@irssi.org>2000-12-02 07:02:59 +0000
committercras <cras@dbcabf3a-b0e7-0310-adc4-f8d773084564>2000-12-02 07:02:59 +0000
commit32790f15151664d7869f4e898c833f1ede81c0f9 (patch)
tree9f61a55f0d803f3e29f85265327caaac476cd3ed /src/lib-popt
parent0cb6db26d98c76b7965b0b9ddf2ed2e2892257cb (diff)
downloadirssi-32790f15151664d7869f4e898c833f1ede81c0f9.zip
don't use alloca()
git-svn-id: http://svn.irssi.org/repos/irssi/trunk@917 dbcabf3a-b0e7-0310-adc4-f8d773084564
Diffstat (limited to 'src/lib-popt')
-rw-r--r--src/lib-popt/popt.c51
1 files changed, 33 insertions, 18 deletions
diff --git a/src/lib-popt/popt.c b/src/lib-popt/popt.c
index 7b11a3c3..c09a0b30 100644
--- a/src/lib-popt/popt.c
+++ b/src/lib-popt/popt.c
@@ -4,10 +4,6 @@
#include "common.h"
-#if HAVE_ALLOCA_H
-# include <alloca.h>
-#endif
-
#include "findme.h"
#include "popt.h"
#include "poptint.h"
@@ -181,8 +177,7 @@ static void execCommand(poptContext con) {
if (!con->execAbsolute && strchr(script, '/')) return;
if (!strchr(script, '/') && con->execPath) {
- argv[pos] = alloca(strlen(con->execPath) + strlen(script) + 2);
- sprintf(argv[pos], "%s/%s", con->execPath, script);
+ argv[pos] = g_strdup_printf("%s/%s", con->execPath, script);
} else {
argv[pos] = script;
}
@@ -274,7 +269,7 @@ static const struct poptOption * findOption(const struct poptOption * table,
int poptGetNextOpt(poptContext con) {
char * optString, * chptr, * localOptString;
char * longArg = NULL;
- char * origOptString;
+ char * origOptString, *dup;
long aLong;
char * end;
const struct poptOption * opt = NULL;
@@ -284,7 +279,12 @@ int poptGetNextOpt(poptContext con) {
void * cbData;
int singleDash;
+ dup = NULL;
while (!done) {
+ if (dup) {
+ g_free(dup);
+ dup = NULL;
+ }
while (!con->os->nextCharArg && con->os->next == con->os->argc
&& con->os > con->optionStack)
con->os--;
@@ -306,12 +306,13 @@ int poptGetNextOpt(poptContext con) {
}
/* Make a copy we can hack at */
- localOptString = optString =
- strcpy(alloca(strlen(origOptString) + 1),
- origOptString);
+ dup = localOptString = optString =
+ g_strdup(origOptString);
- if (!optString[0])
+ if (!optString[0]) {
+ g_free(dup);
return POPT_ERROR_BADOPT;
+ }
if (optString[1] == '-' && !optString[2]) {
con->restLeftover = 1;
@@ -337,7 +338,10 @@ int poptGetNextOpt(poptContext con) {
opt = findOption(con->options, optString, '\0', &cb, &cbData,
singleDash);
- if (!opt && !singleDash) return POPT_ERROR_BADOPT;
+ if (!opt && !singleDash) {
+ g_free(dup);
+ return POPT_ERROR_BADOPT;
+ }
}
if (!opt)
@@ -359,8 +363,10 @@ int poptGetNextOpt(poptContext con) {
opt = findOption(con->options, NULL, *origOptString, &cb,
&cbData, 0);
- if (!opt) return POPT_ERROR_BADOPT;
-
+ if (!opt) {
+ g_free(dup);
+ return POPT_ERROR_BADOPT;
+ }
origOptString++;
if (*origOptString)
con->os->nextCharArg = origOptString;
@@ -380,8 +386,10 @@ int poptGetNextOpt(poptContext con) {
while (con->os->next == con->os->argc &&
con->os > con->optionStack)
con->os--;
- if (con->os->next == con->os->argc)
+ if (con->os->next == con->os->argc) {
+ g_free(dup);
return POPT_ERROR_NOARG;
+ }
con->os->nextArg = con->os->argv[con->os->next++];
}
@@ -395,16 +403,22 @@ int poptGetNextOpt(poptContext con) {
case POPT_ARG_INT:
case POPT_ARG_LONG:
aLong = strtol(con->os->nextArg, &end, 0);
- if (!(end && *end == '\0'))
+ if (!(end && *end == '\0')) {
+ g_free(dup);
return POPT_ERROR_BADNUMBER;
+ }
- if (aLong == LONG_MIN || aLong == LONG_MAX)
+ if (aLong == LONG_MIN || aLong == LONG_MAX) {
+ g_free(dup);
return POPT_ERROR_OVERFLOW;
+ }
if ((opt->argInfo & POPT_ARG_MASK) == POPT_ARG_LONG) {
*((long *) opt->arg) = aLong;
} else {
- if (aLong > INT_MAX || aLong < INT_MIN)
+ if (aLong > INT_MAX || aLong < INT_MIN) {
+ g_free(dup);
return POPT_ERROR_OVERFLOW;
+ }
*((int *) opt->arg) =aLong;
}
break;
@@ -441,6 +455,7 @@ int poptGetNextOpt(poptContext con) {
con->finalArgv[con->finalArgvCount++] = g_strdup(con->os->nextArg);
}
+ if (dup) g_free(dup);
return opt->val;
}