* grub-core/fs/hfs.c: Remove variable length arrays.
Reduces hfs.mod by 8 bytes (52 compressed).
This commit is contained in:
parent
0927e5bdc8
commit
66123940c7
2 changed files with 34 additions and 18 deletions
|
@ -1,3 +1,8 @@
|
||||||
|
2013-10-20 Vladimir Serbinenko <phcoder@gmail.com>
|
||||||
|
|
||||||
|
* grub-core/fs/hfs.c: Remove variable length arrays.
|
||||||
|
Reduces hfs.mod by 8 bytes (52 compressed).
|
||||||
|
|
||||||
2013-10-20 Vladimir Serbinenko <phcoder@gmail.com>
|
2013-10-20 Vladimir Serbinenko <phcoder@gmail.com>
|
||||||
|
|
||||||
* grub-core/fs/udf.c: Remove variable length arrays.
|
* grub-core/fs/udf.c: Remove variable length arrays.
|
||||||
|
|
|
@ -665,14 +665,21 @@ grub_hfs_iterate_records (struct grub_hfs_data *data, int type, int idx,
|
||||||
void *hook_arg),
|
void *hook_arg),
|
||||||
void *hook_arg)
|
void *hook_arg)
|
||||||
{
|
{
|
||||||
int nodesize = type == 0 ? data->cat_size : data->ext_size;
|
grub_size_t nodesize = type == 0 ? data->cat_size : data->ext_size;
|
||||||
|
|
||||||
union
|
union node_union
|
||||||
{
|
{
|
||||||
struct grub_hfs_node node;
|
struct grub_hfs_node node;
|
||||||
char rawnode[nodesize];
|
char rawnode[0];
|
||||||
grub_uint16_t offsets[nodesize / 2];
|
grub_uint16_t offsets[0];
|
||||||
} node;
|
} *node;
|
||||||
|
|
||||||
|
if (nodesize < sizeof (struct grub_hfs_node))
|
||||||
|
nodesize = sizeof (struct grub_hfs_node);
|
||||||
|
|
||||||
|
node = grub_malloc (nodesize);
|
||||||
|
if (!node)
|
||||||
|
return grub_errno;
|
||||||
|
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
|
@ -689,15 +696,16 @@ grub_hfs_iterate_records (struct grub_hfs_data *data, int type, int idx,
|
||||||
(type == 0) ? GRUB_HFS_CNID_CAT : GRUB_HFS_CNID_EXT,
|
(type == 0) ? GRUB_HFS_CNID_CAT : GRUB_HFS_CNID_EXT,
|
||||||
idx / (data->blksz / nodesize), 0);
|
idx / (data->blksz / nodesize), 0);
|
||||||
blk += (idx % (data->blksz / nodesize));
|
blk += (idx % (data->blksz / nodesize));
|
||||||
if (grub_errno)
|
|
||||||
return grub_errno;
|
|
||||||
|
|
||||||
if (grub_disk_read (data->disk, blk, 0,
|
if (grub_errno || grub_disk_read (data->disk, blk, 0,
|
||||||
sizeof (node), &node))
|
nodesize, node))
|
||||||
return grub_errno;
|
{
|
||||||
|
grub_free (node);
|
||||||
|
return grub_errno;
|
||||||
|
}
|
||||||
|
|
||||||
/* Iterate over all records in this node. */
|
/* Iterate over all records in this node. */
|
||||||
for (i = 0; i < grub_be_to_cpu16 (node.node.reccnt); i++)
|
for (i = 0; i < grub_be_to_cpu16 (node->node.reccnt); i++)
|
||||||
{
|
{
|
||||||
int pos = (nodesize >> 1) - 1 - i;
|
int pos = (nodesize >> 1) - 1 - i;
|
||||||
struct pointer
|
struct pointer
|
||||||
|
@ -705,25 +713,28 @@ grub_hfs_iterate_records (struct grub_hfs_data *data, int type, int idx,
|
||||||
grub_uint8_t keylen;
|
grub_uint8_t keylen;
|
||||||
grub_uint8_t key;
|
grub_uint8_t key;
|
||||||
} __attribute__ ((packed)) *pnt;
|
} __attribute__ ((packed)) *pnt;
|
||||||
pnt = (struct pointer *) (grub_be_to_cpu16 (node.offsets[pos])
|
pnt = (struct pointer *) (grub_be_to_cpu16 (node->offsets[pos])
|
||||||
+ node.rawnode);
|
+ node->rawnode);
|
||||||
|
|
||||||
struct grub_hfs_record rec =
|
struct grub_hfs_record rec =
|
||||||
{
|
{
|
||||||
&pnt->key,
|
&pnt->key,
|
||||||
pnt->keylen,
|
pnt->keylen,
|
||||||
&pnt->key + pnt->keylen +(pnt->keylen + 1) % 2,
|
&pnt->key + pnt->keylen +(pnt->keylen + 1) % 2,
|
||||||
nodesize - grub_be_to_cpu16 (node.offsets[pos])
|
nodesize - grub_be_to_cpu16 (node->offsets[pos])
|
||||||
- pnt->keylen - 1
|
- pnt->keylen - 1
|
||||||
};
|
};
|
||||||
|
|
||||||
if (node_hook (&node.node, &rec, hook_arg))
|
if (node_hook (&node->node, &rec, hook_arg))
|
||||||
return 0;
|
{
|
||||||
|
grub_free (node);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
idx = grub_be_to_cpu32 (node.node.next);
|
idx = grub_be_to_cpu32 (node->node.next);
|
||||||
} while (idx && this);
|
} while (idx && this);
|
||||||
|
grub_free (node);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue