Changeset 33b8d024 in mainline for uspace/srv/audio/hound/audio_data.c


Ignore:
Timestamp:
2018-01-16T20:38:46Z (7 years ago)
Author:
Jiří Zárevúcky <zarevucky.jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
2467b41
Parents:
d39c46e0
Message:

Remove const qualifier from the argument of free() and realloc(),
as well as in numerous other variables that hold ownership of memory.

By convention, a pointer that holds ownership is _never_ qualified by const.
This is reflected in the standard type signature of free() and realloc().
Allowing const pointers to hold ownership may seem superficially convenient,
but is actually quite confusing to experienced C programmers.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/srv/audio/hound/audio_data.c

    rd39c46e0 r33b8d024  
    3636#include <macros.h>
    3737#include <stdlib.h>
     38#include <str.h>
    3839
    3940#include "audio_data.h"
     
    5051    pcm_format_t format)
    5152{
    52         audio_data_t *adata = malloc(sizeof(audio_data_t));
     53        audio_data_t *adata = malloc(sizeof(audio_data_t) + size);
    5354        if (adata) {
    5455                unsigned overflow = size % pcm_format_frame_size(&format);
     
    5657                        log_warning("Data not a multiple of frame size, "
    5758                            "clipping.");
    58 
    59                 adata->data = data;
     59                uint8_t *d = ((uint8_t *)adata) + offsetof(audio_data_t, data);
     60                memcpy(d, data, size);
    6061                adata->size = size - overflow;
    6162                adata->format = format;
     
    8687        atomic_count_t refc = atomic_predec(&adata->refcount);
    8788        if (refc == 0) {
    88                 free(adata->data);
    8989                free(adata);
    9090        }
Note: See TracChangeset for help on using the changeset viewer.