From 0c862c2ce705e3835001cd3a08a85da2f7f51f9f Mon Sep 17 00:00:00 2001 From: Moritz Bunkus Date: Sun, 13 Sep 2015 10:21:46 +0200 Subject: [PATCH] parse_timecode: use signed variable for value containing negative values MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit size_t is usually an unsigned value. Storing -1 in it and expecting the following multiplication to result in a negative value only works on architectures where sizeof(size_t) == sizeof(int64_t), meaning on 64bit platforms. On 32bit Windows »negative« would contain MAX_UINT32 instead of MAX_UINT64 resulting in wrong results. Fixes #1425. --- ChangeLog | 5 +++++ src/common/strings/parsing.cpp | 4 ++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index a7a1d31f1..860cff58d 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2015-09-13 Moritz Bunkus + + * all: bug fix: parsing of strings containing negative values or + timecodes was broken on 32bit architectures. Fixes #1425. + 2015-09-05 Moritz Bunkus * MKVToolNix GUI: new merge tool feature: added a column in the diff --git a/src/common/strings/parsing.cpp b/src/common/strings/parsing.cpp index c36756905..99f7fc855 100644 --- a/src/common/strings/parsing.cpp +++ b/src/common/strings/parsing.cpp @@ -41,8 +41,8 @@ parse_timecode(const std::string &src, // HH: is optional; HH, MM and SS can be either one or two digits. // 2. HH:MM:SS:nnnnnnnnn with up to nine digits 'n' for ns precision; // HH: is optional; HH, MM and SS can be either one or two digits. - int h, m, s, n, values[4], num_values, num_digits, num_colons; - size_t offset = 0, negative = 1, i; + int h, m, s, n, values[4], num_values, num_digits, num_colons, negative = 1; + size_t offset = 0, i; bool decimal_point_found; if (src.empty())