about summary refs log tree commit diff stats
path: root/miasm2/jitter/vm_mngr.c
diff options
context:
space:
mode:
Diffstat (limited to 'miasm2/jitter/vm_mngr.c')
-rw-r--r--miasm2/jitter/vm_mngr.c77
1 files changed, 13 insertions, 64 deletions
diff --git a/miasm2/jitter/vm_mngr.c b/miasm2/jitter/vm_mngr.c
index 1114185b..59cbdf6e 100644
--- a/miasm2/jitter/vm_mngr.c
+++ b/miasm2/jitter/vm_mngr.c
@@ -103,6 +103,10 @@ void memory_access_list_add(struct memory_access_list * access, uint64_t start,
 		else
 			access->allocated *= 2;
 		access->array = realloc(access->array, access->allocated * sizeof(struct memory_access));
+		if (access->array == NULL) {
+			fprintf(stderr, "cannot realloc struct memory_access access->array\n");
+			exit(EXIT_FAILURE);
+		}
 	}
 	access->array[access->num].start = start;
 	access->array[access->num].stop = stop;
@@ -669,66 +673,6 @@ int is_mapped(vm_mngr_t* vm_mngr, uint64_t addr, uint64_t size)
        return 1;
 }
 
-int shift_right_arith(unsigned int size, int a, unsigned int b)
-{
-    int i32_a;
-    short i16_a;
-    char i8_a;
-    switch(size){
-	    case 8:
-		    i8_a = a;
-		    return (i8_a >> b)&0xff;
-	    case 16:
-		    i16_a = a;
-		    return (i16_a >> b)&0xffff;
-	    case 32:
-		    i32_a = a;
-		    return (i32_a >> b)&0xffffffff;
-	    default:
-		    fprintf(stderr, "inv size in shift %d\n", size);
-		    exit(0);
-    }
-}
-
-uint64_t shift_right_logic(uint64_t size,
-			   uint64_t a, uint64_t b)
-{
-    uint64_t u32_a;
-    unsigned short u16_a;
-    unsigned char u8_a;
-    switch(size){
-	    case 8:
-		    u8_a = a;
-		    return (u8_a >> b)&0xff;
-	    case 16:
-		    u16_a = a;
-		    return (u16_a >> b)&0xffff;
-	    case 32:
-		    u32_a = a;
-		    return (u32_a >> b)&0xffffffff;
-	    default:
-		    fprintf(stderr, "inv size in shift %"PRIx64"\n", size);
-		    exit(0);
-    }
-}
-
-uint64_t shift_left_logic(uint64_t size, uint64_t a, uint64_t b)
-{
-    switch(size){
-	    case 8:
-		    return (a<<b)&0xff;
-	    case 16:
-		    return (a<<b)&0xffff;
-	    case 32:
-		    return (a<<b)&0xffffffff;
-	    case 64:
-		    return (a<<b)&0xffffffffffffffff;
-	    default:
-		    fprintf(stderr, "inv size in shift %"PRIx64"\n", size);
-		    exit(0);
-    }
-}
-
 unsigned int mul_lo_op(unsigned int size, unsigned int a, unsigned int b)
 {
 	unsigned int mask;
@@ -1602,6 +1546,11 @@ void add_memory_page(vm_mngr_t* vm_mngr, struct memory_page_node* mpn_a)
 	vm_mngr->memory_pages_array = realloc(vm_mngr->memory_pages_array,
 					      sizeof(struct memory_page_node) *
 					      (vm_mngr->memory_pages_number+1));
+	if (vm_mngr->memory_pages_array == NULL) {
+		fprintf(stderr, "cannot realloc struct memory_page_node vm_mngr->memory_pages_array\n");
+		exit(EXIT_FAILURE);
+	}
+
 
 	memmove(&vm_mngr->memory_pages_array[i+1],
 		&vm_mngr->memory_pages_array[i],
@@ -1629,8 +1578,8 @@ char* dump(vm_mngr_t* vm_mngr)
 
 	buf_final = malloc(total_len);
 	if (buf_final == NULL) {
-		fprintf(stderr, "Error: cannot alloc\n");
-		exit(0);
+		fprintf(stderr, "Error: cannot alloc char* buf_final\n");
+		exit(EXIT_FAILURE);
 	}
 	strcpy(buf_final, intro);
 	for (i=0; i< vm_mngr->memory_pages_number; i++) {
@@ -1653,8 +1602,8 @@ char* dump(vm_mngr_t* vm_mngr)
 		total_len += length + 1 + 1;
 		buf_final = realloc(buf_final, total_len);
 		if (buf_final == NULL) {
-			fprintf(stderr, "Error: cannot alloc\n");
-			exit(0);
+			fprintf(stderr, "cannot realloc char* buf_final\n");
+			exit(EXIT_FAILURE);
 		}
 		strcat(buf_final, buf);
 	}