Skip to content

Commit

Permalink
Fix #1983 (bz2 import breaks)
Browse files Browse the repository at this point in the history
* Avoid a malloc(4) / free() and let the compiler figure that out
* sizeof(pointer) != sizeof(memory area pointed to by pointer)
  • Loading branch information
dmoagx committed Sep 18, 2014
1 parent 22d2e2a commit d1425fb
Showing 1 changed file with 4 additions and 7 deletions.
11 changes: 4 additions & 7 deletions Source/SPFileHandle.m
Expand Up @@ -90,7 +90,7 @@ - (id)initWithFile:(void *)theFile fromPath:(const char *)path mode:(int)mode
if (fileMode == O_RDONLY) {

int i, c;
char *bzbuf = malloc(4);
char bzbuf[4];
const char *charFileMode = fileMode == O_WRONLY ? "wb" : "rb";

BZFILE *bzfile;
Expand All @@ -112,12 +112,9 @@ - (id)initWithFile:(void *)theFile fromPath:(const char *)path mode:(int)mode
// indicate the Bzip version. Finally, the 4th byte should be a number between 1 and 9 that indicates
// the block size used.

BOOL isBzip2 = (sizeof(bzbuf) == 4) &&
((bzbuf[0] == 'B') && (bzbuf[1] == 'Z') &&
((bzbuf[2] == 'h') || (bzbuf[2] == '0')) &&
((bzbuf[3] >= 0x31) && (bzbuf[3] <= 0x39)));

free(bzbuf);
BOOL isBzip2 = ((bzbuf[0] == 'B') && (bzbuf[1] == 'Z')) &&
((bzbuf[2] == 'h') || (bzbuf[2] == '0')) &&
((bzbuf[3] >= 0x31) && (bzbuf[3] <= 0x39));

if (isBzip2) bzfile = BZ2_bzopen(path, charFileMode);

Expand Down

0 comments on commit d1425fb

Please sign in to comment.