]> git.lizzy.rs Git - plan9front.git/blobdiff - sys/src/libdraw/readsubfont.c
Improve the posix preprocessor.
[plan9front.git] / sys / src / libdraw / readsubfont.c
index 5314df82db64285d27e395fdd16715c12e35c4f9..df206791222deca094a15a2b771791f657251fde 100644 (file)
@@ -18,23 +18,22 @@ readsubfonti(Display*d, char *name, int fd, Image *ai, int dolock)
                if(i == nil)
                        return nil;
        }
-       if(read(fd, hdr, 3*12) != 3*12){
-               if(ai == nil)
-                       freeimage(i);
-               werrstr("rdsubfonfile: header read error: %r");
-               return nil;
+       p = nil;
+       if(readn(fd, hdr, 3*12) != 3*12){
+               werrstr("readsubfont: header read error: %r");
+               goto Err;
        }
        n = atoi(hdr);
+       if(n <= 0 || n > 0x7fff){
+               werrstr("readsubfont: bad fontchar count %d", n);
+               goto Err;
+       }
        p = malloc(6*(n+1));
        if(p == 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;
+       if(readn(fd, p, 6*(n+1)) != 6*(n+1)){
+               werrstr("readsubfont: fontchar read error: %r");
+               goto Err;
        }
        fc = malloc(sizeof(Fontchar)*(n+1));
        if(fc == nil)
@@ -51,6 +50,11 @@ readsubfonti(Display*d, char *name, int fd, Image *ai, int dolock)
        }
        free(p);
        return f;
+Err:
+       if(ai == nil)
+               freeimage(i);
+       free(p);
+       return nil;
 }
 
 Subfont*