Changeset 1719 for zzuf/trunk/src


Ignore:
Timestamp:
Jan 27, 2007, 4:13:34 PM (13 years ago)
Author:
Sam Hocevar
Message:
  • Better ungetc() implementation. Now we don't need to care about the fuzzing method.
Location:
zzuf/trunk/src
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • zzuf/trunk/src/fd.c

    r1700 r1719  
    257257    files[i].fuzz.tmp = NULL;
    258258#endif
     259    files[i].fuzz.uflag = 0;
    259260
    260261    if(autoinc)
  • zzuf/trunk/src/fuzz.c

    r1705 r1719  
    153153                    goto range_ok;
    154154
    155             continue; /* Not in a range */
     155            continue; /* Not in one of the ranges, skip byte */
    156156
    157157        range_ok:
     
    168168            aligned_buf[j] = byte;
    169169        }
     170    }
     171
     172    /* Handle ungetc() */
     173    if(fuzz->uflag)
     174    {
     175        fuzz->uflag = 0;
     176        if(fuzz->upos == pos)
     177            buf[0] = fuzz->uchar;
    170178    }
    171179}
  • zzuf/trunk/src/lib-stream.c

    r1712 r1719  
    379379int NEW(ungetc)(int c, FILE *stream)
    380380{
    381     unsigned char ch = c;
    382381    int ret, fd;
    383382
     
    387386        return ORIG(ungetc)(c, stream);
    388387
    389 #if defined HAVE___SREFILL /* Don't fuzz or seek if we have __srefill() */
    390 #else
    391     _zz_addpos(fd, -1);
    392     _zz_fuzz(fd, &ch, 1);
    393 #endif
    394     _zz_lock(fd);
    395     ret = ORIG(ungetc)((int)ch, stream);
    396     _zz_unlock(fd);
    397 
    398     if(ret >= 0)
    399         ret = c;
    400 #if defined HAVE___SREFILL /* Don't fuzz or seek if we have __srefill() */
    401 #else
    402     else
    403         _zz_addpos(fd, 1); /* revert what we did */
    404 #endif
     388    _zz_lock(fd);
     389    ret = ORIG(ungetc)(c, stream);
     390    _zz_unlock(fd);
     391
     392    if(ret != EOF)
     393    {
     394        struct fuzz *fuzz = _zz_getfuzz(fd);
     395        fuzz->uflag = 1;
     396        fuzz->upos = _zz_getpos(fd) - 1;
     397        fuzz->uchar = c;
     398#if defined HAVE___SREFILL /* Don't fuzz or seek if we have __srefill() */
     399#else
     400        _zz_addpos(fd, -1);
     401#endif
     402    }
    405403
    406404    debug("%s(0x%02x, [%i]) = '%c'", __func__, c, fd, ret);
  • zzuf/trunk/src/libzzuf.h

    r1718 r1719  
    3939    char *tmp;
    4040#endif
     41    int uflag; uint64_t upos; uint8_t uchar; /* ungetc stuff */
    4142    uint8_t data[CHUNKBYTES];
    4243};
Note: See TracChangeset for help on using the changeset viewer.