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:
ppatience0 2013-07-19 01:07:15 -04:00
parent b0cd0020df
commit 24a5720bec
2 changed files with 6 additions and 5 deletions

View file

@ -823,7 +823,6 @@ static void
writetrailer(Biobuf *fd) writetrailer(Biobuf *fd)
{ {
Bputs(fd, 0xffd9); Bputs(fd, 0xffd9);
Bflush(fd);
} }
static char * static char *
@ -857,8 +856,10 @@ writedata(Biobuf *fd, Image *i, Memimage *m, int gflag, int sflag)
else else
ndata = unloadimage(i, r, data, ndata); ndata = unloadimage(i, r, data, ndata);
if(ndata < 0) { if(ndata < 0) {
if((err = malloc(ERRMAX)) == nil) if((err = malloc(ERRMAX)) == nil) {
free(data);
return "WriteJPG: malloc failed"; return "WriteJPG: malloc failed";
}
snprint(err, ERRMAX, "WriteJPG: %r"); snprint(err, ERRMAX, "WriteJPG: %r");
} else } else
err = encode(fd, r, data, chan, ndata, gflag, sflag); err = encode(fd, r, data, chan, ndata, gflag, sflag);

View file

@ -106,7 +106,7 @@ writedata(Biobuf *fd, Image *image, Memimage *memimage, int rflag)
if(col >= MAXLINE-(2+1)){ if(col >= MAXLINE-(2+1)){
Bprint(fd, "\n"); Bprint(fd, "\n");
col = 0; col = 0;
}else }else if(y < r.max.y-1 || x < r.max.x-1)
col += Bprint(fd, " "); col += Bprint(fd, " ");
} }
if(rflag) if(rflag)
@ -123,7 +123,7 @@ writedata(Biobuf *fd, Image *image, Memimage *memimage, int rflag)
if(col >= MAXLINE-(4+1)){ if(col >= MAXLINE-(4+1)){
Bprint(fd, "\n"); Bprint(fd, "\n");
col = 0; col = 0;
}else }else if(i < ndata-1)
col += Bprint(fd, " "); col += Bprint(fd, " ");
} }
break; break;
@ -139,7 +139,7 @@ writedata(Biobuf *fd, Image *image, Memimage *memimage, int rflag)
if(col >= MAXLINE-(4+4+4+1)){ if(col >= MAXLINE-(4+4+4+1)){
Bprint(fd, "\n"); Bprint(fd, "\n");
col = 0; col = 0;
}else }else if(i < ndata-3)
col += Bprint(fd, " "); col += Bprint(fd, " ");
} }
break; break;