-
Notifications
You must be signed in to change notification settings - Fork 339
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Return more errors where possible when bzcat fails #317
base: master
Are you sure you want to change the base?
Conversation
c79303d
to
209fa23
Compare
@@ -118,7 +121,7 @@ static unsigned int get_bits(struct bunzip_data *bd, char bits_wanted) | |||
// If we need to read more data from file into byte buffer, do so | |||
if (bd->inbufPos == bd->inbufCount) { | |||
if (0 >= (bd->inbufCount = read(bd->in_fd, bd->inbuf, IOBUF_SIZE))) | |||
error_exit("input EOF"); | |||
error_exit("input EOF"); // TODO: return RETVAL_UNEXPECTED_INPUT_EOF |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this one a todo when others are converted?
@@ -612,7 +619,8 @@ static int start_bunzip(struct bunzip_data **bdp, int src_fd, char *inbuf, | |||
if (!len) i += IOBUF_SIZE; | |||
|
|||
// Allocate bunzip_data. Most fields initialize to zero. | |||
bd = *bdp = xzalloc(i); | |||
bd = *bdp = (struct bunzip_data *)calloc(1, i); | |||
if (!bd) return RETVAL_OUT_OF_MEMORY; | |||
if (len) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A) You don't need to typecast a void * in c, it gets automatically converted to any other pointer type on assignment.
B) Unless you're on a nommu system malloc() basically never returns out of memory because it's a virtual allocation, the physical pages get mapped as they're dirtied and that triggers the OOM killer.
for (i=0; i<THREADS; i++) { | ||
bd->bwdata[i].dbuf = (unsigned int *)malloc(bd->dbufSize * sizeof(int)); | ||
if (!bd->bwdata[i].dbuf) return RETVAL_OUT_OF_MEMORY; | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Still don't need to typecast a void * in C.
This is based on the modified version of the code used by libxmp, minus the use of
setjmp
andlongjmp
to handleread
failures.