Is there any reason why maxCheckStartPosition
is designed to be a pointer here?
This variable is used as a search limit and I don't see any reason why it would get changed during Open().
And also I grepped the whole library and I cannot see any Archive
takes the ownership / changes that variable.
This design decision really looks strange to me.
p7zip_9.20.1/CPP/7zip/Archive/IArchive.h:
STDMETHOD(Open)(IInStream *stream, const UInt64 *maxCheckStartPosition, IArchiveOpenCallback *openArchiveCallback) x; \
I don't see any reason why it would get changed during Open().
Beyond not seeing any reason why, contractually it would be undefined behavior if it did. It's labeled const
(and written like that, it's the thing pointed to that's const... not the pointer).
Is there any reason why maxCheckStartPosition is designed to be a pointer here?
Without knowing the specific motivations:
Being a pointer allows for NULL, to be optional while still having the full range of a UInt64 available if non-NULL. This prevents needing to pick a "magic number" meaning no maxCheckStartPosition.
On a 32-bit architecture, a pointer would mean 32-bits in the passed parameter on the stack vs. 64-bits...for which there could be better-or-worse reasons. Some might be trying to micro-optimize the bytes pushed, other times perhaps it may be another weird reason why something you're interfacing with only knows how to push pointer-sized-things to the stack (an FFI-like thing, or something).