@Duoas: your solution doesn't have the bug. I was not saying the lookup approach is generally bad, but by trying to make it short and clever (ok, the original code was long, I know), blackcoder introduced a very subtle bug into it. And finally the given code was worse than the original one. which was kinda funny, given the forum experience of blackcoder ;)
Many real vulnerabilities in programs are such small "almost-not-a-bug" things - they seem to be correct under some assumptions. But hackers like to attack in such a way to break these assumptions, thus breaking the code relying on them. Making the program correctness dependend on the codepage is one of such bugs waiting to happen. I've seen some Linux programs crashing when I changed the locale to UTF, so I've pointed this out. Be careful, and know what you are doing.
That, and C++ requires certain characteristics to hold true for the character set -- such as requiring that the set of English letters with the same letter case be sequentially arranged in the character table. Sorry EBCDIC. |
Are you saying there are platforms where the C++ standard is not 100% implementable? Even worse: that there are platforms where C++ is not 100% implementable and Java is? (AS/400 for example that uses EBCDIC).
Are you kidding? Don't waste my time or memory
|
Sorry, but your corrected, flexible lookup is probably wasting much more cycles than the hashmap. :D And don't be kidding with the memory consumption. You saved like 50 bytes? Wow! You are an amazing optimizer! 50 bytes is nothing even on the most scarce in memory embedded systems.
BTW: Nice try with that lookup with STL, but it is still an ugly piece of code. That magic constants defending the end of the arrays are another possible problem waiting to happen (yes, someone removes a letter and voila, you have an off-by-one bug). I know I'm possibly niggling, but such small things too often show in Secunia reports. The original poster's code was still better and less ugly than that (ok, if was long, but anyway, what is the problem if something is long?)
Oh, BTW, when have telephone keypads ever had letters other than "A-Z" on them? (Hint: never.)
|
This is irrelevant to the problem I posted. This is like defending the old telnet buffer overflow vulnerability by saying "when does a remote terminal ever allow for more than 80 characters?"