After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 705630 - directcontrolbinding: Wrong behaviour of control bindings with properties that span +-INT_MAX
directcontrolbinding: Wrong behaviour of control bindings with properties tha...
Status: RESOLVED FIXED
Product: GStreamer
Classification: Platform
Component: gstreamer (core)
git master
Other Linux
: Normal normal
: 1.0.10
Assigned To: GStreamer Maintainers
GStreamer Maintainers
Depends on:
Blocks:
 
 
Reported: 2013-08-07 17:33 UTC by Adrián Pardini
Modified: 2013-08-26 13:05 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Rewrite value calculation expression to avoid integer overflow. (2.06 KB, patch)
2013-08-07 17:33 UTC, Adrián Pardini
committed Details | Review

Description Adrián Pardini 2013-08-07 17:33:14 UTC
Created attachment 251096 [details] [review]
Rewrite value calculation expression to avoid integer overflow.

Hello all,

I'm trying to animate the xpos and ypos of a videomixer pad but they are always mapped from [0,1] to either -2147483648 or 2147483647 and nothing in between.

I've chased it to the macro definitions of convert_g_value_to_##type and convert_value_to_##type in gstdirectcontrolbinding.c where the expression

v = pspec->minimum + (g##type) ROUNDING_OP ((pspec->maximum - pspec->minimum) * s);

results in:

v = -2147483648 + (g##type) ROUNDING_OP ((-1) * s);

because 2147483647 - (-2147483648) overflows to -1;


Rewriting the expression as:

v = minimum*(1-s) + maximum*s

works but I don't know for sure if it introduces numerical stability issues in upper layers. At least for my current use case it works fine.

The proposed patch implements that.

Discussion thread at: http://lists.freedesktop.org/archives/gstreamer-devel/2013-August/042395.html
Comment 1 Sebastian Dröge (slomo) 2013-08-08 10:32:39 UTC
commit d4f6c8e0e69c5f581ab7fefd1b592f5b4701205c
Author: Adrian Pardini <publico@tangopardo.com.ar>
Date:   Wed Aug 7 14:17:28 2013 -0300

    controller: fixes int overflow with properties that span +-INT_MAX
    
    When the range for a property is defined as -INT_MAX-1 .. INT_MAX, like
    the xpos in a videomixer the following expression in the macro
    definitions of convert_g_value_to_##type (and the equivalent in
    convert_value_to_##type)
    
    v = pspec->minimum + (g##type) ROUNDING_OP ((pspec->maximum - pspec->minimum) * s);
    
    are converted to:
    
    v = -2147483648 + (g##type) ROUNDING_OP ((2147483647 - -2147483648) * s);
    
    (2147483647 - -2147483648) overflows to -1 and the net result is:
    
    v = -2147483648 + (g##type) ROUNDING_OP (-1 * s);
    
    so v only takes the values -2147483648 for s == 0 and 2147483647
    for s == 1.
    
    Rewriting the expression as minimum*(1-s) + maximum*s gives the correct
    result in this case.
    
    https://bugzilla.gnome.org//show_bug.cgi?id=705630
Comment 2 Tim-Philipp Müller 2013-08-26 13:05:05 UTC
Cherry-picked into 1.0 branch.