cal: cal_read_block allocate memory
This commit is contained in:
1 parent
f7bad18a56
commit
117d0bb2d0
2 files changed
+11
-4
No files matched your search
@@ -264,6 +264,7 @@ int cal_read_block(struct cal * cal, const char * name, void ** ptr, unsigned lo
|
|||||||
uint64_t filelen = cal->size;
|
uint64_t filelen = cal->size;
|
||||||
uint8_t * data = cal->mem;
|
uint8_t * data = cal->mem;
|
||||||
struct header * hdr;
|
struct header * hdr;
|
||||||
|
void * offset;
|
||||||
|
|
||||||
find_offset = find_section(data, filelen, INDEX_LAST, name);
|
find_offset = find_section(data, filelen, INDEX_LAST, name);
|
||||||
if ( find_offset < 0 )
|
if ( find_offset < 0 )
|
||||||
@@ -277,12 +278,18 @@ int cal_read_block(struct cal * cal, const char * name, void ** ptr, unsigned lo
|
|||||||
if ( crc32(0, hdr, sizeof(*hdr) - 4) != hdr->hdrsum )
|
if ( crc32(0, hdr, sizeof(*hdr) - 4) != hdr->hdrsum )
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
*ptr = data + find_offset + sizeof(struct header);
|
offset = data + find_offset + sizeof(struct header);
|
||||||
*len = hdr->length;
|
|
||||||
|
|
||||||
if ( crc32(0, *ptr, *len) != hdr->datasum )
|
if ( crc32(0, offset, hdr->length) != hdr->datasum )
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
|
*ptr = malloc(hdr->length);
|
||||||
|
if (!ptr)
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
memcpy(*ptr, offset, hdr->length);
|
||||||
|
*len = hdr->length;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
}
|
}
|
||||||
+1
-1
@@ -53,7 +53,7 @@ static int root_device = -1;
|
|||||||
#define min(a, b) (a < b ? a : b)
|
#define min(a, b) (a < b ? a : b)
|
||||||
#define local_cal_copy(dest, from, len) strncpy(dest, from, min(len, sizeof(dest)-1))
|
#define local_cal_copy(dest, from, len) strncpy(dest, from, min(len, sizeof(dest)-1))
|
||||||
#define local_cal_read(cal, str, ptr, len) ( cal_read_block(cal, str, &ptr, &len, 0) == 0 && ptr )
|
#define local_cal_read(cal, str, ptr, len) ( cal_read_block(cal, str, &ptr, &len, 0) == 0 && ptr )
|
||||||
#define local_cal_readcopy(cal, str, dest) do { void * ptr; unsigned long int len; if ( local_cal_read(cal, str, ptr, len) ) local_cal_copy(dest, ptr, len); } while ( 0 )
|
#define local_cal_readcopy(cal, str, dest) do { void * ptr; unsigned long int len; if ( local_cal_read(cal, str, ptr, len) ) { local_cal_copy(dest, ptr, len); free(ptr); } } while ( 0 )
|
||||||
|
|
||||||
#if defined(__linux__) && defined(__arm__)
|
#if defined(__linux__) && defined(__arm__)
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user