Foreach possible bug?
#1

pawn Код:
#include <a_samp>
#include <foreach>

#define A       10
#define B       5
new Iterator:Foo[A]<B>;

main() {
    Iter_Init(Foo);
   
    for(new i = 0; i != A; ++i) {
        for(new j = 0; j != B; ++j) {
            Iter_Add(Foo[i], j);
        }
    }
}
Am I missing something, or it really is a bug when there is less slots than array elements (accessing over upper boundary)?
Reply
#2

Weird stuff, I just looked at the foreach include and found a macro that isn't mentioned in the foreach thread. You're probably suppose to use IteratorArray when you declare multi-dimensional iterators. I think it might be a mistake on ******'s part, so you should go and report this in the foreach thread.
Reply
#3

I noticed a similar issue in my own code. When defining the iterator, I just add 1 to the numbers in the array.

So for example, doing this:

pawn Код:
new Iterator:PlayerVehicles[MAX_PLAYERS+1]<MAX_VEHICLES+1>;
Reply
#4

@RealCop228 I don't think that fixes the problem. You should use:
Код:
new IteratorArray:PlayerVehicles[MAX_PLAYERS]<MAX_VEHICLES>;
Reply
#5

It worked for me, YJIET...
Reply
#6

Yep, found it in source as well. Works just fine (I mean the IteratorArray "tag")
Reply
#7

Okay, it looks like the "Array index out of bounds" error occurs only when the first dimension is larger than the second dimension.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)