~ubuntu-branches/ubuntu/vivid/tidy/vivid-updates

« back to all changes in this revision

Viewing changes to src/buffio.c

  • Committer: Bazaar Package Importer
  • Author(s): Jason Thomas
  • Date: 2005-10-20 10:26:07 UTC
  • mfrom: (0.2.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20051020102607-ezcx81ght15xsjuj
Tags: 20051018-1
* New upstream release
  (closes: #333444)
* debian/tidy.install: added debian/tidy.conf /etc/tidy/
  (closes: #308883)
* debian/control: changed libtidy0 to libtidy-0.99-0
* updated manpage
  (closes: #224427)

Show diffs side-by-side

added added

removed removed

Lines of Context:
6
6
  CVS Info :
7
7
 
8
8
    $Author: arnaud02 $ 
9
 
    $Date: 2005/04/08 09:11:13 $ 
10
 
    $Revision: 1.8 $ 
 
9
    $Date: 2005/09/21 10:24:15 $ 
 
10
    $Revision: 1.9 $ 
11
11
 
12
12
  Requires buffer to automatically grow as bytes are added.
13
13
  Must keep track of current read and write points.
91
91
 
92
92
/* Avoid thrashing memory by doubling buffer size
93
93
** until larger than requested size.
 
94
   buf->allocated is bigger than allocSize+1 so that a trailing null byte is
 
95
   always available.
94
96
*/
95
97
void TIDY_CALL tidyBufCheckAlloc( TidyBuffer* buf, uint allocSize, uint chunkSize )
96
98
{
97
99
    assert( buf != NULL );
98
100
    if ( 0 == chunkSize )
99
101
        chunkSize = 256;
100
 
    if ( allocSize > buf->allocated )
 
102
    if ( allocSize+1 > buf->allocated )
101
103
    {
102
104
        byte* bp;
103
105
        uint allocAmt = chunkSize;
104
106
        if ( buf->allocated > 0 )
105
107
            allocAmt = buf->allocated;
106
 
        while ( allocAmt < allocSize )
 
108
        while ( allocAmt < allocSize+1 )
107
109
            allocAmt *= 2;
108
110
 
109
111
        bp = (byte*)MemRealloc( buf->bp, allocAmt );