writejpg: the call to Bflush() is unnecessary; free data before exiting in case of malloc error
writeppm: do not print a space after the last pixel
This commit is contained in:
parent
b0cd0020df
commit
24a5720bec
2 changed files with 6 additions and 5 deletions
|
@ -823,7 +823,6 @@ static void
|
|||
writetrailer(Biobuf *fd)
|
||||
{
|
||||
Bputs(fd, 0xffd9);
|
||||
Bflush(fd);
|
||||
}
|
||||
|
||||
static char *
|
||||
|
@ -857,8 +856,10 @@ writedata(Biobuf *fd, Image *i, Memimage *m, int gflag, int sflag)
|
|||
else
|
||||
ndata = unloadimage(i, r, data, ndata);
|
||||
if(ndata < 0) {
|
||||
if((err = malloc(ERRMAX)) == nil)
|
||||
if((err = malloc(ERRMAX)) == nil) {
|
||||
free(data);
|
||||
return "WriteJPG: malloc failed";
|
||||
}
|
||||
snprint(err, ERRMAX, "WriteJPG: %r");
|
||||
} else
|
||||
err = encode(fd, r, data, chan, ndata, gflag, sflag);
|
||||
|
|
|
@ -106,7 +106,7 @@ writedata(Biobuf *fd, Image *image, Memimage *memimage, int rflag)
|
|||
if(col >= MAXLINE-(2+1)){
|
||||
Bprint(fd, "\n");
|
||||
col = 0;
|
||||
}else
|
||||
}else if(y < r.max.y-1 || x < r.max.x-1)
|
||||
col += Bprint(fd, " ");
|
||||
}
|
||||
if(rflag)
|
||||
|
@ -123,7 +123,7 @@ writedata(Biobuf *fd, Image *image, Memimage *memimage, int rflag)
|
|||
if(col >= MAXLINE-(4+1)){
|
||||
Bprint(fd, "\n");
|
||||
col = 0;
|
||||
}else
|
||||
}else if(i < ndata-1)
|
||||
col += Bprint(fd, " ");
|
||||
}
|
||||
break;
|
||||
|
@ -139,7 +139,7 @@ writedata(Biobuf *fd, Image *image, Memimage *memimage, int rflag)
|
|||
if(col >= MAXLINE-(4+4+4+1)){
|
||||
Bprint(fd, "\n");
|
||||
col = 0;
|
||||
}else
|
||||
}else if(i < ndata-3)
|
||||
col += Bprint(fd, " ");
|
||||
}
|
||||
break;
|
||||
|
|
Loading…
Reference in a new issue