summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorChristophe Grenier <grenier@cgsecurity.org>2014-03-21 08:33:10 +0100
committerChristophe Grenier <grenier@cgsecurity.org>2014-03-21 08:33:10 +0100
commit79b567c4e6d0bda71d1d816fda7aaae1c3990e8b (patch)
tree921faa32de9f352da41ca5fcd48b7872b4bd9b24 /src
parent6d89d174d730c8804caf6a2c47dee500d140003d (diff)
Add assert() to document function assumptions in MALLOC(), pfind_sectors_per_cluster() and search_part()
Diffstat (limited to 'src')
-rw-r--r--src/common.c8
-rw-r--r--src/fat_unformat.c2
-rw-r--r--src/godmode.c2
3 files changed, 6 insertions, 6 deletions
diff --git a/src/common.c b/src/common.c
index 2aeeba4..17e8374 100644
--- a/src/common.c
+++ b/src/common.c
@@ -44,6 +44,7 @@
#ifdef HAVE_TIME_H
#include <time.h>
#endif
+#include <assert.h>
#include "types.h"
#include "common.h"
#include "log.h"
@@ -56,12 +57,7 @@ static unsigned int up2power_aux(const unsigned int number);
void *MALLOC(size_t size)
{
void *res;
- if(size<=0)
- {
- log_critical("Try to allocate 0 byte of memory\n");
- log_close();
- exit(EXIT_FAILURE);
- }
+ assert(size>0);
/* Warning, memory leak checker must be posix_memalign/memalign aware, otherwise *
* reports may look strange. Aligned memory is required if the buffer is *
* used for read/write operation with a file opened with O_DIRECT */
diff --git a/src/fat_unformat.c b/src/fat_unformat.c
index e15b943..01061ba 100644
--- a/src/fat_unformat.c
+++ b/src/fat_unformat.c
@@ -53,6 +53,7 @@
#include "pnext.h"
#include "setdate.h"
#include "fat_common.h"
+#include <assert.h>
#define READ_SIZE 4*1024*1024
static int pfind_sectors_per_cluster(disk_t *disk, partition_t *partition, const int verbose, unsigned int *sectors_per_cluster, uint64_t *offset_org, alloc_data_t *list_search_space)
@@ -66,6 +67,7 @@ static int pfind_sectors_per_cluster(disk_t *disk, partition_t *partition, const
alloc_data_t *current_search_space;
unsigned char *buffer_start=(unsigned char *)MALLOC(READ_SIZE);
unsigned char *buffer=buffer_start;
+ assert(disk->sector_size!=0);
current_search_space=td_list_entry(list_search_space->list.next, alloc_data_t, list);
if(current_search_space!=list_search_space)
offset=current_search_space->start;
diff --git a/src/godmode.c b/src/godmode.c
index 3e8107b..af2b6f2 100644
--- a/src/godmode.c
+++ b/src/godmode.c
@@ -27,6 +27,7 @@
#ifdef HAVE_STDLIB_H
#include <stdlib.h>
#endif
+#include <assert.h>
#include "types.h"
#include "common.h"
#include "fnctdsk.h"
@@ -537,6 +538,7 @@ static list_part_t *search_part(disk_t *disk_car, const list_part_t *list_part_o
((uint64_t) disk_car->geom.heads_per_cylinder * disk_car->geom.sectors_per_head * disk_car->sector_size) + 1 ) *
((uint64_t) disk_car->geom.heads_per_cylinder * disk_car->geom.sectors_per_head * disk_car->sector_size),
disk_car->disk_real_size);
+ assert(disk_car->sector_size>0);
partition=partition_new(disk_car->arch);
buffer_disk=(unsigned char*)MALLOC(16*DEFAULT_SECTOR_SIZE);
buffer_disk0=(unsigned char*)MALLOC(16*DEFAULT_SECTOR_SIZE);