Fork us on GitHub Follow us on Facebook Follow us on Twitter

Changeset bad765a in mainline


Ignore:
Timestamp:
2021-11-04T16:29:57Z (4 weeks ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
master
Children:
e3e64f6
Parents:
f05f413
Message:

Fix reading and writing chunk padding

You cannot use riff_read() to read the chunk padding, because it's not
part of the chunk data proper. This fixes libgfxfont's unit test, which
could not read back the TPF it wrote.

Also, it seems prudent to actually write the padding, not just seek
over it. (Might not be a problem but, just in case…)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/riff/src/chunk.c

    rf05f413 rbad765a  
    146146        long pos;
    147147        long cksize;
     148        uint8_t pad;
     149        size_t nw;
    148150        errno_t rc;
    149151
     
    153155
    154156        cksize = pos - wchunk->ckstart;
    155         if (pos % 2 != 0)
     157        if (pos % 2 != 0) {
    156158                ++pos;
     159                pad = 0;
     160                nw = fwrite(&pad, 1, sizeof(pad), rw->f);
     161                if (nw != sizeof(pad))
     162                        return EIO;
     163        }
    157164
    158165        if (fseek(rw->f, wchunk->ckstart - 4, SEEK_SET) < 0)
     
    476483        uint8_t byte;
    477484        size_t nread;
    478         errno_t rc;
    479485
    480486        ckend = riff_rchunk_get_ndpos(rchunk);
     
    483489                /* (Buffered) reading is faster than seeking */
    484490                while (rchunk->riffr->pos < ckend) {
    485                         rc = riff_read(rchunk, &byte, sizeof(byte), &nread);
    486                         if (rc != EOK)
    487                                 return rc;
    488 
     491                        nread = fread(&byte, 1, sizeof(byte), rchunk->riffr->f);
    489492                        if (nread != sizeof(byte))
    490493                                return EIO;
     494
     495                        rchunk->riffr->pos += sizeof(byte);
    491496                }
    492497
     
    495500                if (fseek(rchunk->riffr->f, ckend, SEEK_SET) < 0)
    496501                        return EIO;
     502
    497503                rchunk->riffr->pos = ckend;
    498504        }
Note: See TracChangeset for help on using the changeset viewer.