Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 28 additions & 19 deletions core/zip/src/Bits.c
Original file line number Diff line number Diff line change
Expand Up @@ -299,35 +299,39 @@ ulg R__memcompress(char *tgt, ulg tgtsize, const char *src, ulg srcsize)
ush flags = 0;
ulg crc = 0;
int method = Z_DEFLATED;
bits_internal_state state;
bits_internal_state *state = (bits_internal_state *) malloc(sizeof(bits_internal_state));
Comment thread
linev marked this conversation as resolved.
if (!state) {
R__error("fail to allocate bits_internal_state struct");
return 0L;
}

if (tgtsize <= 6L) { R__error("target buffer too small"); /* errorflag = 1; */ }
#if 0
crc = updcrc((char *)NULL, 0);
crc = updcrc(src, (extent) srcsize);
#endif
#ifdef DYN_ALLOC
state.R__window = 0;
state.R__prev = 0;
state->R__window = 0;
state->R__prev = 0;
#endif

/* R__read_buf = R__mem_read; */
/* assert(R__read_buf == R__mem_read); */
state.in_buf = src;
state.in_size = (unsigned)srcsize;
state.in_offset = 0;

state.out_buf = tgt;
state.out_size = (unsigned)tgtsize;
state.out_offset = 2 + 4;
state.R__window_size = 0L;

R__bi_init(&state);
state.t_state = R__get_thread_tree_state();
R__ct_init(state.t_state, &att, &method);
R__lm_init(&state,(gCompressionLevel != 0 ? gCompressionLevel : 1), &flags);
R__Deflate(&state,&(state.error_flag));
state.R__window_size = 0L; /* was updated by lm_init() */
state->in_buf = src;
state->in_size = (unsigned)srcsize;
state->in_offset = 0;

state->out_buf = tgt;
state->out_size = (unsigned)tgtsize;
state->out_offset = 2 + 4;
state->R__window_size = 0L;

R__bi_init(state);
state->t_state = R__get_thread_tree_state();
R__ct_init(state->t_state, &att, &method);
R__lm_init(state,(gCompressionLevel != 0 ? gCompressionLevel : 1), &flags);
R__Deflate(state,&(state->error_flag));
state->R__window_size = 0L; /* was updated by lm_init() */

/* For portability, force little-endian order on all machines: */
tgt[0] = (char)(method & 0xff);
Expand All @@ -337,7 +341,12 @@ ulg R__memcompress(char *tgt, ulg tgtsize, const char *src, ulg srcsize)
tgt[4] = (char)((crc >> 16) & 0xff);
tgt[5] = (char)((crc >> 24) & 0xff);

return (ulg)state.out_offset;
ulg res = (ulg)state->out_offset;

R__lm_free(state);
free(state);

return res;
}


Expand Down
3 changes: 3 additions & 0 deletions core/zip/src/RZip.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,9 @@ static void R__zipOld(int cxlevel, int *srcsize, const char *src, int *tgtsize,
tgt[8] = (char)((state.in_size >> 16) & 0xff);

*irep = state.out_offset;

R__lm_free(&state);

return;
}

Expand Down
4 changes: 3 additions & 1 deletion core/zip/src/ZDeflate.c
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ int R__lm_init (bits_internal_state *state, int pack_level, ush *flags)
/* ===========================================================================
* Free the window and hash table
*/
void R__lm_free()
void R__lm_free(bits_internal_state *state)
{
#ifdef DYN_ALLOC
Comment thread
silverweed marked this conversation as resolved.
if (state->R__window != NULL) {
Expand All @@ -313,6 +313,8 @@ void R__lm_free()
fcfree(state->R__head);
state->R__prev = state->R__head = NULL;
}
#else
(void) state;
#endif /* DYN_ALLOC */
}

Expand Down
2 changes: 1 addition & 1 deletion core/zip/src/ZIP.h
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ typedef struct tree_internal_state tree_internal_state;

/* in deflate.c */
int R__lm_init OF((bits_internal_state *state,int pack_level, ush *flags));
void R__lm_free OF((void));
void R__lm_free OF((bits_internal_state *state));
ulg R__Deflate OF((bits_internal_state *state,int *errorflag));

/* in trees.c */
Expand Down
Loading