-1

I am using memcmp for comparing the char pointer to empty string as:

if((0 == memcmp("", pcNewBeginPtr, 1))){
    // do some stuff
}

I am able to compare this, but while running through Valgrind, I get this error message:

Invalid read of size 1 at this line.
alexwlchan
  • 5,699
  • 7
  • 38
  • 49
Anuja
  • 21
  • 2

1 Answers1

4

Amazingly, you could read the docs to see what the "invalid read" message means. E.g. you don't legitimately have read access to the memory at pcNewBeginPtr: it's already been freed, wasn't validly initialised to point at a char buffer, points to a local variable in a scope that's already exited etc....

You might read some other questions: e.g. here.

Community
  • 1
  • 1
Tony Delroy
  • 102,968
  • 15
  • 177
  • 252