]> sigrok.org Git - sigrok-cli.git/commitdiff
parsers: use proper conversion routine for PD option data types
authorGerhard Sittig <redacted>
Sat, 23 Apr 2022 19:31:06 +0000 (21:31 +0200)
committerGerhard Sittig <redacted>
Sat, 23 Apr 2022 19:36:34 +0000 (21:36 +0200)
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).

parsers.c

index d92218f8664ed5a8858e32a6b631b8d4c68633aa..c1ab9bdabf5a2bf728c3f4477d5e170e4186605a 100644 (file)
--- 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)) {