That's why it's recommended to use size_t for passing sizes of buffers. It's unlikely to get overflow with it. In this particular case input buffer needs to have size larger than half of address space in order to trigger overflow, which isn't possible (64-bit systems usually have only 48 bits of actual address space, 32-bit systems don't allow allocating so large blocks).
> That's why it's recommended to use size_t for passing sizes of buffers.
I have always been told it is a bad idea to use unsigned integers in your interfaces. Why? An accidental negative (signed) value will be cast into an enormous unsigned value. For example, if you look at the vast majority of the Win32 API, inputs are normally signed integers. They rarely use unsigned integers.never say never :)
Not everybody recommends size_t. There's a sizeable community of people absolutely convinced most integers, including length and capacity integers, should be signed. And they stick to their guns even for C and C++. They have some very compelling logical arguments on their side, but IMO in languages like C and C++ they're just fatally unrealistic.