We had an unusual error come up on one of our sites where a promotional ad group was only showing 2 ads when it should have been displaying 3. It only happened in IE 6 and took us a while to figure out so I figured I’d share the information we discovered. If you look at the code below and instantly know what is incorrect and why, well my hat is off to you. For those of you like me who didn’t readily see what was wrong and why, put on your Henschel Deerstalker hat and put some tobacco in your pipe. This is pretty cool.
function doSomething(){
...
for(i=1;i<somevalue ;i++) {
alert(arrayVar[i]);
}
...
}
Internet Exploder 6 was reporting the variable “i” as going from 1, to 3 and then exiting the loop. No where in the code was there an i++ or any kind of increment that should have increased it’s value. However, there it was, being increased for no apparent reason. I found a missing “;” and a even tried redoing a few calls from $ mootool id calls to getByElementId with no luck. A co-worker and myself then had an idea that possibly the variable was being shared and because it wasn’t being declared that it was actually the same pointer in memory as another similar named variable “i”. We changed the code to include the declaration as below and tada, working code without shared memory:
function doSomething(){
...
for(var i=1;i<somevalue ;i++) {
alert(arrayVar[i]);
}
...
}
As someone who’s constantly thinking about security, I wonder what kind of memory hacks you could put into place with this little tid-bit of knowledge. Obviously no-one should be using IE 6, but for those “wonderful people” who are, what kind of trouble can they get into?
« Bookmarks for June 30th through July 6th Bookmarks for July 8th through July 14th »
