Replace all alloca()s with malloc()

This commit is contained in:
david parsons
2008-03-13 16:49:46 -07:00
parent da2bb58c4f
commit 41c153a48a
3 changed files with 30 additions and 18 deletions
+19 -14
View File
@@ -175,7 +175,7 @@ isopentag(Line *p)
{
int i=0, len;
char *key;
char **look;
char **look = 0;
if ( !p ) return 0;
@@ -192,11 +192,13 @@ isopentag(Line *p)
&& !isspace(T(p->text)[i]); ++i )
;
key = alloca(i);
memcpy(key, T(p->text)+1, i-1);
key[i-1] = 0;
if ( key = malloc(i) ) {
memcpy(key, T(p->text)+1, i-1);
key[i-1] = 0;
look=bsearch(&key, blocktags, SZTAGS, sizeof blocktags[0], (stfu)casort);
look=bsearch(&key,blocktags,SZTAGS,sizeof blocktags[0],(stfu)casort);
free(key);
}
return look ? (*look) : 0;
}
@@ -229,10 +231,7 @@ htmlblock(Paragraph *p, char *tag)
{
Line *t = p->text, *ret;
int closesize;
char *close = alloca(strlen(tag)+4);
sprintf(close, "</%s>", tag);
closesize = strlen(close);
char *close;
if ( selfclose(t, tag) ) {
ret = t->next;
@@ -240,12 +239,18 @@ htmlblock(Paragraph *p, char *tag)
return ret;
}
for ( ; t ; t = t->next) {
if ( strncasecmp(T(t->text), close, closesize) == 0 ) {
ret = t->next;
t->next = 0;
return ret;
if ( close = malloc(strlen(tag)+4) ) {
sprintf(close, "</%s>", tag);
closesize = strlen(close);
for ( ; t ; t = t->next) {
if ( strncasecmp(T(t->text), close, closesize) == 0 ) {
t = t->next;
break;
}
}
free(close);
}
return t;
}
+5 -2
View File
@@ -103,8 +103,11 @@ char **argv;
if ( argc > 1 ) {
char *p, *dot;
source = alloca(strlen(argv[1]) + 6);
dest = alloca(strlen(argv[1]) + 6);
source = malloc(strlen(argv[1]) + 6);
dest = malloc(strlen(argv[1]) + 6);
if ( !(source && dest) )
fail("out of memory allocating name buffers");
strcpy(source, argv[1]);
if (( p = strrchr(source, '/') ))
+6 -2
View File
@@ -134,7 +134,8 @@ open_template(char *template)
szcwd = root ? 1 + strlen(root) : 2;
cwd = alloca(szcwd);
if ( (cwd = malloc(szcwd)) == 0 )
return 0;
while ( !(ret = fopen(template, "r")) ) {
if ( getcwd(cwd, szcwd) == 0 ) {
@@ -151,6 +152,7 @@ open_template(char *template)
up: if ( chdir("..") == -1 )
break;
}
free(cwd);
popd(here);
return ret;
} /* open_template */
@@ -516,7 +518,9 @@ char **argv;
if ( argc > 0 ) {
int added_text=0;
source = alloca(strlen(argv[0]) + strlen(".text") + 1);
if ( (source = malloc(strlen(argv[0]) + strlen(".text") + 1)) == 0 )
fail("out of memory allocating name buffer");
strcpy(source,argv[0]);
if ( !freopen(source, "r", stdin) ) {