From: Gerhard Sittig Date: Sat, 23 Apr 2022 19:31:06 +0000 (+0200) Subject: parsers: use proper conversion routine for PD option data types X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=e8e8b5e1a09563b66e9ef6d475b3c735c8fdc910;p=sigrok-cli.git parsers: use proper conversion routine for PD option data types The generic_arg_to_opt() routine converted text input to protocol decoder option values, but might have lost significant information. Use a signed conversion routine for the int32 data, use a long long routine for uint64 data. This shall unbreak negative values (like UART packet separators), and improve compatibility with 32bit targets (like for large sample numbers or high frequency values). --- diff --git a/parsers.c b/parsers.c index d92218f..c1ab9bd 100644 --- a/parsers.c +++ b/parsers.c @@ -444,11 +444,11 @@ GHashTable *generic_arg_to_opt(const struct sr_option **opts, GHashTable *genarg g_hash_table_insert(hash, g_strdup(opts[i]->id), g_variant_ref_sink(gvar)); } else if (g_variant_is_of_type(opts[i]->def, G_VARIANT_TYPE_INT32)) { - gvar = g_variant_new_int32(strtoul(s, NULL, 10)); + gvar = g_variant_new_int32(strtol(s, NULL, 10)); g_hash_table_insert(hash, g_strdup(opts[i]->id), g_variant_ref_sink(gvar)); } else if (g_variant_is_of_type(opts[i]->def, G_VARIANT_TYPE_UINT64)) { - gvar = g_variant_new_uint64(strtoul(s, NULL, 10)); + gvar = g_variant_new_uint64(strtoull(s, NULL, 10)); g_hash_table_insert(hash, g_strdup(opts[i]->id), g_variant_ref_sink(gvar)); } else if (g_variant_is_of_type(opts[i]->def, G_VARIANT_TYPE_DOUBLE)) {