* [FFmpeg-devel] [PATCH] avcodec/vvcdec: allocate and store structs on their own within the table list
@ 2024-01-18 15:10 James Almer
2024-01-19 4:33 ` Nuo Mi
0 siblings, 1 reply; 2+ messages in thread
From: James Almer @ 2024-01-18 15:10 UTC (permalink / raw)
To: ffmpeg-devel
Fixes "runtime error: member access within misaligned address 0xf00 for type
'struct bar', which requires # byte alignment" errors under GCC ubsan.
Signed-off-by: James Almer <jamrial@gmail.com>
---
libavcodec/vvc/vvcdec.c | 34 +++++++++++-----------------------
1 file changed, 11 insertions(+), 23 deletions(-)
diff --git a/libavcodec/vvc/vvcdec.c b/libavcodec/vvc/vvcdec.c
index 54ada28124..540a05f8cf 100644
--- a/libavcodec/vvc/vvcdec.c
+++ b/libavcodec/vvc/vvcdec.c
@@ -55,14 +55,6 @@ typedef struct TabList {
l->nb_tabs++; \
} while (0)
-static size_t tl_size(const TabList *l)
-{
- size_t total = 0;
- for (int i = 0; i < l->nb_tabs; i++)
- total += l->tabs[i].size;
- return total;
-}
-
static void tl_init(TabList *l, const int zero, const int realloc)
{
l->nb_tabs = 0;
@@ -72,32 +64,28 @@ static void tl_init(TabList *l, const int zero, const int realloc)
static int tl_free(TabList *l)
{
- for (int i = 1; i < l->nb_tabs; i++) {
- void **p = l->tabs[i].tab;
- *p = NULL;
- }
- av_freep(l->tabs[0].tab);
+ for (int i = 0; i < l->nb_tabs; i++)
+ av_freep(l->tabs[i].tab);
+
return 0;
}
static int tl_create(TabList *l)
{
- size_t size = tl_size(l);
if (l->realloc) {
- uint8_t *p = l->zero ? av_mallocz(size) : av_malloc(size);
- if (!p)
- return AVERROR(ENOMEM);
tl_free(l);
- // set pointer for each table
for (int i = 0; i < l->nb_tabs; i++) {
Tab *t = l->tabs + i;
- *t->tab = p;
- p += t->size;
+ *t->tab = l->zero ? av_mallocz(t->size) : av_malloc(t->size);
+ if (!*t->tab)
+ return AVERROR(ENOMEM);
+ }
+ } else if (l->zero) {
+ for (int i = 0; i < l->nb_tabs; i++) {
+ Tab *t = l->tabs + i;
+ memset(*t->tab, 0, t->size);
}
- } else {
- if (l->zero)
- memset(*l->tabs[0].tab, 0, size);
}
return 0;
}
--
2.43.0
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [FFmpeg-devel] [PATCH] avcodec/vvcdec: allocate and store structs on their own within the table list
2024-01-18 15:10 [FFmpeg-devel] [PATCH] avcodec/vvcdec: allocate and store structs on their own within the table list James Almer
@ 2024-01-19 4:33 ` Nuo Mi
0 siblings, 0 replies; 2+ messages in thread
From: Nuo Mi @ 2024-01-19 4:33 UTC (permalink / raw)
To: FFmpeg development discussions and patches
On Thu, Jan 18, 2024 at 11:10 PM James Almer <jamrial@gmail.com> wrote:
> Fixes "runtime error: member access within misaligned address 0xf00 for
> type
> 'struct bar', which requires # byte alignment" errors under GCC ubsan.
>
LGTM
Thank you, James
>
> Signed-off-by: James Almer <jamrial@gmail.com>
> ---
> libavcodec/vvc/vvcdec.c | 34 +++++++++++-----------------------
> 1 file changed, 11 insertions(+), 23 deletions(-)
>
> diff --git a/libavcodec/vvc/vvcdec.c b/libavcodec/vvc/vvcdec.c
> index 54ada28124..540a05f8cf 100644
> --- a/libavcodec/vvc/vvcdec.c
> +++ b/libavcodec/vvc/vvcdec.c
> @@ -55,14 +55,6 @@ typedef struct TabList {
> l->nb_tabs++; \
> } while (0)
>
> -static size_t tl_size(const TabList *l)
> -{
> - size_t total = 0;
> - for (int i = 0; i < l->nb_tabs; i++)
> - total += l->tabs[i].size;
> - return total;
> -}
> -
> static void tl_init(TabList *l, const int zero, const int realloc)
> {
> l->nb_tabs = 0;
> @@ -72,32 +64,28 @@ static void tl_init(TabList *l, const int zero, const
> int realloc)
>
> static int tl_free(TabList *l)
> {
> - for (int i = 1; i < l->nb_tabs; i++) {
> - void **p = l->tabs[i].tab;
> - *p = NULL;
> - }
> - av_freep(l->tabs[0].tab);
> + for (int i = 0; i < l->nb_tabs; i++)
> + av_freep(l->tabs[i].tab);
> +
> return 0;
> }
>
> static int tl_create(TabList *l)
> {
> - size_t size = tl_size(l);
> if (l->realloc) {
> - uint8_t *p = l->zero ? av_mallocz(size) : av_malloc(size);
> - if (!p)
> - return AVERROR(ENOMEM);
> tl_free(l);
>
> - // set pointer for each table
> for (int i = 0; i < l->nb_tabs; i++) {
> Tab *t = l->tabs + i;
> - *t->tab = p;
> - p += t->size;
> + *t->tab = l->zero ? av_mallocz(t->size) : av_malloc(t->size);
> + if (!*t->tab)
> + return AVERROR(ENOMEM);
> + }
> + } else if (l->zero) {
> + for (int i = 0; i < l->nb_tabs; i++) {
> + Tab *t = l->tabs + i;
> + memset(*t->tab, 0, t->size);
> }
> - } else {
> - if (l->zero)
> - memset(*l->tabs[0].tab, 0, size);
> }
> return 0;
> }
> --
> 2.43.0
>
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
> To unsubscribe, visit link above, or email
> ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
>
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2024-01-19 4:34 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-01-18 15:10 [FFmpeg-devel] [PATCH] avcodec/vvcdec: allocate and store structs on their own within the table list James Almer
2024-01-19 4:33 ` Nuo Mi
Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
This inbox may be cloned and mirrored by anyone:
git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git
# If you have public-inbox 1.1+ installed, you may
# initialize and index your mirror using the following commands:
public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \
ffmpegdev@gitmailbox.com
public-inbox-index ffmpegdev
Example config snippet for mirrors.
AGPL code for this site: git clone https://public-inbox.org/public-inbox.git