Consider a custom data structure that represents a 3 byte unsigned integer. In little-endian assembly, one can simply load 4 bytes into a register via a dword pointer and, for instance, perform addition on 3 byte integers, store the lower word at memory address 'x', shift the result right by 16 and store the lower byte at memory address x + 2. The slower, non undefined behavior version of the load would be to first zero out register 'a', load the lower word into register 'a', load the third byte into register 'b', shift 'b' left by 16 and OR register 'a' and 'b' into another register.
So now let's assume that a given 3 byte integer is "right at the edge" of the program space or data segment; intuitively, you'd access memory illegally by dereferencing the integer's address as a dword, wouldn't you? Or more generally: when does a memory access violation occur when reading memory; is it only the base address that's being considered or is it (baseAddress + lengthInBytes)? Having searched for an answer for weeks, I haven't come across an answer yet, which is why I'm asking the community...