| View previous topic :: View next topic |
| Author |
Message |
oib111 I post too much
Reputation: 0
Joined: 02 Apr 2007 Posts: 2947 Location: you wanna know why?
|
Posted: Fri Mar 13, 2009 8:16 pm Post subject: Access Violation |
|
|
I'm trying to compile some code to parse through some command line arguments and I keep getting an access violation. My code is:
| Code: |
Commands = (char*)HeapAlloc(GetProcessHeap(), 0, sizeof(CHAR)*(strlen(lpCmdLine)+1));
if(Commands != NULL) {
strcpy(Commands, lpCmdLine);
}
char *c = new char[1]; //the new char[1] fixed a previous error
int i = 0;
int j = 0;
do {
c[1] = Commands[i]; //access violation on this line
Open[j] = c[1];
i++;
j++;
} while(strcmp(c, " ") != 0);
do {
c[1] = Commands[i];
RecvUserName[j] = c[1];
i++;
j++;
} while(strcmp(c, " ") != 0);
i += 1;
j = 0;
do {
c[1] = Commands[i];
RecvFileName[j] = c[1];
i++;
j++;
} while(strcmp(c, '\0') != 0);
delete [] c;
|
The access violation is:
| Quote: |
'IBIM Transfer.exe': Loaded 'C:\Documents and Settings\OIB\My Documents\Visual Studio 2008\Projects\IBIM Transfer\Debug\IBIM Transfer.exe', Symbols loaded.
'IBIM Transfer.exe': Loaded 'C:\WINDOWS\system32\ntdll.dll'
'IBIM Transfer.exe': Loaded 'C:\WINDOWS\system32\kernel32.dll'
'IBIM Transfer.exe': Loaded 'C:\WINDOWS\system32\user32.dll'
'IBIM Transfer.exe': Loaded 'C:\WINDOWS\system32\gdi32.dll'
'IBIM Transfer.exe': Loaded 'C:\WINDOWS\system32\comdlg32.dll'
'IBIM Transfer.exe': Loaded 'C:\WINDOWS\system32\advapi32.dll'
'IBIM Transfer.exe': Loaded 'C:\WINDOWS\system32\rpcrt4.dll'
'IBIM Transfer.exe': Loaded 'C:\WINDOWS\system32\secur32.dll'
'IBIM Transfer.exe': Loaded 'C:\WINDOWS\WinSxS\x86_Microsoft.Windows.Common-Controls_6595b64144ccf1df_6.0.2600.5512_x-ww_35d4ce83\comctl32.dll'
'IBIM Transfer.exe': Loaded 'C:\WINDOWS\system32\msvcrt.dll'
'IBIM Transfer.exe': Loaded 'C:\WINDOWS\system32\shlwapi.dll'
'IBIM Transfer.exe': Loaded 'C:\WINDOWS\system32\shell32.dll'
'IBIM Transfer.exe': Loaded 'C:\WINDOWS\system32\ws2_32.dll'
'IBIM Transfer.exe': Loaded 'C:\WINDOWS\system32\ws2help.dll'
'IBIM Transfer.exe': Loaded 'C:\WINDOWS\system32\shimeng.dll'
'IBIM Transfer.exe': Loaded 'C:\WINDOWS\system32\imm32.dll'
'IBIM Transfer.exe': Loaded 'C:\WINDOWS\system32\wbsys.dll'
First-chance exception at 0x7c91b1fa in IBIM Transfer.exe: 0xC0000005: Access violation writing location 0x00000010.
'IBIM Transfer.exe': Unloaded 'C:\WINDOWS\system32\wbsys.dll'
'IBIM Transfer.exe': Unloaded 'C:\WINDOWS\system32\shimeng.dll'
First-chance exception at 0x00416cb2 in IBIM Transfer.exe: 0xC0000005: Access violation reading location 0x000000b2.
Unhandled exception at 0x00416cb2 in IBIM Transfer.exe: 0xC0000005: Access violation reading location 0x000000b2.
|
_________________
| 8D wrote: |
cigs dont make people high, which weed does, which causes them to do bad stuff. like killing |
|
|
| Back to top |
|
 |
Zand Master Cheater
Reputation: 0
Joined: 21 Jul 2006 Posts: 424
|
Posted: Fri Mar 13, 2009 9:09 pm Post subject: |
|
|
Probably that.
|
|
| Back to top |
|
 |
oib111 I post too much
Reputation: 0
Joined: 02 Apr 2007 Posts: 2947 Location: you wanna know why?
|
Posted: Fri Mar 13, 2009 10:07 pm Post subject: |
|
|
Changed to c[0] and I'm still getting access violations.
_________________
| 8D wrote: |
cigs dont make people high, which weed does, which causes them to do bad stuff. like killing |
|
|
| Back to top |
|
 |
Zand Master Cheater
Reputation: 0
Joined: 21 Jul 2006 Posts: 424
|
Posted: Sat Mar 14, 2009 12:02 am Post subject: |
|
|
| Post your full code + maybe think about using tokens.
|
|
| Back to top |
|
 |
Noz3001 I'm a spammer
Reputation: 26
Joined: 29 May 2006 Posts: 6220 Location: /dev/null
|
Posted: Sat Mar 14, 2009 3:07 am Post subject: |
|
|
| Code: | | char *c = new char[128]; |
|
|
| Back to top |
|
 |
oib111 I post too much
Reputation: 0
Joined: 02 Apr 2007 Posts: 2947 Location: you wanna know why?
|
Posted: Sat Mar 14, 2009 10:31 am Post subject: |
|
|
Sorry noz that didn't help.
_________________
| 8D wrote: |
cigs dont make people high, which weed does, which causes them to do bad stuff. like killing |
|
|
| Back to top |
|
 |
Zand Master Cheater
Reputation: 0
Joined: 21 Jul 2006 Posts: 424
|
Posted: Sat Mar 14, 2009 10:49 am Post subject: |
|
|
| Code: | Commands = (char*)HeapAlloc(GetProcessHeap(), 0, strlen(lpCmdLine)+1);
if(Commands) {
strcpy(Commands, lpCmdLine);
int i = 0;
int j = 0;
for( ; ! isspace( Commands[i] ); i++, j++ )
{
Open[j] = Commands[i];
}
for( ; ! isspace( Commands[i] ); i++, j++ )
{
RecvUserName[j] = Commands[i]; // I R DINK PROBLEMZ HERE
}
for( i += 1, j = 0; Commands[i] != '\0'; i++, j++ )
{
RecvFileName[j] = Commands[i]; I R DINK PROBLEMZ HERE
}
} |
|
|
| Back to top |
|
 |
oib111 I post too much
Reputation: 0
Joined: 02 Apr 2007 Posts: 2947 Location: you wanna know why?
|
Posted: Sat Mar 14, 2009 11:29 am Post subject: |
|
|
Zand with your code I still get an access violation. Except its on the line:
| Code: |
for(;!isspace(Commands[i]); i++, j++ )
|
Access violation:
| Quote: |
'IBIM Transfer.exe': Loaded 'C:\Documents and Settings\OIB\My Documents\Visual Studio 2008\Projects\IBIM Transfer\Debug\IBIM Transfer.exe', Symbols loaded.
'IBIM Transfer.exe': Loaded 'C:\WINDOWS\system32\ntdll.dll'
'IBIM Transfer.exe': Loaded 'C:\WINDOWS\system32\kernel32.dll'
'IBIM Transfer.exe': Loaded 'C:\WINDOWS\system32\user32.dll'
'IBIM Transfer.exe': Loaded 'C:\WINDOWS\system32\gdi32.dll'
'IBIM Transfer.exe': Loaded 'C:\WINDOWS\system32\comdlg32.dll'
'IBIM Transfer.exe': Loaded 'C:\WINDOWS\system32\advapi32.dll'
'IBIM Transfer.exe': Loaded 'C:\WINDOWS\system32\rpcrt4.dll'
'IBIM Transfer.exe': Loaded 'C:\WINDOWS\system32\secur32.dll'
'IBIM Transfer.exe': Loaded 'C:\WINDOWS\WinSxS\x86_Microsoft.Windows.Common-Controls_6595b64144ccf1df_6.0.2600.5512_x-ww_35d4ce83\comctl32.dll'
'IBIM Transfer.exe': Loaded 'C:\WINDOWS\system32\msvcrt.dll'
'IBIM Transfer.exe': Loaded 'C:\WINDOWS\system32\shlwapi.dll'
'IBIM Transfer.exe': Loaded 'C:\WINDOWS\system32\shell32.dll'
'IBIM Transfer.exe': Loaded 'C:\WINDOWS\system32\ws2_32.dll'
'IBIM Transfer.exe': Loaded 'C:\WINDOWS\system32\ws2help.dll'
'IBIM Transfer.exe': Loaded 'C:\WINDOWS\system32\shimeng.dll'
'IBIM Transfer.exe': Loaded 'C:\WINDOWS\system32\imm32.dll'
'IBIM Transfer.exe': Loaded 'C:\WINDOWS\system32\wbsys.dll', Binary was not built with debug information.
First-chance exception at 0x7c91b1fa in IBIM Transfer.exe: 0xC0000005: Access violation writing location 0x00000010.
'IBIM Transfer.exe': Unloaded 'C:\WINDOWS\system32\wbsys.dll'
'IBIM Transfer.exe': Unloaded 'C:\WINDOWS\system32\shimeng.dll'
First-chance exception at 0x00416caa in IBIM Transfer.exe: 0xC0000005: Access violation reading location 0x000000b2.
Unhandled exception at 0x00416caa in IBIM Transfer.exe: 0xC0000005: Access violation reading location 0x000000b2.
|
_________________
| 8D wrote: |
cigs dont make people high, which weed does, which causes them to do bad stuff. like killing |
|
|
| Back to top |
|
 |
Flyte Peanuts!!!!
Reputation: 6
Joined: 19 Apr 2006 Posts: 1887 Location: Canada
|
Posted: Sat Mar 14, 2009 12:18 pm Post subject: |
|
|
| For the love of god, tokenize the string first using strtok() or something.
|
|
| Back to top |
|
 |
oib111 I post too much
Reputation: 0
Joined: 02 Apr 2007 Posts: 2947 Location: you wanna know why?
|
Posted: Sat Mar 14, 2009 1:38 pm Post subject: |
|
|
Thanks Flyte. strtok worked.
_________________
| 8D wrote: |
cigs dont make people high, which weed does, which causes them to do bad stuff. like killing |
|
|
| Back to top |
|
 |
|