Fix some compiler warnings

The descriptor strings are dynamically allocated and owned by the
struct. The const qualifiers are a bit misleading here, and result in
warnings when trying to free the pointers again.
This commit is contained in:
Jef Driesen 2018-02-20 19:12:27 +01:00
parent ea2272d4b0
commit 96bac1de13

View File

@ -64,7 +64,7 @@ enum eon_sample {
#define EON_MAX_GROUP 16
struct type_desc {
const char *desc, *format, *mod;
char *desc, *format, *mod;
unsigned int size;
enum eon_sample type[EON_MAX_GROUP];
};
@ -290,9 +290,9 @@ static void
desc_free (struct type_desc desc[], unsigned int count)
{
for (unsigned int i = 0; i < count; ++i) {
free((void *)desc[i].desc);
free((void *)desc[i].format);
free((void *)desc[i].mod);
free(desc[i].desc);
free(desc[i].format);
free(desc[i].mod);
}
}
@ -463,8 +463,8 @@ struct sample_data {
dc_sample_callback_t callback;
void *userdata;
unsigned int time;
const char *state_type, *notify_type;
const char *warning_type, *alarm_type;
char *state_type, *notify_type;
char *warning_type, *alarm_type;
/* We gather up deco and cylinder pressure information */
int gasnr;
@ -613,7 +613,7 @@ static void sample_gas_switch_event(struct sample_data *info, unsigned short idx
*
* "enum:0=NoFly Time,1=Depth,2=Surface Time,3=..."
*/
static const char *lookup_enum(const struct type_desc *desc, unsigned char value)
static char *lookup_enum(const struct type_desc *desc, unsigned char value)
{
const char *str = desc->format;
unsigned char c;
@ -819,7 +819,7 @@ static void sample_event_alarm_value(const struct type_desc *desc, struct sample
static void sample_setpoint_type(const struct type_desc *desc, struct sample_data *info, unsigned char value)
{
dc_sample_value_t sample = {0};
const char *type = lookup_enum(desc, value);
char *type = lookup_enum(desc, value);
if (!type) {
DEBUG(info->eon->base.context, "sample_setpoint_type(%u) did not match anything in %s", value, desc->format);
@ -834,12 +834,12 @@ static void sample_setpoint_type(const struct type_desc *desc, struct sample_dat
sample.ppo2 = info->eon->cache.customsetpoint;
else {
DEBUG(info->eon->base.context, "sample_setpoint_type(%u) unknown type '%s'", value, type);
free((void *)type);
free(type);
return;
}
if (info->callback) info->callback(DC_SAMPLE_SETPOINT, sample, info->userdata);
free((void *)type);
free(type);
}
// uint32
@ -1148,7 +1148,7 @@ static int add_gas_type(suunto_eonsteel_parser_t *eon, const struct type_desc *d
{
int idx = eon->cache.ngases;
dc_tankvolume_t tankinfo = DC_TANKVOLUME_METRIC;
const char *name;
char *name;
if (idx >= MAXGASES)
return 0;
@ -1170,7 +1170,7 @@ static int add_gas_type(suunto_eonsteel_parser_t *eon, const struct type_desc *d
eon->cache.initialized |= 1 << DC_FIELD_GASMIX_COUNT;
eon->cache.initialized |= 1 << DC_FIELD_TANK_COUNT;
free((void *)name);
free(name);
return 0;
}