summaryrefslogtreecommitdiff
path: root/xdelta3/xdelta3-second.h
diff options
context:
space:
mode:
Diffstat (limited to 'xdelta3/xdelta3-second.h')
-rw-r--r--xdelta3/xdelta3-second.h38
1 files changed, 19 insertions, 19 deletions
diff --git a/xdelta3/xdelta3-second.h b/xdelta3/xdelta3-second.h
index f72ed9b..b9830ab 100644
--- a/xdelta3/xdelta3-second.h
+++ b/xdelta3/xdelta3-second.h
@@ -94,25 +94,27 @@ xd3_test_clean_bits (xd3_stream *stream, bit_state *bits)
94} 94}
95#endif 95#endif
96 96
97static xd3_sec_stream* 97static int
98xd3_get_secondary (xd3_stream *stream, xd3_sec_stream **sec_streamp) 98xd3_get_secondary (xd3_stream *stream, xd3_sec_stream **sec_streamp,
99 int is_encode)
99{ 100{
100 xd3_sec_stream *sec_stream; 101 if (*sec_streamp == NULL)
101
102 if ((sec_stream = *sec_streamp) == NULL)
103 { 102 {
103 int ret;
104
104 if ((*sec_streamp = stream->sec_type->alloc (stream)) == NULL) 105 if ((*sec_streamp = stream->sec_type->alloc (stream)) == NULL)
105 { 106 {
106 return NULL; 107 stream->msg = "error initializing secondary stream";
108 return XD3_INVALID;
107 } 109 }
108 110
109 sec_stream = *sec_streamp; 111 if ((ret = stream->sec_type->init (stream, *sec_streamp, is_encode)) != 0)
110 112 {
111 /* If cuumulative stats, init once. */ 113 return ret;
112 stream->sec_type->init (sec_stream); 114 }
113 } 115 }
114 116
115 return sec_stream; 117 return 0;
116} 118}
117 119
118static int 120static int
@@ -120,14 +122,13 @@ xd3_decode_secondary (xd3_stream *stream,
120 xd3_desect *sect, 122 xd3_desect *sect,
121 xd3_sec_stream **sec_streamp) 123 xd3_sec_stream **sec_streamp)
122{ 124{
123 xd3_sec_stream *sec_stream;
124 uint32_t dec_size; 125 uint32_t dec_size;
125 uint8_t *out_used; 126 uint8_t *out_used;
126 int ret; 127 int ret;
127 128
128 if ((sec_stream = xd3_get_secondary (stream, sec_streamp)) == NULL) 129 if ((ret = xd3_get_secondary (stream, sec_streamp, 0)) != 0)
129 { 130 {
130 return ENOMEM; 131 return ret;
131 } 132 }
132 133
133 /* Decode the size, allocate the buffer. */ 134 /* Decode the size, allocate the buffer. */
@@ -141,7 +142,7 @@ xd3_decode_secondary (xd3_stream *stream,
141 142
142 out_used = sect->copied2; 143 out_used = sect->copied2;
143 144
144 if ((ret = stream->sec_type->decode (stream, sec_stream, 145 if ((ret = stream->sec_type->decode (stream, *sec_streamp,
145 & sect->buf, sect->buf_max, 146 & sect->buf, sect->buf_max,
146 & out_used, out_used + dec_size))) 147 & out_used, out_used + dec_size)))
147 { 148 {
@@ -244,7 +245,6 @@ xd3_encode_secondary (xd3_stream *stream,
244 xd3_sec_cfg *cfg, 245 xd3_sec_cfg *cfg,
245 int *did_it) 246 int *did_it)
246{ 247{
247 xd3_sec_stream *sec_stream;
248 xd3_output *tmp_head; 248 xd3_output *tmp_head;
249 xd3_output *tmp_tail; 249 xd3_output *tmp_tail;
250 250
@@ -257,9 +257,9 @@ xd3_encode_secondary (xd3_stream *stream,
257 257
258 if (orig_size < SECONDARY_MIN_INPUT) { return 0; } 258 if (orig_size < SECONDARY_MIN_INPUT) { return 0; }
259 259
260 if ((sec_stream = xd3_get_secondary (stream, sec_streamp)) == NULL) 260 if ((ret = xd3_get_secondary (stream, sec_streamp, 1)) != 0)
261 { 261 {
262 return ENOMEM; 262 return ret;
263 } 263 }
264 264
265 tmp_head = xd3_alloc_output (stream, NULL); 265 tmp_head = xd3_alloc_output (stream, NULL);
@@ -268,7 +268,7 @@ xd3_encode_secondary (xd3_stream *stream,
268 * simpler, but is a little gross. Should not need the entire 268 * simpler, but is a little gross. Should not need the entire
269 * section in contiguous memory, but it is much easier this way. */ 269 * section in contiguous memory, but it is much easier this way. */
270 if ((ret = xd3_emit_size (stream, & tmp_head, orig_size)) || 270 if ((ret = xd3_emit_size (stream, & tmp_head, orig_size)) ||
271 (ret = stream->sec_type->encode (stream, sec_stream, *head, 271 (ret = stream->sec_type->encode (stream, *sec_streamp, *head,
272 tmp_head, cfg))) 272 tmp_head, cfg)))
273 { 273 {
274 goto getout; 274 goto getout;