Skip to content

Commit

Permalink
libc/vsmprint.c: don't use pointer after realloc
Browse files Browse the repository at this point in the history
  • Loading branch information
adriangrigore committed Jul 9, 2024
1 parent a5f00a0 commit e3fe16a
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions libc/vsmprint.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,24 @@ static int
fmtStrFlush(Fmt *f)
{
char *s;
int n;
int n, d;

if(f->start == nil)
return 0;
n = (uintptr)f->farg;
n *= 2;
s = (char*)f->start;
f->start = realloc(s, n);
if(f->start == nil){
d = (char*)f->to - (char*)f->start;
s = realloc(f->start, n);
if(s == nil){
f->farg = nil;
f->to = nil;
f->stop = nil;
free(s);
free(f->start);
return 0;
}
f->start = s;
f->farg = (void*)(uintptr)n;
f->to = (char*)f->start + ((char*)f->to - s);
f->to = (char*)f->start + d;
f->stop = (char*)f->start + n - 1;
return 1;
}
Expand Down

0 comments on commit e3fe16a

Please sign in to comment.