Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
htsmsg: fix crash caused by wrong htsmsg_set_str() update, fixes #3631
  • Loading branch information
perexg committed Mar 15, 2016
1 parent f2fba6e commit f754e0c
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
20 changes: 17 additions & 3 deletions src/htsmsg.c
Expand Up @@ -417,6 +417,20 @@ htsmsg_field_set_str(htsmsg_field_t *f, const char *str)
return 0;
}

/*
*
*/
int
htsmsg_field_set_str_force(htsmsg_field_t *f, const char *str)
{
if (f->hmf_type != HMF_STR) {
htsmsg_field_data_destroy(f);
f->hmf_type = HMF_STR;
f->hmf_str = "";
}
return htsmsg_field_set_str(f, str);
}

/*
*
*/
Expand Down Expand Up @@ -781,15 +795,15 @@ htsmsg_field_get_string(htsmsg_field_t *f)
case HMF_STR:
break;
case HMF_BOOL:
htsmsg_field_set_str(f, f->hmf_bool ? "true" : "false");
htsmsg_field_set_str_force(f, f->hmf_bool ? "true" : "false");
break;
case HMF_S64:
snprintf(buf, sizeof(buf), "%"PRId64, f->hmf_s64);
htsmsg_field_set_str(f, buf);
htsmsg_field_set_str_force(f, buf);
break;
case HMF_DBL:
snprintf(buf, sizeof(buf), "%lf", f->hmf_dbl);
htsmsg_field_set_str(f, buf);
htsmsg_field_set_str_force(f, buf);
break;
}
return f->hmf_str;
Expand Down
1 change: 1 addition & 0 deletions src/htsmsg.h
Expand Up @@ -183,6 +183,7 @@ int htsmsg_set_str(htsmsg_t *msg, const char *name, const char *str);
* Update a string field
*/
int htsmsg_field_set_str(htsmsg_field_t *f, const char *str);
int htsmsg_field_set_str_force(htsmsg_field_t *f, const char *str);

/**
* Add an field where source is a list or map message.
Expand Down

0 comments on commit f754e0c

Please sign in to comment.