multiboot: Simplify to avoid confusing assignment.

Found by: Coverity scan.
This commit is contained in:
Vladimir Serbinenko 2015-01-26 09:43:52 +01:00
parent 1e0d718371
commit ef02b4ca93
2 changed files with 39 additions and 22 deletions

View file

@ -121,6 +121,24 @@ load_kernel (grub_file_t file, const char *filename,
return grub_multiboot_load_elf (file, filename, buffer);
}
static struct multiboot_header *
find_header (char *buffer, grub_ssize_t len)
{
struct multiboot_header *header;
/* Look for the multiboot header in the buffer. The header should
be at least 12 bytes and aligned on a 4-byte boundary. */
for (header = (struct multiboot_header *) buffer;
((char *) header <= buffer + len - 12);
header = (struct multiboot_header *) ((char *) header + MULTIBOOT_HEADER_ALIGN))
{
if (header->magic == MULTIBOOT_HEADER_MAGIC
&& !(header->magic + header->flags + header->checksum))
return header;
}
return NULL;
}
grub_err_t
grub_multiboot_load (grub_file_t file, const char *filename)
{
@ -143,16 +161,7 @@ grub_multiboot_load (grub_file_t file, const char *filename)
return grub_errno;
}
/* Look for the multiboot header in the buffer. The header should
be at least 12 bytes and aligned on a 4-byte boundary. */
for (header = (struct multiboot_header *) buffer;
((char *) header <= buffer + len - 12) || (header = 0);
header = (struct multiboot_header *) ((char *) header + MULTIBOOT_HEADER_ALIGN))
{
if (header->magic == MULTIBOOT_HEADER_MAGIC
&& !(header->magic + header->flags + header->checksum))
break;
}
header = find_header (buffer, len);
if (header == 0)
{

View file

@ -79,6 +79,25 @@ grub_multiboot_add_elfsyms (grub_size_t num, grub_size_t entsize,
elf_sections = data;
}
static struct multiboot_header *
find_header (grub_properly_aligned_t *buffer, grub_ssize_t len)
{
struct multiboot_header *header;
/* Look for the multiboot header in the buffer. The header should
be at least 12 bytes and aligned on a 4-byte boundary. */
for (header = (struct multiboot_header *) buffer;
((char *) header <= (char *) buffer + len - 12);
header = (struct multiboot_header *) ((grub_uint32_t *) header + MULTIBOOT_HEADER_ALIGN / 4))
{
if (header->magic == MULTIBOOT_HEADER_MAGIC
&& !(header->magic + header->architecture
+ header->header_length + header->checksum)
&& header->architecture == MULTIBOOT_ARCHITECTURE_CURRENT)
return header;
}
return NULL;
}
grub_err_t
grub_multiboot_load (grub_file_t file, const char *filename)
{
@ -107,18 +126,7 @@ grub_multiboot_load (grub_file_t file, const char *filename)
COMPILE_TIME_ASSERT (MULTIBOOT_HEADER_ALIGN % 4 == 0);
/* Look for the multiboot header in the buffer. The header should
be at least 12 bytes and aligned on a 4-byte boundary. */
for (header = (struct multiboot_header *) buffer;
((char *) header <= (char *) buffer + len - 12) || (header = 0);
header = (struct multiboot_header *) ((grub_uint32_t *) header + MULTIBOOT_HEADER_ALIGN / 4))
{
if (header->magic == MULTIBOOT_HEADER_MAGIC
&& !(header->magic + header->architecture
+ header->header_length + header->checksum)
&& header->architecture == MULTIBOOT_ARCHITECTURE_CURRENT)
break;
}
header = find_header (buffer, len);
if (header == 0)
{