SA-MP Forums Archive
Foreach possible bug? - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Foreach possible bug? (/showthread.php?tid=422435)



Foreach possible bug? - Misiur - 13.03.2013

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)?


Re: Foreach possible bug? - Stylock - 13.03.2013

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.


Re: Foreach possible bug? - Scenario - 13.03.2013

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>;



Re: Foreach possible bug? - Stylock - 13.03.2013

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



Re: Foreach possible bug? - Scenario - 13.03.2013

It worked for me, YJIET...


Re: Foreach possible bug? - Misiur - 13.03.2013

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


Re: Foreach possible bug? - Stylock - 13.03.2013

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