GNOME Bugzilla – Bug 764288
structure: Large integer gets detected as double instead of int64
Last modified: 2018-11-03 12:33:54 UTC
Created attachment 324893 [details] Test case Running the attached test case gives this output: Serialized structure measurement, field1=(int)1000000000; Structure didn't contain an int64 field1 Serialized structure measurement, field1=(double)10000000000; Structure didn't contain an int64 field1 Why double? There's no decimal point anywhere, shouldn't it be detected as an int64 instead? PS: I know it's leaky, it's just a small demo. PS2: Why is there no GST_STRUCTURE_FORMAT ? Now I'm leaking the strings as well as the structures :(
Alternatively it should just fail for things that are bigger than G_MAXINT. Switching from int to int64 (or double) just because of adding another 0 into a string probably caused a few surprises in the past already. We probably can't change this for 1.x though, might want to warn about it though.
Drive by comment, there is a GST_PTR_FORMAT, which works for structures (but within the gst logging API, not g_print).
GST_PTR_FORMAT indeed handles GstStructure too, I forgot about that. gst_info_strdup_vprintf() can also handle those btw.
We're clearly missing a gst_print() ;) As for this bug, I would make it bail out with a parsing error if the number is larger than MAXINT. In that case the type just has to be specified manually. I think that's better than magic and doesn't risk people inadvertently reading garbage values later.
Created attachment 325844 [details] [review] structure: Don't try to parse too large integers as doubles are fractions Having the number of digits decide between different types is going to cause unexpected surprises.
This now still fails... as now the integer is successfully parsed as "string" :) To solve this properly we would need functions to check if something looks like an integer (all digits, optionally starting with a - or +), double (same as integer but with one .) or fraction (same as integer but with one /). Should we go that route?
-- GitLab Migration Automatic Message -- This bug has been migrated to freedesktop.org's GitLab instance and has been closed from further activity. You can subscribe and participate further through the new bug through this link to our GitLab instance: https://gitlab.freedesktop.org/gstreamer/gstreamer/issues/164.