*
* @return Zero when successful
*/
-static int averaging_create(averaging_t * avg, int size)
+static int averaging_create(averaging_t *avg, int size)
{
- int a;
-
- avg->ring_buffer = (long int *) malloc(size * sizeof(*avg));
+ avg->ring_buffer = calloc ((size_t) size, sizeof (*avg));
if (avg->ring_buffer == NULL)
{
ERROR ("barometer: averaging_create - ring buffer allocation of size %d failed",
return -1;
}
- for (a=0; a<size; ++a)
- {
- avg->ring_buffer[a] = 0L;
- }
-
avg->ring_buffer_size = size;
avg->ring_buffer_sum = 0L;
avg->ring_buffer_head = 0;