CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7
  1. #1
    Join Date
    Aug 1999
    Location
    Germany
    Posts
    2,338

    Error in str_misaligned in application in Windows 7

    Hello!

    I have developed a big application on Windows XP. Now I changed my OS to Windows 7 with a new computer.

    I just copied the whole project and the settings of my Visual Studio 2005, and the compiling went well. But starting the application, I get an error


    Unhandled exception at 0x5e8bb10c (msvcr80d.dll) in MyApp.exe: 0xC0000005: Access violation reading location 0x000000fe

    File strlen.asm:
    Code:
    str_misaligned:
            ; simple byte loop until string is aligned
            mov     al,byte ptr [ecx] <- Error
            add     ecx,1
            test    al,al
            je      short byte_3
            test    ecx,3
            jne     short str_misaligned
    while just concate 2 strings:

    CString a = table+"."+fields[nField].name;


    Uh The same code works fine in Windows XP. Any idea what I could do? I set WINVER=0x0501 in the compiling-settings (because the target-computers are mostly XP) and started Visual Studio as administrator.
    Last edited by martho; September 14th, 2010 at 10:10 AM.

  2. #2
    Lindley is offline Elite Member Power Poster
    Join Date
    Oct 2007
    Location
    Seattle, WA
    Posts
    10,895

    Re: Error in str_misaligned in application in Windows 7

    Presumably this was a bug all along and the change to Windows 7 only exposed it. You should be glad; undetected bugs can have nasty and confusing consequences down the road.

    Of course, it's impossible to say what the problem is without seeing more code around that location.

  3. #3
    Join Date
    Oct 2009
    Posts
    577

    Smile Re: Error in str_misaligned in application in Windows 7

    Quote Originally Posted by martho View Post
    Hello!

    I have developed a big application on Windows XP. Now I changed my OS to Windows 7 with a new computer.

    I just copied the whole project and the settings of my Visual Studio 2005, and the compiling went well. But starting the application, I get an error


    Unhandled exception at 0x5e8bb10c (msvcr80d.dll) in MyApp.exe: 0xC0000005: Access violation reading location 0x000000fe

    File strlen.asm:
    Code:
    str_misaligned:
            ; simple byte loop until string is aligned
            mov     al,byte ptr [ecx] <- Error
            add     ecx,1
            test    al,al
            je      short byte_3
            test    ecx,3
            jne     short str_misaligned
    while just concate 2 strings:

    CString a = table+"."+fields[nField].name;


    Uh The same code works fine in Windows XP. Any idea what I could do? I set WINVER=0x0501 in the compiling-settings (because the target-computers are mostly XP) and started Visual Studio as administrator.
    It is actually 3 strings you want to concatenate. Can you tell what type the table and fields[nField].name is? And is nField a valid index or may it point beyond array boundaries?

  4. #4
    Join Date
    Oct 2009
    Posts
    577

    Smile Re: Error in str_misaligned in application in Windows 7

    0xC0000005: Access violation reading location 0x000000fe

    The 0x0x000000fe is too low to be a valid pointer (address). It looks as if a pointer to a struct/class is NULL and you were accessing a member at offset 0xfe from begin of the class.

    Is it possible that 'fields' is a NULL pointer?

  5. #5
    Join Date
    Apr 1999
    Posts
    27,449

    Re: Error in str_misaligned in application in Windows 7

    Quote Originally Posted by martho View Post
    Uh The same code works fine in Windows XP. Any idea what I could do?
    Yes. Fix your code.

    It doesn't matter if it ran fine in XP, because the code wasn't really running "fine" at all. There was always a bug, and as Lindley pointed out, the bug was exposed in Windows 7.

    When you write a C++ application, and the application overwrites the boundaries of an array, misuses pointers, or similar faulty coding, nothing guarantees that the app will fail. That's the nature of C++ applications -- fauly coding doesn't mean you will see the fault when you run the program. Lucky for you, you now see that there is a problem.

    Regards,

    Paul McKenzie
    Last edited by Paul McKenzie; September 14th, 2010 at 06:42 PM.

  6. #6
    Join Date
    Aug 1999
    Location
    Germany
    Posts
    2,338

    Re: Error in str_misaligned in application in Windows 7

    Thanks for your replys that put me into the right direction.

    The code was okay, but a mysql-dll, which delivers the field-array, returns some null-pointers in Windows 7. Perhaps a mismatch of lib/dll (wrong pathes or a wrong version). I will check this further.

  7. #7
    Join Date
    Apr 1999
    Posts
    27,449

    Re: Error in str_misaligned in application in Windows 7

    Quote Originally Posted by martho View Post
    Thanks for your replys that put me into the right direction.

    The code was okay, but a mysql-dll, which delivers the field-array, returns some null-pointers in Windows 7. Perhaps a mismatch of lib/dll (wrong pathes or a wrong version). I will check this further.
    Still, the crash should not have occurred if you had proper error checking in the application.

    You should be checking all of your return values to make sure they are valid before using them. If a function states it returns certain values, then your app should be checking the return values.

    Regards,

    Paul McKenzie

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured