Skip to content
Snippets Groups Projects
Commit d4db0444 authored by Kostyantyn Vorobyov's avatar Kostyantyn Vorobyov Committed by Julien Signoles
Browse files

[ADT RTL]: Fixed the following bugs:

  - Incorrect initialization via realloc
  - Incorrect initialization test for partially initialized blocks
  - Unsupported specifiers in debug-level print
parent 63657f7d
No related branches found
No related tags found
No related merge requests found
...@@ -162,10 +162,11 @@ void* __realloc(void* ptr, size_t size) { ...@@ -162,10 +162,11 @@ void* __realloc(void* ptr, size_t size) {
/* realloc bigger larger block */ /* realloc bigger larger block */
else { else {
int nb = needed_bytes(size); int nb = needed_bytes(size);
int nb_old = needed_bytes(tmp->size);
tmp->init_ptr = native_malloc(nb); tmp->init_ptr = native_malloc(nb);
memset(tmp->init_ptr, 0xFF, nb); memset(tmp->init_ptr, 0xFF, nb_old);
if(size%8 != 0) if(tmp->size%8 != 0)
tmp->init_ptr[size/8] <<= (8 - size%8); tmp->init_ptr[tmp->size/8] &= ~(255 << tmp->size%8);
} }
} }
/* contains initialized and uninitialized parts */ /* contains initialized and uninitialized parts */
...@@ -292,11 +293,10 @@ int __initialized (void * ptr, size_t size) { ...@@ -292,11 +293,10 @@ int __initialized (void * ptr, size_t size) {
return true; return true;
for(i = 0; i < size; i++) { for(i = 0; i < size; i++) {
/* if one byte is uninitialized */ size_t offset = (uintptr_t)ptr - tmp->ptr + i;
int byte_offset = (size_t)ptr - tmp->ptr + i; int byte = offset/8;
int ind = byte_offset / 8; int bit = offset%8;
unsigned char mask_bit = 1U << (7 - (byte_offset % 8)); if (((tmp->init_ptr[byte] >> bit) & 1) == 0)
if((tmp->init_ptr[ind] & mask_bit) == 0)
return false; return false;
} }
return true; return true;
...@@ -400,16 +400,13 @@ void __e_acsl_memory_init(int *argc_ref, char ***argv_ref, size_t ptr_size) { ...@@ -400,16 +400,13 @@ void __e_acsl_memory_init(int *argc_ref, char ***argv_ref, size_t ptr_size) {
/* print the information about a block */ /* print the information about a block */
void __e_acsl_print_block (struct _block * ptr) { void __e_acsl_print_block (struct _block * ptr) {
if (ptr != NULL) { if (ptr != NULL) {
DLOG("%p; %zu Bytes; %slitteral; [init] : %li ", DLOG("%a; %lu Bytes; %slitteral; [init] : %d ",
(char*)ptr->ptr, ptr->size, (char*)ptr->ptr, ptr->size,
ptr->is_readonly ? "" : "not ", ptr->init_cpt); ptr->is_readonly ? "" : "not ", ptr->init_cpt);
if(ptr->init_ptr != NULL) { if(ptr->init_ptr != NULL) {
unsigned i; unsigned i;
for(i = 0; i < ptr->size; i++) { for(i = 0; i < ptr->size/8; i++)
int ind = i / 8; DLOG("%b ", ptr->init_ptr[i]);
int one_bit = (unsigned)1 << (8 - (i % 8) - 1);
DLOG("%i", (ptr->init_ptr[ind] & one_bit) != 0);
}
} }
DLOG("\n"); DLOG("\n");
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment