Changeset 4232
- Timestamp:
- Jan 6, 2010, 3:00:41 AM (13 years ago)
- Location:
- zzuf/trunk/src
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
zzuf/trunk/src/common/fuzz.c
r4112 r4232 95 95 96 96 #if defined LIBZZUF 97 debug2("fuzz(%i, @%lli, %lli)", fd, (long long int)pos, (long long int)len); 97 debug2("... fuzz(%i, @%lli, %lli)", fd, (long long int)pos, 98 (long long int)len); 98 99 #endif 99 100 -
zzuf/trunk/src/libzzuf/lib-stream.c
r4230 r4232 220 220 static inline void debug_stream(char const *prefix, FILE *stream) 221 221 { 222 debug2("%p stream([%i], %p, %i)", prefix, fileno(stream), 223 get_stream_ptr(stream), get_stream_cnt(stream)); 222 debug2("... %s stream([%i], %p, %i + %i)", prefix, fileno(stream), 223 get_stream_ptr(stream), get_stream_off(stream), 224 get_stream_cnt(stream)); 224 225 } 225 226 … … 246 247 _zz_register(fd); \ 247 248 _zz_fuzz(fd, get_stream_ptr(ret), get_stream_cnt(ret)); \ 249 debug_stream("after", ret); \ 248 250 debug("%s(\"%s\", \"%s\") = [%i]", __func__, path, mode, fd); \ 249 debug_stream("new", ret); \250 251 } \ 251 252 } while(0) … … 335 336 if(!_zz_ready || !_zz_iswatched(fd) || !_zz_isactive(fd)) \ 336 337 return ORIG(myfseek)(stream, offset, whence); \ 337 debug_stream(" old", stream); \338 debug_stream("before", stream); \ 338 339 /* FIXME: ftell() will return -1 on a pipe such as stdin */ \ 339 340 oldpos = MYFTELL(stream); \ … … 344 345 _zz_unlock(fd); \ 345 346 newpos = MYFTELL(stream); \ 346 if (newpos > oldpos + oldcnt || newpos < oldpos - oldoff) \347 if (newpos >= oldpos + oldcnt || newpos < oldpos - oldoff) \ 347 348 { \ 348 349 _zz_setpos(fd, newpos - get_stream_off(stream)); \ … … 351 352 } \ 352 353 _zz_setpos(fd, newpos); \ 354 debug_stream("after", stream); \ 353 355 debug("%s([%i], %lli, %s) = %i", __func__, \ 354 356 fd, (long long int)offset, get_seek_mode_name(whence), ret); \ 355 debug_stream("new", stream); \356 357 } while(0) 357 358 … … 366 367 if(!_zz_ready || !_zz_iswatched(fd) || !_zz_isactive(fd)) \ 367 368 return ORIG(myfsetpos)(stream, pos); \ 368 debug_stream(" old", stream); \369 debug_stream("before", stream); \ 369 370 /* FIXME: ftell() will return -1 on a pipe such as stdin */ \ 370 371 oldpos = MYFTELL(stream); \ … … 375 376 _zz_unlock(fd); \ 376 377 newpos = MYFTELL(stream); \ 377 if (newpos > oldpos + oldcnt || newpos < oldpos - oldoff) \378 if (newpos >= oldpos + oldcnt || newpos < oldpos - oldoff) \ 378 379 { \ 379 380 _zz_setpos(fd, newpos - get_stream_off(stream)); \ … … 382 383 } \ 383 384 _zz_setpos(fd, (int64_t)FPOS_CAST(*pos)); \ 385 debug_stream("after", stream); \ 384 386 debug("%s([%i], %lli) = %i", __func__, \ 385 387 fd, (long long int)FPOS_CAST(*pos), ret); \ 386 debug_stream("new", stream); \387 388 } \ 388 389 while(0) … … 398 399 if(!_zz_ready || !_zz_iswatched(fd) || !_zz_isactive(fd)) \ 399 400 return ORIG(rewind)(stream); \ 400 debug_stream(" old", stream); \401 debug_stream("before", stream); \ 401 402 /* FIXME: ftell() will return -1 on a pipe such as stdin */ \ 402 403 oldpos = MYFTELL(stream); \ … … 407 408 _zz_unlock(fd); \ 408 409 newpos = MYFTELL(stream); \ 409 if (newpos > oldpos + oldcnt || newpos < oldpos - oldoff) \410 if (newpos >= oldpos + oldcnt || newpos < oldpos - oldoff) \ 410 411 { \ 411 412 _zz_setpos(fd, newpos - get_stream_off(stream)); \ … … 414 415 } \ 415 416 _zz_setpos(fd, newpos); \ 417 debug_stream("after", stream); \ 416 418 debug("%s([%i])", __func__, fd); \ 417 debug_stream("new", stream); \418 419 } while(0) 419 420 … … 483 484 if(!_zz_ready || !_zz_iswatched(fd) || !_zz_isactive(fd)) \ 484 485 return ORIG(myfread)(ptr, size, nmemb, stream); \ 485 debug_stream(" old", stream); \486 debug_stream("before", stream); \ 486 487 /* FIXME: ftell() will return -1 on a pipe such as stdin */ \ 487 488 oldpos = MYFTELL(stream); \ … … 492 493 _zz_unlock(fd); \ 493 494 newpos = MYFTELL(stream); \ 494 if (newpos > oldpos + oldcnt) \495 if (newpos >= oldpos + oldcnt) \ 495 496 { \ 496 497 /* Fuzz returned data that wasn't in the old internal buffer */ \ … … 503 504 } \ 504 505 _zz_setpos(fd, newpos); \ 505 if (newpos > oldpos + 4) \ 506 debug_stream("after", stream); \ 507 if (newpos >= oldpos + 4) \ 506 508 debug("%s(%p, %li, %li, [%i]) = %li \"%c%c%c%c...", __func__, \ 507 509 ptr, (long int)size, (long int)nmemb, fd, \ … … 514 516 debug("%s(%p, %li, %li, [%i]) = %li", __func__, ptr, \ 515 517 (long int)size, (long int)nmemb, fd, (long int)ret); \ 516 debug_stream("new", stream); \517 518 } while(0) 518 519 … … 548 549 if(!_zz_ready || !_zz_iswatched(fd) || !_zz_isactive(fd)) \ 549 550 return ORIG(myfgetc)(arg); \ 550 debug_stream(" old", s); \551 debug_stream("before", s); \ 551 552 oldpos = MYFTELL(s); \ 552 553 oldoff = get_stream_off(s); \ … … 564 565 ret = ch; \ 565 566 } \ 566 if (newpos > oldpos + oldcnt) \567 if (newpos >= oldpos + oldcnt) \ 567 568 { \ 568 569 /* Fuzz the internal stream buffer */ \ … … 572 573 } \ 573 574 _zz_setpos(fd, newpos); \ 575 debug_stream("after", s); \ 574 576 if(ret == EOF) \ 575 577 debug("%s([%i]) = EOF", __func__, fd); \ 576 578 else \ 577 579 debug("%s([%i]) = '%c'", __func__, fd, ret); \ 578 debug_stream("new", s); \579 580 } while(0) 580 581 … … 643 644 if(!_zz_ready || !_zz_iswatched(fd) || !_zz_isactive(fd)) \ 644 645 return ORIG(myfgets)(s, size, stream); \ 645 debug_stream(" old", stream); \646 debug_stream("before", stream); \ 646 647 oldpos = MYFTELL(stream); \ 647 648 oldoff = get_stream_off(stream); \ … … 670 671 chr = ch; \ 671 672 } \ 672 if (newpos > oldpos + oldcnt) \673 if (newpos >= oldpos + oldcnt) \ 673 674 { \ 674 675 /* Fuzz the internal stream buffer, if necessary */ \ … … 696 697 } \ 697 698 _zz_setpos(fd, newpos); \ 699 debug_stream("after", stream); \ 698 700 debug("%s(%p, %i, [%i]) = %p", __func__, s, size, fd, ret); \ 699 debug_stream("new", stream); \700 701 } while(0) 701 702 … … 725 726 return ORIG(ungetc)(c, stream); 726 727 727 debug_stream(" old", stream);728 debug_stream("before", stream); 728 729 oldpos = MYFTELL(stream); 729 730 _zz_lock(fd); … … 732 733 _zz_setpos(fd, oldpos - 1); 733 734 735 debug_stream("after", stream); 734 736 if(ret == EOF) 735 737 debug("%s(0x%02x, [%i]) = EOF", __func__, c, fd); 736 738 else 737 739 debug("%s(0x%02x, [%i]) = '%c'", __func__, c, fd, ret); 738 debug_stream("new", stream);739 740 return ret; 740 741 } … … 753 754 return ORIG(fclose)(fp); 754 755 755 debug_stream(" old", fp);756 debug_stream("before", fp); 756 757 _zz_lock(fd); 757 758 ret = ORIG(fclose)(fp); … … 780 781 if(!_zz_ready || !_zz_iswatched(fd) || !_zz_isactive(fd)) \ 781 782 return ORIG(getdelim)(lineptr, n, delim, stream); \ 782 debug_stream(" old", stream); \783 debug_stream("before", stream); \ 783 784 oldpos = MYFTELL(stream); \ 784 785 oldoff = get_stream_off(stream); \ … … 812 813 chr = ch; \ 813 814 } \ 814 if (newpos > oldpos + oldcnt) \815 if (newpos >= oldpos + oldcnt) \ 815 816 { \ 816 817 /* Fuzz the internal stream buffer, if necessary */ \ … … 839 840 } \ 840 841 _zz_setpos(fd, newpos); \ 842 debug_stream("after", stream); \ 841 843 if(need_delim) \ 842 844 debug("%s(%p, %p, '%c', [%i]) = %li", __func__, \ … … 845 847 debug("%s(%p, %p, [%i]) = %li", __func__, \ 846 848 lineptr, n, fd, (long int)ret); \ 847 debug_stream("new", stream); \848 849 break; \ 849 850 } while(0) … … 889 890 return ORIG(fgetln)(stream, len); 890 891 891 debug_stream(" old", stream);892 debug_stream("before", stream); 892 893 oldpos = MYFTELL(stream); 893 894 oldoff = get_stream_off(stream); … … 914 915 chr = ch; 915 916 } 916 if (newpos > oldpos + oldcnt)917 if (newpos >= oldpos + oldcnt) 917 918 { 918 919 /* Fuzz the internal stream buffer, if necessary */ … … 940 941 ret = fuzz->tmp; 941 942 943 debug_stream("after", stream); 942 944 debug("%s([%i], &%li) = %p", __func__, fd, (long int)*len, ret); 943 debug_stream("new", stream);944 945 return ret; 945 946 } … … 966 967 if(!_zz_ready || !_zz_iswatched(fd) || !_zz_isactive(fd)) \ 967 968 return ORIG(myrefill)(fp); \ 968 debug_stream(" old", fp); \969 debug_stream("before", fp); \ 969 970 pos = _zz_getpos(fd); \ 970 971 _zz_lock(fd); \ … … 1001 1002 } \ 1002 1003 _zz_setpos(fd, pos); /* FIXME: do we always need to do this? */ \ 1004 debug_stream("after", fp); \ 1003 1005 if (REFILL_RETURNS_INT) \ 1004 1006 debug("%s([%i]) = %i", __func__, fd, ret); \ … … 1007 1009 else \ 1008 1010 debug("%s([%i]) = '%c'", __func__, fd, ret); \ 1009 debug_stream("new", fp); \1010 1011 } \ 1011 1012 while(0)
Note: See TracChangeset
for help on using the changeset viewer.