* Copyright (C) 2007 by Dominic Rath *
* Dominic.Rath@gmx.de *
* *
+ * Copyright (C) 2007,2008 Øyvind Harboe *
+ * oyvind.harboe@zylin.com *
+ * *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
{
return retval;
}
- if ((retval = fileio_read(&fileio, 9, buffer, &read_bytes)) != ERROR_OK)
- {
- return ERROR_FILEIO_OPERATION_FAILED;
- }
- if (read_bytes != 9)
+ retval = fileio_read(&fileio, 9, buffer, &read_bytes);
+
+ if (retval==ERROR_OK)
{
- return ERROR_FILEIO_OPERATION_FAILED;
+ if (read_bytes != 9)
+ {
+ retval=ERROR_FILEIO_OPERATION_FAILED;
+ }
}
fileio_close(&fileio);
+
+ if (retval!=ERROR_OK)
+ return retval;
/* check header against known signatures */
if (strncmp((char*)buffer,ELFMAG,SELFMAG)==0)
elf->header = malloc(sizeof(Elf32_Ehdr));
+ if(elf->header == NULL)
+ {
+ LOG_ERROR("insufficient memory to perform operation ");
+ return ERROR_FILEIO_OPERATION_FAILED;
+ }
+
if ((retval = fileio_read(&elf->fileio, sizeof(Elf32_Ehdr), (u8*)elf->header, &read_bytes)) != ERROR_OK)
{
LOG_ERROR("cannot read ELF file header, read failed");
}
elf->segments = malloc(elf->segment_count*sizeof(Elf32_Phdr));
+ if(elf->segments == NULL)
+ {
+ LOG_ERROR("insufficient memory to perform operation ");
+ return ERROR_FILEIO_OPERATION_FAILED;
+ }
if ((retval = fileio_read(&elf->fileio, elf->segment_count*sizeof(Elf32_Phdr), (u8*)elf->segments, &read_bytes)) != ERROR_OK)
{