mothra: make emalloc zero memory, fix uninitialized nextline pointer crash
This commit is contained in:
parent
a5d30a3d04
commit
02acb1d4f0
|
@ -72,7 +72,7 @@ char *selgen(Panel *, int);
|
|||
char *nullgen(Panel *, int);
|
||||
Field *newfield(Form *form){
|
||||
Field *f;
|
||||
f=emallocz(sizeof(Field), 1);
|
||||
f=emalloc(sizeof(Field));
|
||||
if(form->efields==0)
|
||||
form->fields=f;
|
||||
else
|
||||
|
@ -99,7 +99,7 @@ void rdform(Hglob *g){
|
|||
htmlerror(g->name, g->lineno, "nested forms illegal\n");
|
||||
break;
|
||||
}
|
||||
g->form=emallocz(sizeof(Form), 1);
|
||||
g->form=emalloc(sizeof(Form));
|
||||
s=pl_getattr(g->attr, "action");
|
||||
g->form->action=strdup((s && s[0]) ? s : g->dst->url->fullname);
|
||||
s=pl_getattr(g->attr, "method");
|
||||
|
@ -223,7 +223,7 @@ void rdform(Hglob *g){
|
|||
if((f=g->form->efields)==0) goto BadTag;
|
||||
if(f->size<8)
|
||||
f->size++;
|
||||
o=emallocz(sizeof(Option), 1);
|
||||
o=emalloc(sizeof(Option));
|
||||
for(op=&f->options;*op;op=&(*op)->next);
|
||||
*op=o;
|
||||
o->next=0;
|
||||
|
|
|
@ -75,7 +75,7 @@ void getimage(Rtext *t, Www *w){
|
|||
goto Err;
|
||||
}
|
||||
close(fd);
|
||||
p = emallocz(sizeof(Pix), 1);
|
||||
p=emalloc(sizeof(Pix));
|
||||
nstrcpy(p->name, ap->image, sizeof(p->name));
|
||||
p->b=b;
|
||||
p->width=ap->width;
|
||||
|
|
|
@ -28,8 +28,9 @@ void pl_snarfentry(Panel *p, int cut){
|
|||
write(fd, ep->entry, n);
|
||||
ep->entp=ep->entry;
|
||||
}else{
|
||||
n = 1024;
|
||||
if((s=malloc(n+SLACK))==0){
|
||||
n=1024;
|
||||
s=malloc(n+SLACK);
|
||||
if(s==0){
|
||||
close(fd);
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -12,8 +12,7 @@
|
|||
#define LEAD 4 /* extra space between lines */
|
||||
Rtext *pl_rtnew(Rtext **t, int space, int indent, Image *b, Panel *p, Font *f, char *s, int hot, void *user){
|
||||
Rtext *new;
|
||||
new=malloc(sizeof(Rtext));
|
||||
if(new==0) return 0;
|
||||
new=pl_emalloc(sizeof(Rtext));
|
||||
new->hot=hot;
|
||||
new->user=user;
|
||||
new->space=space;
|
||||
|
@ -23,6 +22,7 @@ Rtext *pl_rtnew(Rtext **t, int space, int indent, Image *b, Panel *p, Font *f, c
|
|||
new->font=f;
|
||||
new->text=s;
|
||||
new->next=0;
|
||||
new->nextline=0;
|
||||
new->r=Rect(0,0,0,0);
|
||||
if(*t)
|
||||
(*t)->last->next=new;
|
||||
|
|
|
@ -370,8 +370,7 @@ void tw_relocate(Textwin *t, int first, int last, Point dst){
|
|||
int nbyte;
|
||||
if(first<t->top || last<first || t->bot<last) return;
|
||||
nbyte=(last-first+1)*sizeof(Point);
|
||||
srcloc=malloc(nbyte);
|
||||
if(srcloc==0) return;
|
||||
srcloc=pl_emalloc(nbyte);
|
||||
memmove(srcloc, &t->loc[first-t->top], nbyte);
|
||||
tw_setloc(t, first, last, dst);
|
||||
if(tw_before(t, dst, srcloc[0]))
|
||||
|
@ -445,19 +444,9 @@ void twreshape(Textwin *t, Rectangle r){
|
|||
}
|
||||
Textwin *twnew(Image *b, Font *f, Rune *text, int ntext){
|
||||
Textwin *t;
|
||||
t=malloc(sizeof(Textwin));
|
||||
if(t==0) return 0;
|
||||
t->text=malloc((ntext+SLACK)*sizeof(Rune));
|
||||
if(t->text==0){
|
||||
free(t);
|
||||
return 0;
|
||||
}
|
||||
t->loc=malloc(SLACK*sizeof(Point));
|
||||
if(t->loc==0){
|
||||
free(t->text);
|
||||
free(t);
|
||||
return 0;
|
||||
}
|
||||
t=pl_emalloc(sizeof(Textwin));
|
||||
t->text=pl_emalloc((ntext+SLACK)*sizeof(Rune));
|
||||
t->loc=pl_emalloc(SLACK*sizeof(Point));
|
||||
t->eloc=t->loc+SLACK;
|
||||
t->etext=t->text+ntext;
|
||||
t->eslack=t->etext+SLACK;
|
||||
|
|
|
@ -458,14 +458,7 @@ void *emalloc(int n){
|
|||
v=malloc(n);
|
||||
if(v==0)
|
||||
sysfatal("out of memory");
|
||||
setmalloctag(v, getcallerpc(&n));
|
||||
return v;
|
||||
}
|
||||
void *emallocz(int n, int z){
|
||||
void *v;
|
||||
v = emalloc(n);
|
||||
if(z)
|
||||
memset(v, 0, n);
|
||||
memset(v, 0, n);
|
||||
setmalloctag(v, getcallerpc(&n));
|
||||
return v;
|
||||
}
|
||||
|
@ -982,7 +975,7 @@ mothon(Www *w, int on)
|
|||
x = t->next;
|
||||
if(on){
|
||||
t->next = nil;
|
||||
ap=mallocz(sizeof(Action), 1);
|
||||
ap=emalloc(sizeof(Action));
|
||||
ap->link = strdup(a->link);
|
||||
plrtstr(&t->next, 0, 0, t->font, strdup("->"), 1, ap);
|
||||
t->next->next = x;
|
||||
|
|
|
@ -89,7 +89,6 @@ void freepix(void *p);
|
|||
int pipeline(char *, int);
|
||||
void getfonts(void);
|
||||
void *emalloc(int);
|
||||
void *emallocz(int, int);
|
||||
void nstrcpy(char *to, char *from, int len);
|
||||
void freeform(void *p);
|
||||
int Ufmt(Fmt *f);
|
||||
|
|
|
@ -117,19 +117,17 @@ void pl_htmloutput(Hglob *g, int nsp, char *s, Field *field){
|
|||
if(g->state->image[0]==0 && g->state->link[0]==0 && g->state->name[0]==0 && field==0)
|
||||
ap=0;
|
||||
else{
|
||||
ap=mallocz(sizeof(Action), 1);
|
||||
if(ap!=0){
|
||||
if(g->state->image[0])
|
||||
ap->image = strdup(g->state->image);
|
||||
if(g->state->link[0])
|
||||
ap->link = strdup(g->state->link);
|
||||
if(g->state->name[0])
|
||||
ap->name = strdup(g->state->name);
|
||||
ap->ismap=g->state->ismap;
|
||||
ap->width=g->state->width;
|
||||
ap->height=g->state->height;
|
||||
ap->field=field;
|
||||
}
|
||||
ap=emalloc(sizeof(Action));
|
||||
if(g->state->image[0])
|
||||
ap->image = strdup(g->state->image);
|
||||
if(g->state->link[0])
|
||||
ap->link = strdup(g->state->link);
|
||||
if(g->state->name[0])
|
||||
ap->name = strdup(g->state->name);
|
||||
ap->ismap=g->state->ismap;
|
||||
ap->width=g->state->width;
|
||||
ap->height=g->state->height;
|
||||
ap->field=field;
|
||||
}
|
||||
if(space<0) space=0;
|
||||
if(indent<0) indent=0;
|
||||
|
|
Loading…
Reference in a new issue