why does the int_value of the pa_json_object structure need to be declared as int64_t?

赵成义 zhaochengyi at uniontech.com
Tue Jul 9 11:22:50 UTC 2024


Hi Arun,

>Can I change "int64_t int_value;" to "int int_value;"?
>In the ./src/pulse/format.c file, the function pa_json_object_get_int
>is called multiple times, converting int64_t to int.

>./src/pulse/format.c:
>
>int pa_format_info_get_prop_int(const pa_format_info *f, const char *key, int *v) {
>  const char *str;
>  pa_json_object *o;
>
>  pa_assert(f);
>  pa_assert(key);
>  pa_assert(v);
>
>  str = pa_proplist_gets(f->plist, key);
>  if (!str)
>      return -PA_ERR_NOENTITY;
>
>  o = pa_json_parse(str);
>  if (!o) {
>      pa_log_debug("Failed to parse format info property '%s'.", key);
>      return -PA_ERR_INVALID;
>  }
>
>  if (pa_json_object_get_type(o) != PA_JSON_TYPE_INT) {
>      pa_log_debug("Format info property '%s' type is not int.", key);
>      pa_json_object_free(o);
>      return -PA_ERR_INVALID;
>  }
>
>  *v = pa_json_object_get_int(o);

I just want to avoid truncation or overflow errors caused by implicit type conversion from int64_t to int here.
If you think there is no problem with the conversion here, I will not modify it.

Thanks,
Chengyi


More information about the pulseaudio-discuss mailing list