* grub-core/kern/disk.c (grub_disk_write): Use malloc/free instead of

variable length arrays.

	Saves 50 bytes on compressed image.
This commit is contained in:
Vladimir 'phcoder' Serbinenko 2013-10-21 00:10:34 +02:00
parent 2e4659b810
commit 2cc679adae
2 changed files with 19 additions and 2 deletions

View File

@ -1,3 +1,10 @@
2013-10-20 Vladimir Serbinenko <phcoder@gmail.com>
* grub-core/kern/disk.c (grub_disk_write): Use malloc/free instead of
variable length arrays.
Saves 50 bytes on compressed image.
2013-10-20 Vladimir Serbinenko <phcoder@gmail.com>
* grub-core/loader/i386/bsd.c: Remove variable length arrays.

View File

@ -635,10 +635,14 @@ grub_disk_write (grub_disk_t disk, grub_disk_addr_t sector,
if (real_offset != 0 || (size < (1U << disk->log_sector_size)
&& size != 0))
{
char tmp_buf[1 << disk->log_sector_size];
char *tmp_buf;
grub_size_t len;
grub_partition_t part;
tmp_buf = grub_malloc (1 << disk->log_sector_size);
if (!tmp_buf)
return grub_errno;
part = disk->partition;
disk->partition = 0;
if (grub_disk_read (disk, sector,
@ -646,6 +650,7 @@ grub_disk_write (grub_disk_t disk, grub_disk_addr_t sector,
!= GRUB_ERR_NONE)
{
disk->partition = part;
grub_free (tmp_buf);
goto finish;
}
disk->partition = part;
@ -660,7 +665,12 @@ grub_disk_write (grub_disk_t disk, grub_disk_addr_t sector,
if ((disk->dev->write) (disk, transform_sector (disk, sector),
1, tmp_buf) != GRUB_ERR_NONE)
goto finish;
{
grub_free (tmp_buf);
goto finish;
}
grub_free (tmp_buf);
sector += (1 << (disk->log_sector_size - GRUB_DISK_SECTOR_BITS));
buf = (const char *) buf + len;