The Blizzard API for gearsets is busted (you have a comment implying as much), but not in the way that your indexing fixes, or at least not on the characters I tested.
The problem is that Blizzard doesn't compress the array that they save gearsets into after you delete one, and it always adds a new gearset to the first empty index. You can recreate this test by doing the following on a new character:
i. Create gearsets A, B, C. The gearset array will be a[0] = A, a[1] = B, a[2] = C
ii. Delete gearset B. The gearset array will be a[0] = A, a[1]= null, a[2] = C
iii. Create gearset D. The gearset array will be a[0] = A, a[1] = D, a[2] = C
In practice, this means that a) the wacky local minimum and local maximums don't do the right thing and aren't necessary [anymore?], and b) a for loop that goes from 0 to getNumEquipmentSets() is not guaranteed to find all sets. In Step (ii) above, for example, numSets will be 2, and the for loop will only check a[0] and a[1], only finding gearset A. Instead, you need to iterate over the GetEquipmentSetInfo(i) array starting at i = 0 and ending once you've found the same number of gearsets that getNumEquipmentSets() returns. I did this with separate variables for 'i' and 'found sets' in a while loop.