Friday 15 April 2011

c - test if strstr return a valid pointer -


I am trying to use the strstr function like this:

  const char * PInicio = Strust (original, bite); If (pInicio! = NULL) ...   

Unlike expected, when I perform "if" the compiler throws an access status violation exception. It happens every time, I try to get some key words that do not exist from the string.

The call stack is:

  ntdll.dll! 779315de () [OS Quadros Abaixo podem estar estretos E / ou ausentes, Nenhum Sambolo Foi Carregado ntdll.dll] ntdll.dll 779315de () ntdll.dll para 7792014e ()>! ! Msvcr100d.dll _output_l (_iobuf * stream, const char * format, localeinfo_struct * plocinfo, char * argptr) Linha 2361 + 0xA bytes C ++ cccccccc ()   

was produced: Exceçà £ O Primeira chance them 0x0f8620a7 (msvcr100d.dll) No TestesApp.exe: 0xc0000005: Violaçà £ ode acesso Ao ler o Local 0x00000001 Exceçà £ o sem-tratamento them any TestesApp.exe 0x779315de: 0xc0000005: Violaçà £ ode acesso Ao ler o Local 0x00000001 Before the exception, the variable values ​​were:

  1. chave: 0x00196f64 "$ GNGSA" type: char *
  2. Origem: 0x00196840 "$ GPRMC, 0,00,651.082, 191,210 ,,,,,,,, ,,,, * 4F $ GPGGA, 000652.0 9 1 ,,,,,,,,,, M, 0.0, M, , 0000 * 5F $ GPGSA, A, 1 ,,,,,,,,,,,,,,, 1 e "type: const char *
  3. pInicio: 0x00000000 illegal & gt; Type: const char *

    The linker is the command line:

      / OUT: "c: \ user \ lindro \ document \ visual studio 2010 \ projects \ TestesApp \ debug \ TestesApp.exe "/ INCREMENTAL / Nologo" kernel32.lib "" user32.lib "" gdi32.lib "" winspool.lib "" comdlg32.lib "" advapi32.lib "" shell32.lib "" ole32 lib "" oleaut32.lib "" uuid.lib "" odbc32.lib "" odbccp32.lib "/ MANIFEST /ManifestFile:"Debug\TestesApp.exe.intermediate.manifest" / ALLOWISOLATION / MANIFESTUAC: "class = 'asInvoker' uiAccess = 'False' / debug / PDB: "C: \ Users \ Leandro \ Documents \ Visual Studio 2010 \ Projects \ TestesApp \ Debug \ TestesApp.pdb" / Subsystem: Console / Pig Eedi: "C: \ Users \ Leandro \ Documents \ Visual Studio 2010 \ Projects \ TestesApp \ Debug \ TestesApp.pgd" / TLBID: 1 / DYNAMICBASE / NXCOMPAT / MACHINE: X86 / ERRORREPORT: queue   

    There is also a C / C + command line

      / zi / Nologo / W3 / WX- / OD draft / Oy-/ D "WIN32" / D "_DEBUG" / D "_CONSOLE" / D "_UNICODE" / D "Unicode" / GM / Iacssi / RTC 1 / GS / fp: precise / Jesse: Wchar_t / Zc: ForScope /Fp"DebugTestesAppkpch "/ FA" debug \ "/ Fo" Debug \ "/Fd"Debug\vc100.pdb" / Goals Difference / analyze- / errorReport: Queue   

    After this, I want to test the pointer Try if it is clear that it is my problem, how to solve it?

    Best regards!

    Your bug can not duplicate what I've tried here:

     < Code> int main (int argc, char ** argv) {char * chave = "$ GNGSA"; Constant four * origem = "$ GPRMC, 000651.082, 191,210 ,,,,,,, ,,, n * 4F $ GPGGA, 000652.0 9 1 ,,,,,,,,,, m, 0.0, m ,,,, 0000 * 5 F $ GPGSA, A, 1 ,,,,,,,,,,,,,,, 1E "; Const char * pInicio = strstr (original, bite); If (PINCIO! = Null) {printf ("got it \ n"); } Return 0; }   

    This Visual Studio 2010 compile and runs without error. It does not match in any way. I'm open to making instructions for making bugs to adjust it.

    - Edit -

    Set the compiler command line to: / ZI / nologo / W3 / WX- / OD / Oy- / D "WIN32" / D " _DEBUG "/ D" _CONSOLE "/ D" _UNICODE "/ D" Unicode "/ g / EHsc / RTCl / GS / fp: precise / Zc: wchar_t / Zc: forScope /Fp"Debug\odt.pch" / FA " Debug \ "/ fo" debug \ "/Fd"Debug\vc100.pdb" / Goals difference / analysis- / errorReport: line

    linker command line: / OUT: "E: \ code \ odt" \ Debug \ odt.exe "/ INCREMENTAL / Nologo" kernel32.lib "" user32.lib "" gdi32.lib "" winspool.lib "" comdlg32.lib "" advapi32.lib "" shell32.lib "" ole32.lib "" Oleaut32.lib "" uuid.lib "" odbc32.lib "" odbccp32.lib "/ MANIFEST /ManifestFile:"Debugoodt.exe.intermediate.manifest" / ALLOWISOLATION / MANIFESTUAC: "level = 'a SInvoker 'uiAccess =' ​​false '"/ debug /PDB:"E:\code\odt\Debug.odt.pdb" / subsystem: console / pgd: "e: \ code \ odt \ debug \ odt.pgd" / TLBID : 1 / DYNAMICBASE / NXCOMPAT / Machine: X86 / ERRORREPORT: Queue

    Even with both the command line basically the same, I'm still getting no error. I do not know what to say, sorry.

No comments:

Post a Comment