|
From: David C. <dcc...@ac...> - 2015-03-11 01:30:42
|
On 3/10/2015 5:21 PM, David C. Rankin wrote:
> All,
>
> I have an issue with valgrind-3.8.1 (openSuSE 13.1 x86_64) reporting the error:
>
> Conditional jump or move depends on uninitialised value(s)
>
> The error stems from reallocation of a new block of memory. The error is
> triggered when iterating over the reallocated pointer array into the reallocated
> block, despite explicitly setting/initializing values of the new pointers to 0
> with memset (equivalent to the original allocation with calloc).
Not quite. calloc() gets the size of the object being cleared in
addition to the number of objects, while memset() gets only the size in
bytes. You need to multiply cmax by sizeof(*slines), as you did for the
realloc() call. (Of course, "slines + cmax" on the same line of code is
pointer arithmetic, so it automatically performs this multiplication. C
does have its warts.)
--
David Chapman dcc...@ac...
Chapman Consulting -- San Jose, CA
Software Development Done Right.
www.chapman-consulting-sj.com
|