/[jscoverage]/trunk/stream.c
ViewVC logotype

Diff of /trunk/stream.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 102 by siliconforks, Sat May 31 07:07:27 2008 UTC revision 210 by siliconforks, Fri Oct 3 02:25:02 2008 UTC
# Line 41  Line 41 
41  }  }
42    
43  void Stream_write(Stream * stream, const void * p, size_t size) {  void Stream_write(Stream * stream, const void * p, size_t size) {
44    if (SIZE_MAX - size < stream->length) {    size_t stream_length = stream->length;
45    
46      if (SIZE_MAX - size < stream_length) {
47      fatal("out of memory");      fatal("out of memory");
48    }    }
49    
50    size_t new_length = stream->length + size;    size_t new_length = stream_length + size;
51    size_t new_capacity = stream->capacity;    size_t new_capacity = stream->capacity;
52    if (new_capacity < new_length) {    if (new_capacity < new_length) {
53      if (SIZE_MAX / 2 < new_capacity) {      if (SIZE_MAX / 2 < new_capacity) {
# Line 58  Line 60 
60      if (new_capacity < new_length) {      if (new_capacity < new_length) {
61        new_capacity = new_length;        new_capacity = new_length;
62      }      }
   }  
63    
   if (new_capacity != stream->capacity) {  
64      stream->data = xrealloc(stream->data, new_capacity);      stream->data = xrealloc(stream->data, new_capacity);
65      stream->capacity = new_capacity;      stream->capacity = new_capacity;
66    }    }
67    
68    memcpy(stream->data + stream->length, p, size);    memcpy(stream->data + stream_length, p, size);
69    stream->length = new_length;    stream->length = new_length;
70  }  }
71    

Legend:
Removed from v.102  
changed lines
  Added in v.210

  ViewVC Help
Powered by ViewVC 1.1.24