commit - a2c2caaafe37e119078bc88f6ebee6d338cbff46
commit + 4e206880423db866dd1db0622a9b4d5b0881fee1
blob - 99c42752095fc8bc7380e1cb3c65d31e9e19f5b5
blob + 16dcd1e876e70956519ce63396e979d7dd47a304
--- src/libdraw/creadimage.c
+++ src/libdraw/creadimage.c
return nil;
}
- if(dolock)
- lockdisplay(d);
- i = allocimage(d, r, chan, 0, 0);
- if(dolock)
- unlockdisplay(d);
- if(i == nil)
- return nil;
- ncblock = _compblocksize(r, i->depth);
+ if(d){
+ if(dolock)
+ lockdisplay(d);
+ i = allocimage(d, r, chan, 0, 0);
+ if(dolock)
+ unlockdisplay(d);
+ if(i == nil)
+ return nil;
+ }else{
+ i = mallocz(sizeof(Image), 1);
+ if(i == nil)
+ return nil;
+ }
+ ncblock = _compblocksize(r, chantodepth(chan));
buf = malloc(ncblock);
if(buf == nil)
goto Errout;
}
if(readn(fd, buf, nb)!=nb)
goto Errout;
- if(dolock)
- lockdisplay(d);
- a = bufimage(i->display, 21+nb);
- if(a == nil)
- goto Erroutlock;
- a[0] = 'Y';
- BPLONG(a+1, i->id);
- BPLONG(a+5, r.min.x);
- BPLONG(a+9, miny);
- BPLONG(a+13, r.max.x);
- BPLONG(a+17, maxy);
- if(!new) /* old image: flip the data bits */
- _twiddlecompressed(buf, nb);
- memmove(a+21, buf, nb);
- if(dolock)
- unlockdisplay(d);
+ if(d){
+ if(dolock)
+ lockdisplay(d);
+ a = bufimage(i->display, 21+nb);
+ if(a == nil)
+ goto Erroutlock;
+ a[0] = 'Y';
+ BPLONG(a+1, i->id);
+ BPLONG(a+5, r.min.x);
+ BPLONG(a+9, miny);
+ BPLONG(a+13, r.max.x);
+ BPLONG(a+17, maxy);
+ if(!new) /* old image: flip the data bits */
+ _twiddlecompressed(buf, nb);
+ memmove(a+21, buf, nb);
+ if(dolock)
+ unlockdisplay(d);
+ }
miny = maxy;
}
free(buf);
blob - 9feffa423a948f713ca3036e62a5ce096162ad7b
blob + d7a9354554606fce440f96d641c7f1f2ecc26909
--- src/libdraw/font.c
+++ src/libdraw/font.c
if(f->display){
if(f->display->screenimage)
depth = f->display->screenimage->depth;
- }
+ }else
+ depth = 8;
name = subfontname(cf->name, f->name, depth);
if(name == nil)
return nil;
}
subf->cf = cf;
- if(subf->f->ascent > f->ascent){
+ if(subf->f->ascent > f->ascent && f->display){
/* should print something? this is a mistake in the font file */
/* must prevent c->top from going negative when loading cache */
Image *b;
c->width = fi->width;
c->x = h*f->width;
c->left = fi->left;
+ if(f->display == nil)
+ return 1;
flushimage(f->display, 0); /* flush any pending errors */
b = bufimage(f->display, 37);
if(b == 0)
Display *d;
ret = 0;
- d = f->display;
if(depth <= 0)
depth = 1;
+ d = f->display;
+ if(d == nil)
+ goto Nodisplay;
+
new = allocimage(d, Rect(0, 0, ncache*wid, f->height), CHAN1(CGrey, depth), 0, 0);
if(new == nil){
fprint(2, "font cache resize failed: %r\n");
}
freeimage(f->cacheimage);
f->cacheimage = new;
+ Nodisplay:
f->width = wid;
f->maxdepth = depth;
ret = 1;
blob - b7a8e44a63457ac9426e37e022831683a1b5d76a
blob + 2cbec8126474c33a6b17d546d8caf5ef2c3d1a0d
--- src/libdraw/getsubfont.c
+++ src/libdraw/getsubfont.c
* _getsubfont is called only from string.c and stringwidth.c,
* which are known to be safe to have this done.
*/
- if(d->locking == 0)
+ if(d && d->locking == 0)
unlockdisplay(d);
- f = readsubfont(d, name, fd, d->locking==0);
- if(d->locking == 0)
+ f = readsubfont(d, name, fd, d && d->locking==0);
+ if(d && d->locking == 0)
lockdisplay(d);
if(f == 0)
fprint(2, "getsubfont: can't read %s: %r\n", name);
blob - 1d2717b0d105f731b00e21310c09f626ce31c2bf
blob + 8135c45d80ac219180b285aece1d57643ddf2f38
--- src/libdraw/readimage.c
+++ src/libdraw/readimage.c
return creadimage(d, fd, dolock);
if(readn(fd, hdr+11, 5*12-11) != 5*12-11)
return nil;
- chunk = d->bufsize - 32; /* a little room for header */
+ if(d)
+ chunk = d->bufsize - 32; /* a little room for header */
+ else
+ chunk = 8192;
/*
* distinguish new channel descriptor from old ldepth.
maxy = r.max.y;
l = bytesperline(r, chantodepth(chan));
- if(dolock)
- lockdisplay(d);
- i = allocimage(d, r, chan, 0, -1);
- if(dolock)
- unlockdisplay(d);
- if(i == nil)
- return nil;
+ if(d){
+ if(dolock)
+ lockdisplay(d);
+ i = allocimage(d, r, chan, 0, -1);
+ if(dolock)
+ unlockdisplay(d);
+ if(i == nil)
+ return nil;
+ }else{
+ i = mallocz(sizeof(Image), 1);
+ if(i == nil)
+ return nil;
+ }
+
tmp = malloc(chunk);
if(tmp == nil)
goto Err;
for(j=0; j<chunk; j++)
tmp[j] ^= 0xFF;
- if(dolock)
- lockdisplay(d);
- if(loadimage(i, Rect(r.min.x, miny, r.max.x, miny+dy), tmp, chunk) <= 0)
- goto Err1;
- if(dolock)
- unlockdisplay(d);
+ if(d){
+ if(dolock)
+ lockdisplay(d);
+ if(loadimage(i, Rect(r.min.x, miny, r.max.x, miny+dy), tmp, chunk) <= 0)
+ goto Err1;
+ if(dolock)
+ unlockdisplay(d);
+ }
miny += dy;
}
free(tmp);
blob - 0e587b4819410862bc365abf4d32e90de9ef3494
blob + 05962640661e86b07e626db68eb694f6011ff3e0
--- src/libdraw/readsubfont.c
+++ src/libdraw/readsubfont.c
n = atoi(hdr);
p = malloc(6*(n+1));
if(p == nil)
- return nil;
+ goto Err;
if(read(fd, p, 6*(n+1)) != 6*(n+1)){
werrstr("rdsubfonfile: fontchar read error: %r");
Err:
+ if(ai == nil)
+ freeimage(i);
free(p);
return nil;
}
blob - f0d1372119f159b6d89c1d84841f8b246423a400
blob + 8d8c6d081a1be0219ccf6c1136b574b1fa869259
--- src/libdraw/stringwidth.c
+++ src/libdraw/stringwidth.c
}else
rptr = &r;
twid = 0;
- while(len && (*s || *r)){
+ while(len>0 && (*s || *r)){
max = Max;
if(len < max)
max = len;
blob - eb0bdba89c446355cbeed7005548d11c13a62405
blob + 2a7f489b420611ba2ad9106e23d59d7e51cdfe66
--- src/libdraw/subfontcache.c
+++ src/libdraw/subfontcache.c
Subfont*
lookupsubfont(Display *d, char *name)
{
- if(strcmp(name, "*default*") == 0)
+ if(d && strcmp(name, "*default*") == 0)
return d->defaultsubfont;
- if(lastname && strcmp(name, lastname)==0 && d==lastsubfont->bits->display){
+ if(lastname && strcmp(name, lastname)==0)
+ if(d==lastsubfont->bits->display){
lastsubfont->ref++;
return lastsubfont;
}