title: Valgrind C: Argument of function has a fishy (possibly negative) value
body: <p>I'm getting this error message in multiple places in my code where I call malloc or realloc. Here is one example.</p>
  
  <pre><code>void* reallocate_array(void* ptr, size_t size)
  {
      return realloc(ptr,size)
  }
  </code></pre>
  
  <p>EDIT2: Looks like the problem is in the test case. I can't modify this</p>
  
  <pre><code>char* reallocated = (char*) reallocate_array(allocated,-1)
  </code></pre>
  
  <p>Here is my solution which got rid of the fishy value error</p>
  
  <pre><code>if((int)size &lt; 0)
  {
      return NULL;
  }
  </code></pre>
  
  <p>I was under the impression that size_t was an unsigned integer, meaning it could never be negative. Could this be bug in Valgrind or is it warning me of a possible wraparound? </p>
  
  <p>EDIT: Valgrind output</p>
  
  <pre><code>==20841== 1 errors in context 1 of 3:
  ==20841== Argument 'size' of function realloc has a fishy (possibly negative) value: -1
  ==20841==    at 0x4C2BB78: realloc (vg_replace_malloc.c:785)
  ==20841==    by 0x4057B1: reallocate_array (allocation.c:24)
  ==20841==    by 0x402A8A: reallocate_NegativeBytes_Test::TestBody() (tests.cpp:56)
  </code></pre>