sizeof(IndexSubItem) is more clear than 2 * sizeof(void *) and it avoids any questions about struct padding.
From: Alex Henrie alexhenrie24@gmail.com
sizeof(IndexSubItem) is more clear than 2 * sizeof(void *) and it avoids any questions about struct padding. --- dlls/hhctrl.ocx/index.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/dlls/hhctrl.ocx/index.c b/dlls/hhctrl.ocx/index.c index 113daa9efc9..97781fc10a9 100644 --- a/dlls/hhctrl.ocx/index.c +++ b/dlls/hhctrl.ocx/index.c @@ -129,7 +129,7 @@ static IndexItem *parse_index_sitemap_object(HHInfo *info, stream_t *stream)
item = calloc(1, sizeof(IndexItem)); item->nItems = 0; - item->items = calloc(2, sizeof(void *)); + item->items = calloc(1, sizeof(IndexSubItem)); item->itemFlags = 0x11;
while(next_node(stream, &node)) {
It doesn't matter what you allocate here, the pointer will be replaced when `item_realloc()` gets called. This line was originally an allocation of size 0 that got changed in commit 9dba420d0a78: ``` - item = heap_alloc_zero(sizeof(IndexItem)); + item = calloc(1, sizeof(IndexItem)); item->nItems = 0; - item->items = heap_alloc_zero(0); + item->items = calloc(2, sizeof(void *)); item->itemFlags = 0x11; ``` So, I would suggest making this a `malloc(0)` instead so that it's clear that we just want the pointer for later use in `realloc`.
On Sun Jun 18 00:44:41 2023 +0000, Erich Hoover wrote:
It doesn't matter what you allocate here, the pointer will be replaced when `item_realloc()` gets called. This line was originally an allocation of size 0 that got changed in commit 9dba420d0a78:
- item = heap_alloc_zero(sizeof(IndexItem)); + item = calloc(1, sizeof(IndexItem)); item->nItems = 0; - item->items = heap_alloc_zero(0); + item->items = calloc(2, sizeof(void *)); item->itemFlags = 0x11;
So, I would suggest making this a `malloc(0)` instead so that it's clear that we just want the pointer for later use in `realloc`.
I remember being confused as to the intention here when I converted this library to use CRT allocation functions. If the initial value is only used as a parameter to realloc, let's just initialize it to NULL.
On Sun Jun 18 00:44:41 2023 +0000, Alex Henrie wrote:
I remember being confused as to the intention here when I converted this library to use CRT allocation functions. If the initial value is only used as a parameter to realloc, let's just initialize it to NULL.
Wine might not care, but that won't work on all platforms (I have been burned by that before).
On Sun Jun 18 00:46:24 2023 +0000, Erich Hoover wrote:
Wine might not care, but that won't work on all platforms (I have been burned by that before).
I'm afraid that `malloc(0)` is even less likely to work in all CRT implementations. `realloc(NULL, size)` where size > 0 at least has the advantage of being required to work according to all versions of the C standard. In any case, it definitely works in Wine's msvcrt.