mirror of
https://github.com/irssi/irssi.git
synced 2026-08-20 17:12:51 +02:00
don't use alloca()
git-svn-id: http://svn.irssi.org/repos/irssi/trunk@917 dbcabf3a-b0e7-0310-adc4-f8d773084564
This commit is contained in:
parent
0cb6db26d9
commit
32790f1515
1 changed files with 33 additions and 18 deletions
|
|
@ -4,10 +4,6 @@
|
||||||
|
|
||||||
#include "common.h"
|
#include "common.h"
|
||||||
|
|
||||||
#if HAVE_ALLOCA_H
|
|
||||||
# include <alloca.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include "findme.h"
|
#include "findme.h"
|
||||||
#include "popt.h"
|
#include "popt.h"
|
||||||
#include "poptint.h"
|
#include "poptint.h"
|
||||||
|
|
@ -181,8 +177,7 @@ static void execCommand(poptContext con) {
|
||||||
if (!con->execAbsolute && strchr(script, '/')) return;
|
if (!con->execAbsolute && strchr(script, '/')) return;
|
||||||
|
|
||||||
if (!strchr(script, '/') && con->execPath) {
|
if (!strchr(script, '/') && con->execPath) {
|
||||||
argv[pos] = alloca(strlen(con->execPath) + strlen(script) + 2);
|
argv[pos] = g_strdup_printf("%s/%s", con->execPath, script);
|
||||||
sprintf(argv[pos], "%s/%s", con->execPath, script);
|
|
||||||
} else {
|
} else {
|
||||||
argv[pos] = script;
|
argv[pos] = script;
|
||||||
}
|
}
|
||||||
|
|
@ -274,7 +269,7 @@ static const struct poptOption * findOption(const struct poptOption * table,
|
||||||
int poptGetNextOpt(poptContext con) {
|
int poptGetNextOpt(poptContext con) {
|
||||||
char * optString, * chptr, * localOptString;
|
char * optString, * chptr, * localOptString;
|
||||||
char * longArg = NULL;
|
char * longArg = NULL;
|
||||||
char * origOptString;
|
char * origOptString, *dup;
|
||||||
long aLong;
|
long aLong;
|
||||||
char * end;
|
char * end;
|
||||||
const struct poptOption * opt = NULL;
|
const struct poptOption * opt = NULL;
|
||||||
|
|
@ -284,7 +279,12 @@ int poptGetNextOpt(poptContext con) {
|
||||||
void * cbData;
|
void * cbData;
|
||||||
int singleDash;
|
int singleDash;
|
||||||
|
|
||||||
|
dup = NULL;
|
||||||
while (!done) {
|
while (!done) {
|
||||||
|
if (dup) {
|
||||||
|
g_free(dup);
|
||||||
|
dup = NULL;
|
||||||
|
}
|
||||||
while (!con->os->nextCharArg && con->os->next == con->os->argc
|
while (!con->os->nextCharArg && con->os->next == con->os->argc
|
||||||
&& con->os > con->optionStack)
|
&& con->os > con->optionStack)
|
||||||
con->os--;
|
con->os--;
|
||||||
|
|
@ -306,12 +306,13 @@ int poptGetNextOpt(poptContext con) {
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Make a copy we can hack at */
|
/* Make a copy we can hack at */
|
||||||
localOptString = optString =
|
dup = localOptString = optString =
|
||||||
strcpy(alloca(strlen(origOptString) + 1),
|
g_strdup(origOptString);
|
||||||
origOptString);
|
|
||||||
|
|
||||||
if (!optString[0])
|
if (!optString[0]) {
|
||||||
|
g_free(dup);
|
||||||
return POPT_ERROR_BADOPT;
|
return POPT_ERROR_BADOPT;
|
||||||
|
}
|
||||||
|
|
||||||
if (optString[1] == '-' && !optString[2]) {
|
if (optString[1] == '-' && !optString[2]) {
|
||||||
con->restLeftover = 1;
|
con->restLeftover = 1;
|
||||||
|
|
@ -337,7 +338,10 @@ int poptGetNextOpt(poptContext con) {
|
||||||
|
|
||||||
opt = findOption(con->options, optString, '\0', &cb, &cbData,
|
opt = findOption(con->options, optString, '\0', &cb, &cbData,
|
||||||
singleDash);
|
singleDash);
|
||||||
if (!opt && !singleDash) return POPT_ERROR_BADOPT;
|
if (!opt && !singleDash) {
|
||||||
|
g_free(dup);
|
||||||
|
return POPT_ERROR_BADOPT;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!opt)
|
if (!opt)
|
||||||
|
|
@ -359,8 +363,10 @@ int poptGetNextOpt(poptContext con) {
|
||||||
|
|
||||||
opt = findOption(con->options, NULL, *origOptString, &cb,
|
opt = findOption(con->options, NULL, *origOptString, &cb,
|
||||||
&cbData, 0);
|
&cbData, 0);
|
||||||
if (!opt) return POPT_ERROR_BADOPT;
|
if (!opt) {
|
||||||
|
g_free(dup);
|
||||||
|
return POPT_ERROR_BADOPT;
|
||||||
|
}
|
||||||
origOptString++;
|
origOptString++;
|
||||||
if (*origOptString)
|
if (*origOptString)
|
||||||
con->os->nextCharArg = origOptString;
|
con->os->nextCharArg = origOptString;
|
||||||
|
|
@ -380,8 +386,10 @@ int poptGetNextOpt(poptContext con) {
|
||||||
while (con->os->next == con->os->argc &&
|
while (con->os->next == con->os->argc &&
|
||||||
con->os > con->optionStack)
|
con->os > con->optionStack)
|
||||||
con->os--;
|
con->os--;
|
||||||
if (con->os->next == con->os->argc)
|
if (con->os->next == con->os->argc) {
|
||||||
|
g_free(dup);
|
||||||
return POPT_ERROR_NOARG;
|
return POPT_ERROR_NOARG;
|
||||||
|
}
|
||||||
|
|
||||||
con->os->nextArg = con->os->argv[con->os->next++];
|
con->os->nextArg = con->os->argv[con->os->next++];
|
||||||
}
|
}
|
||||||
|
|
@ -395,16 +403,22 @@ int poptGetNextOpt(poptContext con) {
|
||||||
case POPT_ARG_INT:
|
case POPT_ARG_INT:
|
||||||
case POPT_ARG_LONG:
|
case POPT_ARG_LONG:
|
||||||
aLong = strtol(con->os->nextArg, &end, 0);
|
aLong = strtol(con->os->nextArg, &end, 0);
|
||||||
if (!(end && *end == '\0'))
|
if (!(end && *end == '\0')) {
|
||||||
|
g_free(dup);
|
||||||
return POPT_ERROR_BADNUMBER;
|
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;
|
return POPT_ERROR_OVERFLOW;
|
||||||
|
}
|
||||||
if ((opt->argInfo & POPT_ARG_MASK) == POPT_ARG_LONG) {
|
if ((opt->argInfo & POPT_ARG_MASK) == POPT_ARG_LONG) {
|
||||||
*((long *) opt->arg) = aLong;
|
*((long *) opt->arg) = aLong;
|
||||||
} else {
|
} else {
|
||||||
if (aLong > INT_MAX || aLong < INT_MIN)
|
if (aLong > INT_MAX || aLong < INT_MIN) {
|
||||||
|
g_free(dup);
|
||||||
return POPT_ERROR_OVERFLOW;
|
return POPT_ERROR_OVERFLOW;
|
||||||
|
}
|
||||||
*((int *) opt->arg) =aLong;
|
*((int *) opt->arg) =aLong;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
@ -441,6 +455,7 @@ int poptGetNextOpt(poptContext con) {
|
||||||
con->finalArgv[con->finalArgvCount++] = g_strdup(con->os->nextArg);
|
con->finalArgv[con->finalArgvCount++] = g_strdup(con->os->nextArg);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (dup) g_free(dup);
|
||||||
return opt->val;
|
return opt->val;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue