X-Git-Url: https://review.openocd.org/gitweb?a=blobdiff_plain;f=src%2Ftarget%2Fimage.c;h=454fc6c183baa8ed8e4f1de039c5dbd11989150e;hb=33a17fd35995a7f679f92600055a8f55ae380022;hp=d36fbc34c83bb8eb543439bb2a3ebcc4c03be1a8;hpb=19167a7af6053f1eba0420509408731db007368c;p=openocd.git diff --git a/src/target/image.c b/src/target/image.c index d36fbc34c8..454fc6c183 100644 --- a/src/target/image.c +++ b/src/target/image.c @@ -158,7 +158,13 @@ static int image_ihex_buffer_complete_inner(struct image *image, char *lpszLine, /* we can't determine the number of sections that we'll have to create ahead of time, * so we locally hold them until parsing is finished */ - ihex->buffer = malloc(fileio->size >> 1); + int filesize; + int retval; + retval = fileio_size(fileio, &filesize); + if (retval != ERROR_OK) + return retval; + + ihex->buffer = malloc(filesize >> 1); cooked_bytes = 0x0; image->num_sections = 0; section[image->num_sections].private = &ihex->buffer[cooked_bytes]; @@ -425,7 +431,7 @@ static int image_elf_read_headers(struct image *image) if ((elf->endianness != ELFDATA2LSB) &&(elf->endianness != ELFDATA2MSB)) { - LOG_ERROR("invalid ELF file, unknown endianess setting"); + LOG_ERROR("invalid ELF file, unknown endianness setting"); return ERROR_IMAGE_FORMAT_ERROR; } @@ -537,7 +543,13 @@ static int image_mot_buffer_complete_inner(struct image *image, char *lpszLine, /* we can't determine the number of sections that we'll have to create ahead of time, * so we locally hold them until parsing is finished */ - mot->buffer = malloc(fileio->size >> 1); + int retval; + int filesize; + retval = fileio_size(fileio, &filesize); + if (retval != ERROR_OK) + return retval; + + mot->buffer = malloc(filesize >> 1); cooked_bytes = 0x0; image->num_sections = 0; section[image->num_sections].private = &mot->buffer[cooked_bytes]; @@ -743,11 +755,18 @@ int image_open(struct image *image, const char *url, const char *type_string) { return retval; } + int filesize; + retval = fileio_size(&image_binary->fileio, &filesize); + if (retval != ERROR_OK) + { + fileio_close(&image_binary->fileio); + return retval; + } image->num_sections = 1; image->sections = malloc(sizeof(struct imagesection)); image->sections[0].base_address = 0x0; - image->sections[0].size = image_binary->fileio.size; + image->sections[0].size = filesize; image->sections[0].flags = 0; } else if (image->type == IMAGE_IHEX)