forked from PsychoticNinja/irssi
..and removed the rest of the alloca()s too
git-svn-id: http://svn.irssi.org/repos/irssi/trunk@918 dbcabf3a-b0e7-0310-adc4-f8d773084564
This commit is contained in:
parent
32790f1515
commit
cfd50ce9cd
@ -10,10 +10,6 @@
|
|||||||
#include <libc.h>
|
#include <libc.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if HAVE_ALLOCA_H
|
|
||||||
# include <alloca.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include "findme.h"
|
#include "findme.h"
|
||||||
|
|
||||||
char * findProgramPath(char * argv0) {
|
char * findProgramPath(char * argv0) {
|
||||||
@ -29,9 +25,8 @@ char * findProgramPath(char * argv0) {
|
|||||||
|
|
||||||
if (!path) return NULL;
|
if (!path) return NULL;
|
||||||
|
|
||||||
start = pathbuf = alloca(strlen(path) + 1);
|
start = pathbuf = g_strdup(path);
|
||||||
buf = malloc(strlen(path) + strlen(argv0) + 2);
|
buf = g_malloc(strlen(path) + strlen(argv0) + 2);
|
||||||
strcpy(pathbuf, path);
|
|
||||||
|
|
||||||
chptr = NULL;
|
chptr = NULL;
|
||||||
do {
|
do {
|
||||||
@ -40,8 +35,10 @@ char * findProgramPath(char * argv0) {
|
|||||||
sprintf(buf, "%s/%s", start, argv0);
|
sprintf(buf, "%s/%s", start, argv0);
|
||||||
|
|
||||||
#ifndef WIN32
|
#ifndef WIN32
|
||||||
if (!access(buf, X_OK))
|
if (!access(buf, X_OK)) {
|
||||||
|
g_free(pathbuf);
|
||||||
return buf;
|
return buf;
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (chptr)
|
if (chptr)
|
||||||
@ -50,6 +47,7 @@ char * findProgramPath(char * argv0) {
|
|||||||
start = NULL;
|
start = NULL;
|
||||||
} while (start && *start);
|
} while (start && *start);
|
||||||
|
|
||||||
|
g_free(pathbuf);
|
||||||
free(buf);
|
free(buf);
|
||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
|
@ -4,10 +4,6 @@
|
|||||||
|
|
||||||
#include "common.h"
|
#include "common.h"
|
||||||
|
|
||||||
#if HAVE_ALLOCA_H
|
|
||||||
# include <alloca.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include "popt.h"
|
#include "popt.h"
|
||||||
#include "poptint.h"
|
#include "poptint.h"
|
||||||
|
|
||||||
@ -77,16 +73,17 @@ int poptReadConfigFile(poptContext con, char * fn) {
|
|||||||
fileLength = lseek(fd, 0, SEEK_END);
|
fileLength = lseek(fd, 0, SEEK_END);
|
||||||
lseek(fd, 0, 0);
|
lseek(fd, 0, 0);
|
||||||
|
|
||||||
file = alloca(fileLength + 1);
|
file = malloc(fileLength + 1);
|
||||||
if (read(fd, file, fileLength) != fileLength) {
|
if (read(fd, file, fileLength) != fileLength) {
|
||||||
rc = errno;
|
rc = errno;
|
||||||
close(fd);
|
close(fd);
|
||||||
errno = rc;
|
errno = rc;
|
||||||
|
free(file);
|
||||||
return POPT_ERROR_ERRNO;
|
return POPT_ERROR_ERRNO;
|
||||||
}
|
}
|
||||||
close(fd);
|
close(fd);
|
||||||
|
|
||||||
dst = buf = alloca(fileLength + 1);
|
dst = buf = malloc(fileLength + 1);
|
||||||
|
|
||||||
chptr = file;
|
chptr = file;
|
||||||
end = (file + fileLength);
|
end = (file + fileLength);
|
||||||
@ -116,6 +113,8 @@ int poptReadConfigFile(poptContext con, char * fn) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
free(buf);
|
||||||
|
free(file);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -132,10 +131,11 @@ int poptReadDefaultConfig(poptContext con, int useEnv) {
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
if ((home = getenv("HOME"))) {
|
if ((home = getenv("HOME"))) {
|
||||||
fn = alloca(strlen(home) + 20);
|
fn = malloc(strlen(home) + 20);
|
||||||
strcpy(fn, home);
|
strcpy(fn, home);
|
||||||
strcat(fn, "/.popt");
|
strcat(fn, "/.popt");
|
||||||
rc = poptReadConfigFile(con, fn);
|
rc = poptReadConfigFile(con, fn);
|
||||||
|
free(fn);
|
||||||
if (rc) return rc;
|
if (rc) return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -6,10 +6,6 @@
|
|||||||
|
|
||||||
#include "common.h"
|
#include "common.h"
|
||||||
|
|
||||||
#ifdef HAVE_ALLOCA_H
|
|
||||||
#include <alloca.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include "popt.h"
|
#include "popt.h"
|
||||||
#include "poptint.h"
|
#include "poptint.h"
|
||||||
|
|
||||||
@ -66,7 +62,7 @@ static void singleOptionHelp(FILE * f, int maxLeftCol,
|
|||||||
int helpLength;
|
int helpLength;
|
||||||
const char * ch;
|
const char * ch;
|
||||||
char format[10];
|
char format[10];
|
||||||
char * left = alloca(maxLeftCol + 1);
|
char * left = malloc(maxLeftCol + 1);
|
||||||
const char * argDescrip = getArgDescrip(opt, translation_domain);
|
const char * argDescrip = getArgDescrip(opt, translation_domain);
|
||||||
|
|
||||||
*left = '\0';
|
*left = '\0';
|
||||||
@ -76,7 +72,10 @@ static void singleOptionHelp(FILE * f, int maxLeftCol,
|
|||||||
sprintf(left, "-%c", opt->shortName);
|
sprintf(left, "-%c", opt->shortName);
|
||||||
else if (opt->longName)
|
else if (opt->longName)
|
||||||
sprintf(left, "--%s", opt->longName);
|
sprintf(left, "--%s", opt->longName);
|
||||||
if (!*left) return ;
|
if (!*left) {
|
||||||
|
free(left);
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (argDescrip) {
|
if (argDescrip) {
|
||||||
strcat(left, "=");
|
strcat(left, "=");
|
||||||
strcat(left, argDescrip);
|
strcat(left, argDescrip);
|
||||||
@ -86,9 +85,12 @@ static void singleOptionHelp(FILE * f, int maxLeftCol,
|
|||||||
fprintf(f," %-*s ", maxLeftCol, left);
|
fprintf(f," %-*s ", maxLeftCol, left);
|
||||||
else {
|
else {
|
||||||
fprintf(f," %s\n", left);
|
fprintf(f," %s\n", left);
|
||||||
|
free(left);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
free(left);
|
||||||
|
|
||||||
helpLength = strlen(help);
|
helpLength = strlen(help);
|
||||||
while (helpLength > lineLength) {
|
while (helpLength > lineLength) {
|
||||||
ch = help + lineLength - 1;
|
ch = help + lineLength - 1;
|
||||||
|
@ -10,10 +10,6 @@
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
#ifdef HAVE_ALLOCA_H
|
|
||||||
#include <alloca.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include "popt.h"
|
#include "popt.h"
|
||||||
|
|
||||||
static const int poptArgvArrayGrowDelta = 5;
|
static const int poptArgvArrayGrowDelta = 5;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user