summaryrefslogtreecommitdiffstats
path: root/gst/matroska/ebml-read.c
diff options
context:
space:
mode:
Diffstat (limited to 'gst/matroska/ebml-read.c')
-rw-r--r--gst/matroska/ebml-read.c15
1 files changed, 10 insertions, 5 deletions
diff --git a/gst/matroska/ebml-read.c b/gst/matroska/ebml-read.c
index 67b9b5f3..c5b9c0da 100644
--- a/gst/matroska/ebml-read.c
+++ b/gst/matroska/ebml-read.c
@@ -464,7 +464,7 @@ gst_ebml_read_sint (GstEbmlRead *ebml,
{
GstBuffer *buf;
guint8 *data;
- guint size;
+ guint size, negative = 0, n = 0;
if (!gst_ebml_read_buffer (ebml, id, &buf))
return FALSE;
@@ -478,14 +478,19 @@ gst_ebml_read_sint (GstEbmlRead *ebml,
gst_buffer_unref (buf);
return FALSE;
}
+ if (data[0] & 0x80) {
+ negative = 1;
+ data[0] &= ~0x80;
+ }
*num = 0;
- while (size > 0) {
- *num = (*num << 8) | data[GST_BUFFER_SIZE (buf) - size];
- size--;
+ while (n < size) {
+ *num = (*num << 8) | data[n++];
}
/* make signed */
- *num -= (1LL << ((8 * GST_BUFFER_SIZE (buf)) - 1));
+ if (negative) {
+ *num = *num - (1LL << ((8 * size) - 1));
+ }
gst_buffer_unref (buf);