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

Diff of /trunk/stream.c

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

revision 92 by siliconforks, Wed May 7 04:21:22 2008 UTC revision 210 by siliconforks, Fri Oct 3 02:25:02 2008 UTC
# Line 19  Line 19 
19    
20  #define _GNU_SOURCE  #define _GNU_SOURCE
21    
22    #include <config.h>
23    
24  #include "stream.h"  #include "stream.h"
25    
26  #include <stdarg.h>  #include <stdarg.h>
# Line 39  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 56  Line 60 
60      if (new_capacity < new_length) {      if (new_capacity < new_length) {
61        new_capacity = new_length;        new_capacity = new_length;
62      }      }
   }  
63    
64    if (new_capacity != stream->capacity) {      stream->data = xrealloc(stream->data, new_capacity);
     stream->data = xrealloc(stream->data, stream->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    
# Line 103  Line 105 
105    free(stream->data);    free(stream->data);
106    free(stream);    free(stream);
107  }  }
108    
109    void Stream_reset(Stream * stream) {
110      stream->length = 0;
111    }

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

  ViewVC Help
Powered by ViewVC 1.1.24