Time to let someone else take a look at the code? Sometimes the most obvious errors just can't be seen by the writer of the code.
This. I've lost count of how many times I've been on both ends of:
Developer #1: "I've been trying to figure this bug out all day, think you could take a look?"
(30 second pause)
Developer #2: "Umm, WTF is this line here supposed to be doing? That doesn't look right."
Developer #1: "D'oh! Can't believe I missed that."
Your brain plays tricks on you. Sometimes you read what you *think* should be there, not what's *actually* there. And reading it over and over again just reinforces it.
This is also why the original developer of a piece of code should not be involved in the final verification testing of that code. You're unlikely to think of testing the corner cases you overlooked while writing the code; you didn't think of them the first time around, so you're probably not going to think of them when you test either.
Edit: If the code in question is reasonably self-contained and you don't mind posting it publicly I'm sure there are people here who would be willing to take a look (provided we're not doing your homework for you).
Edit 2: What language? If it is a compiled language try disabling compiler optimizations.
The years just pass like trains. I wave, but they don't slow down.
-- Steven Wilson