]> git.draconx.ca Git - liblbx.git/blobdiff - src/image.c
Trivial manual fixes.
[liblbx.git] / src / image.c
index 853852000492e3413cf8e17f851ee6458c0be9e5..ed80565439f65329875c831f200efd2645ec2213 100644 (file)
@@ -62,10 +62,10 @@ struct lbx_image_priv {
        unsigned currentx, currenty, currentn;
        int read_state;
 
-       unsigned long offsets[];
+       unsigned long offsets[FLEXIBLE_ARRAY_MEMBER];
 };
 
-static struct lbx_image_priv *lbx_img_init(unsigned char hdr[static HDR_LEN])
+static struct lbx_image_priv *lbx_img_init(unsigned char *hdr)
 {
        unsigned short nframes = unpack_16_le(hdr+6);
        struct lbx_image_priv *img;
@@ -93,6 +93,12 @@ static struct lbx_image_priv *lbx_img_init(unsigned char hdr[static HDR_LEN])
        if (img->flags & FLAG_LOOPING)
                img->pub.leadin = 0;
 
+       if (img->pub.leadin >= img->pub.frames) {
+               lbx_error_raise(LBX_EFORMAT);
+               free(img);
+               return NULL;
+       }
+
        return img;
 }
 
@@ -124,7 +130,6 @@ struct lbx_image *lbx_img_open(void *f, const struct lbx_file_ops *fops,
         */
        _lbx_assert(img->wtf  == 0); /* version? */
        _lbx_assert(img->wtf2 == 0); /* very likely is simply reserved. */
-       _lbx_assert(img->pub.frames > img->pub.leadin);
        _lbx_assert(!(img->flags & ~FLAG_ALL));
 
        /* Read all offsets.  Should be merged with identical code in lbx.c */
@@ -308,11 +313,14 @@ long lbx_img_read_row_data(struct lbx_image *pub, void *buf)
                return -1;
        }
 
-       if (!(img->flags & FLAG_RAW)) {
-               /* Skip padding byte, if any */
-               if (img->currentn % 2) {
-                       if (img->fops->seek(img->f, 1, SEEK_CUR))
-                               return -1;
+       if (!(img->flags & FLAG_RAW) && img->currentn % 2) {
+               unsigned char c;
+
+               /* Skip padding byte */
+               if (img->fops->read(&c, 1, img->f) != 1) {
+                       if (img->fops->eof(img->f))
+                               lbx_error_raise(LBX_EEOF);
+                       return -1;
                }
        }
 
@@ -400,22 +408,6 @@ readerr:
        return -1;
 }
 
-void lbx_img_getinfo(struct lbx_image *pub, struct lbx_imginfo *info)
-{
-       struct lbx_image_priv *img = (struct lbx_image_priv *)pub;
-
-       *info = (struct lbx_imginfo) { 0 };
-
-       /* There seems to be two ways of specifying that an image loops. */
-       if (img->flags & FLAG_LOOPING) {
-               info->loopstart = 0;
-               info->looping   = 1;
-       } else if (img->pub.leadin != pub->frames - 1) {
-               info->loopstart = img->pub.leadin;
-               info->looping   = 1;
-       }
-}
-
 int lbx_img_close(struct lbx_image *pub)
 {
        struct lbx_image_priv *img = (struct lbx_image_priv *)pub;