Memory errors

0 views
Skip to first unread message

LANS

unread,
Dec 7, 2008, 9:53:31 PM12/7/08
to Xsera Development
#include <iostream>
#include <stdio.h>


int main () {
int messageIDLength = 63;
char *messageID[63] = {"0", "1", "2", "3", "4", "5", "6", "7", "8",
"9", "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M",
"N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z", "a",
"b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o",
"p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"};
int i;
bool goodMessage = true;
for(i = 0; i < messageIDLength; i++)
{//......................
0........9....||...................A........Z....||...................a.........z....||................
_

if( (*messageID[i] >= 48 && *messageID[i]<= 57) || (*messageID[i]
>= 65 && *messageID[i] <= 90) || (*messageID[i] >= 97 && *messageID
[i] <= 122) || (*messageID[i] == 95) )
{
}
else
{
goodMessage = false;
break;
}

}
if(goodMessage == true)
std::cout<< "true";
else {
std::cout << "false";
}
return 0;
}




Anyways, if I add a bad character into that, it succesfully spits out
"false". If there are no bad characters, it segfaults. I can't figure
it out right now, but it has something to do with the last two terms
of the array (its fine up through i=62 for a 63-length array). When I
run it through GDB with a breakpoint on the loop, it says
"EXEC_BAD_ACCESS". When I run it straight, it says "Error 10
(SIGGBUS)". Any help would be appreciated.

Thanks,
Andrew

LANS

unread,
Dec 7, 2008, 9:57:02 PM12/7/08
to Xsera Development
Oy, I just fixed it as I posted this (When you know me and my code
better, you'll realize I NEVER am able to fix my own problems until I
ask someone, then it hits me. It drives my IRL teachers nuts)

The problem was I made the array 63-length for all the allowed
characters AND a "bad" character. But there are only 62 good
characters, so it choked when the last entry wasn't defined.

Adam

unread,
Dec 7, 2008, 9:58:41 PM12/7/08
to xser...@googlegroups.com
It's alright, that happens with me too. Just ask Alastair...

Adam
Reply all
Reply to author
Forward
0 new messages