This is an automated email from the git hooks/post-receive script. Git pushed a commit to branch master in repository ffmpeg.
commit 33e5fca2ee586e6201024c5fad300cfc8061d84d Author: Niklas Haas <[email protected]> AuthorDate: Mon Apr 27 17:51:10 2026 +0200 Commit: Niklas Haas <[email protected]> CommitDate: Thu Jun 25 01:20:15 2026 +0200 avutil/tests/rational: add explicit unit tests for edge cases The existing tests don't really stress test the edge-case behavior when adding or multiplying values that over/underflow. Sponsored-by: Sovereign Tech Fund Signed-off-by: Niklas Haas <[email protected]> --- libavutil/tests/rational.c | 53 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) diff --git a/libavutil/tests/rational.c b/libavutil/tests/rational.c index ff75896de2..2c9ca947fc 100644 --- a/libavutil/tests/rational.c +++ b/libavutil/tests/rational.c @@ -53,6 +53,59 @@ int main(void) } } + /* Check overflow behavior and edge cases */ + static const AVRational unit_mul_q[][3] = { + {{INT_MAX, 2}, { 2, 1}, { INT_MAX, 1}}, + {{INT_MAX, 2}, {-2, 1}, {-INT_MAX, 1}}, + {{INT_MAX, 2}, { 0, 1}, {0, 1}}, + {{INT_MIN, 2}, { 2, 1}, {-INT_MAX, 1}}, /* not INT_MIN */ + {{INT_MIN, 2}, {-2, 1}, { INT_MAX, 1}}, + {{INT_MIN, 2}, { 0, 1}, {0, 1}}, + {{INT_MAX >> 8, 1}, {INT_MAX >> 8, 1}, {INT_MAX, 1}}, + {{1, INT_MAX >> 8}, {1, INT_MAX >> 8}, {0, 1}}, + {{1, 1}, {0, 0}, {0, 0}}, + {{0, 1}, {0, 0}, {0, 0}}, + }; + + for (i = 0; i < FF_ARRAY_ELEMS(unit_mul_q); i++) { + for (int c = 0; c < 2; c++) { /* test commutativity */ + AVRational a = unit_mul_q[i][c ? 1 : 0]; + AVRational b = unit_mul_q[i][c ? 0 : 1]; + AVRational c = unit_mul_q[i][2]; + AVRational r = av_mul_q(a, b); + if (r.num != c.num || r.den != c.den) { + av_log(NULL, AV_LOG_ERROR, "%d/%d * %d/%d = %d/%d, expected %d/%d\n", + a.num, a.den, b.num, b.den, r.num, r.den, c.num, c.den); + } + } + } + + static const AVRational unit_add_q[][3] = { + {{INT_MAX, 1}, { 2, 2}, { INT_MAX, 1}}, + {{INT_MAX, 1}, {-2, 2}, { INT_MAX - 1, 1}}, + {{INT_MAX, 1}, { 0, 2}, { INT_MAX, 1}}, + {{INT_MIN, 1}, { 2, 2}, {-INT_MAX, 1}}, + {{INT_MIN, 1}, {-2, 2}, {-INT_MAX, 1}}, + {{INT_MIN, 1}, { 0, 2}, {-INT_MAX, 1}}, + {{INT_MAX - 10, 1}, {20, 1}, { INT_MAX, 1}}, + {{2, INT_MAX}, {2, INT_MAX}, {4, INT_MAX}}, + {{1, 1}, {0, 0}, {0, 0}}, + {{0, 1}, {0, 0}, {0, 0}}, + }; + + for (i = 0; i < FF_ARRAY_ELEMS(unit_add_q); i++) { + for (int c = 0; c < 2; c++) { /* test commutativity */ + AVRational a = unit_add_q[i][c ? 1 : 0]; + AVRational b = unit_add_q[i][c ? 0 : 1]; + AVRational c = unit_add_q[i][2]; + AVRational r = av_add_q(a, b); + if (r.num != c.num || r.den != c.den) { + av_log(NULL, AV_LOG_ERROR, "%d/%d + %d/%d = %d/%d, expected %d/%d\n", + a.num, a.den, b.num, b.den, r.num, r.den, c.num, c.den); + } + } + } + for (i = 0; i < FF_ARRAY_ELEMS(numlist); i++) { int64_t a = numlist[i]; _______________________________________________ ffmpeg-cvslog mailing list -- [email protected] To unsubscribe send an email to [email protected]
