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
15 changes: 7 additions & 8 deletions lib/file.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
#endif
#include "cabfile.h"
#include "log.h"
#include <assert.h>
#include <stdlib.h>
#include <string.h>

Expand Down Expand Up @@ -58,7 +57,7 @@ static FileDescriptor* unshield_read_file_descriptor(Unshield* unshield, int ind

fd->name_offset = READ_UINT32(p); p += 4;
fd->directory_index = READ_UINT16(p); p += 2;
assert(fd->directory_index < unshield_directory_count(unshield));
UNSHIELD_ASSERT(fd->directory_index < unshield_directory_count(unshield));

p += 2;
fd->flags = READ_UINT16(p); p += 2;
Expand All @@ -80,7 +79,7 @@ static FileDescriptor* unshield_read_file_descriptor(Unshield* unshield, int ind
if (header->major_version == 5)
{
memcpy(fd->md5, p, 0x10); p += 0x10;
assert((p - saved_p) == 0x3a);
UNSHIELD_ASSERT((p - saved_p) == 0x3a);
}

break;
Expand Down Expand Up @@ -111,9 +110,9 @@ static FileDescriptor* unshield_read_file_descriptor(Unshield* unshield, int ind
p += 0x10;
fd->name_offset = READ_UINT32(p); p += 4;
fd->directory_index = READ_UINT16(p); p += 2;
assert(fd->directory_index < unshield_directory_count(unshield));
UNSHIELD_ASSERT(fd->directory_index < unshield_directory_count(unshield));

assert((p - saved_p) == 0x40);
UNSHIELD_ASSERT((p - saved_p) == 0x40);

p += 0xc;
fd->link_previous = READ_UINT32(p); p += 4;
Expand All @@ -130,7 +129,7 @@ static FileDescriptor* unshield_read_file_descriptor(Unshield* unshield, int ind

fd->volume = READ_UINT16(p); p += 2;

assert((p - saved_p) == 0x57);
UNSHIELD_ASSERT((p - saved_p) == 0x57);
break;
}

Expand Down Expand Up @@ -938,7 +937,7 @@ int unshield_file_directory(Unshield* unshield, int index)/*{{{*/
FileDescriptor* fd = unshield_get_file_descriptor(unshield, index);
if (fd)
{
assert(fd->directory_index < unshield_directory_count(unshield));
UNSHIELD_ASSERT(fd->directory_index < unshield_directory_count(unshield));
return fd->directory_index;
}
else
Expand Down Expand Up @@ -1167,7 +1166,7 @@ bool unshield_file_save_old(Unshield* unshield, int index, const char* filename)
#endif

input_buffer = realloc(input_buffer, input_buffer_size);
assert(input_buffer);
UNSHIELD_ASSERT(input_buffer);
}

if (!unshield_reader_read(reader, input_buffer, input_size))
Expand Down
3 changes: 1 addition & 2 deletions lib/libunshield.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
#define _DEFAULT_SOURCE 1
#include "internal.h"
#include "log.h"
#include <assert.h>
#include <ctype.h>
#include <stdlib.h>
#include <string.h>
Expand Down Expand Up @@ -144,7 +143,7 @@ static bool unshield_get_cab_descriptor(Header* header)
header->cab.file_count = READ_UINT32(p); p += 4;
header->cab.file_table_offset2 = READ_UINT32(p); p += 4;

assert((p - (header->data + header->common.cab_descriptor_offset)) == 0x30);
UNSHIELD_ASSERT((p - (header->data + header->common.cab_descriptor_offset)) == 0x30);

if (header->cab.file_table_size != header->cab.file_table_size2)
unshield_warning("File table sizes do not match");
Expand Down
9 changes: 9 additions & 0 deletions lib/libunshield.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,15 @@

#define UNSHIELD_LOG_LEVEL_HIGHEST 4

#ifdef NDEBUG
#undef NDEBUG
#include <assert.h>
#define UNSHIELD_ASSERT(x) assert(x)
#define NDEBUG
#else
#include <assert.h>
#define UNSHIELD_ASSERT(x) assert(x)
#endif

#ifdef __cplusplus
extern "C" {
Expand Down