POV-Ray : Newsgroups : povray.off-topic : update, updates, updates : Re: update, updates, updates Server Time
29 Jul 2024 02:19:41 EDT (-0400)
  Re: update, updates, updates  
From: Warp
Date: 18 Jan 2013 13:30:05
Message: <50f994ad@news.povray.org>
clipka <ano### [at] anonymousorg> wrote:
> So take an array with a limited size, an "int" as an index into that 
> array, a check whether that index into that array is smaller than the 
> array's size - and you have the recipe for a stack overflow or similar 
> (unless you also remember to check whether the index is non-negative).

There's no index value that *could* be smaller than MIN_INT, so you would
have a bug certainly (the program wrongly thinks that all indices are
outside the array), but still no out-of-bounds access.

Even if the array size is (interpreted as) something larger than MIN_INT,
thus allowing for indices that are smaller than it, it would still bug
but not access out of the array (because negative indices "wrap around"
when they are converted to memory offsets, ending up at the same place
as the unsigned index with the same bit pattern.)

The only situation that I can think of where an out-of-bounds access will
probably happen is if pointers (and thus array indices) are 64-bit but
the array size is wrongly a signed (32-bit) int. It then gets expanded
to 64-bit when indexing the array, and ends up truly at negative addresses
(from the array's start.)

-- 
                                                          - Warp


Post a reply to this message

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.