Skip to content

Commit d1425fb

Browse files
committed
Fix #1983 (bz2 import breaks)
* Avoid a malloc(4) / free() and let the compiler figure that out * sizeof(pointer) != sizeof(memory area pointed to by pointer)
1 parent 22d2e2a commit d1425fb

File tree

1 file changed

+4
-7
lines changed

1 file changed

+4
-7
lines changed

Source/SPFileHandle.m

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ - (id)initWithFile:(void *)theFile fromPath:(const char *)path mode:(int)mode
9090
if (fileMode == O_RDONLY) {
9191

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

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

115-
BOOL isBzip2 = (sizeof(bzbuf) == 4) &&
116-
((bzbuf[0] == 'B') && (bzbuf[1] == 'Z') &&
117-
((bzbuf[2] == 'h') || (bzbuf[2] == '0')) &&
118-
((bzbuf[3] >= 0x31) && (bzbuf[3] <= 0x39)));
119-
120-
free(bzbuf);
115+
BOOL isBzip2 = ((bzbuf[0] == 'B') && (bzbuf[1] == 'Z')) &&
116+
((bzbuf[2] == 'h') || (bzbuf[2] == '0')) &&
117+
((bzbuf[3] >= 0x31) && (bzbuf[3] <= 0x39));
121118

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

0 commit comments

Comments
 (0)