Thread: Access Violation using memcmp?

  1. #1
    Registered User
    Join Date
    Dec 2007
    Posts
    51

    Access Violation using memcmp?

    I get an access violation when I use memcmp... not too sure what that means, but heres the error:

    Unhandled exception at 0x1024002d in myprogram.exe: 0xC0000005: Access violation reading location 0xffffffcc.
    Code:
    char * Compare(char *searchCmd)
    {
    	searchCmd = '\xA1';
    	while (memcmp(currentPlace, searchCmd, 1) != 0)
    		currentPlace++;
    }

  2. #2
    Chinese pâté foxman's Avatar
    Join Date
    Jul 2007
    Location
    Canada
    Posts
    404
    Your stuff is pretty weird. Doesn't make a lot of sense.


    Code:
    char * Compare(char *searchCmd)
    {
    	searchCmd = '\xA1';    // (char *) = (char); This looks highly suspicious
    
    	// I would like to know what's the value of currentPlace here, and would be curious to know his type
    	// Also, your loop might read in memory who doesn't belong to your program
    	while (memcmp(currentPlace, searchCmd, 1) != 0)
    		currentPlace++;
    
    	// Your function should return a (char *). Currently, it returns nothings.
    }
    What are you trying to do ?

  3. #3
    Registered User
    Join Date
    Dec 2007
    Posts
    51
    Quote Originally Posted by foxman View Post
    Your stuff is pretty weird. Doesn't make a lot of sense.


    Code:
    char * Compare(char *searchCmd)
    {
    	searchCmd = '\xA1';    // (char *) = (char); This looks highly suspicious
    
    	// I would like to know what's the value of currentPlace here, and would be curious to know his type
    	// Also, your loop might read in memory who doesn't belong to your program
    	while (memcmp(currentPlace, searchCmd, 1) != 0)
    		currentPlace++;
    
    	// Your function should return a (char *). Currently, it returns nothings.
    }
    What are you trying to do ?
    well all im trying to do is read a byte from a global pointer to a char (called currentPlace) and seeing if it matches with the char searchCmd (so, basically seeing if the value of the byte what currentPlace is pointing to equals what the value of the byte that searchCmd points to)

    All currentPlace does is go up the memory values to see if any are equal to the value that searchCmd points to

  4. #4
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,318
    Quote Originally Posted by someprogr View Post
    well all im trying to do is read a byte from a global pointer to a char (called currentPlace) and seeing if it matches with the char searchCmd (so, basically seeing if the value of the byte what currentPlace is pointing to equals what the value of the byte that searchCmd points to)

    All currentPlace does is go up the memory values to see if any are equal to the value that searchCmd points to
    That doesn't make sense, and doesn't explain why there would be a loop, or what '\xA1' is for. Virtually all of that code is utter garbage and of no use in any working program.
    Let me rephrase the question that has been asked:

    What is 'Compare' supposed to do, from the point of view of the code that calls it? Are you attempting to reimplement strcmp or strchr?
    My homepage
    Advice: Take only as directed - If symptoms persist, please see your debugger

    Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Istream::Release access violation? [C++]
    By A10 in forum Windows Programming
    Replies: 10
    Last Post: 01-13-2009, 10:56 PM
  2. Access violation... can't figure it out...
    By Raigne in forum C++ Programming
    Replies: 7
    Last Post: 10-11-2007, 10:52 AM
  3. FtpFileFind access violation with MS VC++ 6.0
    By earth_angel in forum C++ Programming
    Replies: 3
    Last Post: 09-22-2005, 07:02 PM
  4. Help! CListCtrl access violation
    By bonkey in forum Windows Programming
    Replies: 4
    Last Post: 11-18-2003, 02:40 PM
  5. 0xC0000005: Access Violation
    By Strider in forum Windows Programming
    Replies: 3
    Last Post: 11-07-2001, 02:46 PM