From e198cf5d5b1531b628bad0b798b120e78fc88340 Mon Sep 17 00:00:00 2001 From: Quentin Renard Date: Fri, 29 Mar 2024 10:09:33 +0100 Subject: [PATCH] Updated max array size computation --- filter_context.go | 5 +++-- format_context.go | 6 +----- 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/filter_context.go b/filter_context.go index 94325ee..f48f969 100644 --- a/filter_context.go +++ b/filter_context.go @@ -7,6 +7,7 @@ package astiav //#include import "C" import ( + "math" "unsafe" ) @@ -60,7 +61,7 @@ func (fc *FilterContext) NbOutputs() int { } func (fc *FilterContext) Inputs() (ls []*FilterLink) { - lcs := (*[maxArraySize](*C.struct_AVFilterLink))(unsafe.Pointer(fc.c.inputs)) + lcs := (*[(math.MaxInt32 - 1) / unsafe.Sizeof((*C.struct_AVFilterLink)(nil))](*C.struct_AVFilterLink))(unsafe.Pointer(fc.c.inputs)) for i := 0; i < fc.NbInputs(); i++ { ls = append(ls, newFilterLinkFromC(lcs[i])) } @@ -68,7 +69,7 @@ func (fc *FilterContext) Inputs() (ls []*FilterLink) { } func (fc *FilterContext) Outputs() (ls []*FilterLink) { - lcs := (*[maxArraySize](*C.struct_AVFilterLink))(unsafe.Pointer(fc.c.outputs)) + lcs := (*[(math.MaxInt32 - 1) / unsafe.Sizeof((*C.struct_AVFilterLink)(nil))](*C.struct_AVFilterLink))(unsafe.Pointer(fc.c.outputs)) for i := 0; i < fc.NbOutputs(); i++ { ls = append(ls, newFilterLinkFromC(lcs[i])) } diff --git a/format_context.go b/format_context.go index 0ef33b3..7bcc4fa 100644 --- a/format_context.go +++ b/format_context.go @@ -9,10 +9,6 @@ import ( "unsafe" ) -const ( - maxArraySize = math.MaxInt32 - 1 -) - // https://github.com/FFmpeg/FFmpeg/blob/n5.0/libavformat/avformat.h#L1202 type FormatContext struct { c *C.struct_AVFormatContext @@ -134,7 +130,7 @@ func (fc *FormatContext) StartTime() int64 { } func (fc *FormatContext) Streams() (ss []*Stream) { - scs := (*[maxArraySize](*C.struct_AVStream))(unsafe.Pointer(fc.c.streams)) + scs := (*[(math.MaxInt32 - 1) / unsafe.Sizeof((*C.struct_AVStream)(nil))](*C.struct_AVStream))(unsafe.Pointer(fc.c.streams)) for i := 0; i < fc.NbStreams(); i++ { ss = append(ss, newStreamFromC(scs[i])) }