shithub: libopusenc

Download patch

ref: 8d5c2fb9aa870325f6dd0816a2b93cf223af74f6
parent: 630163e86a73b1e27f83fe9f238b2f5ee13b30c6
author: Jean-Marc Valin <[email protected]>
date: Thu May 11 13:33:33 EDT 2017

Using size_t for things that could be beyond 4GB

--- a/src/ogg_packer.c
+++ b/src/ogg_packer.c
@@ -122,12 +122,12 @@
 
 typedef struct {
   oggp_uint64 granulepos;
-  int buf_pos;
-  int buf_size;
-  int lacing_pos;
-  int lacing_size;
+  size_t buf_pos;
+  size_t buf_size;
+  size_t lacing_pos;
+  size_t lacing_size;
   int flags;
-  int pageno;
+  size_t pageno;
 } oggp_page;
 
 struct oggpacker {
@@ -135,21 +135,21 @@
   unsigned char *buf;
   unsigned char *alloc_buf;
   unsigned char *user_buf;
-  int buf_size;
-  int buf_fill;
-  int buf_begin;
+  size_t buf_size;
+  size_t buf_fill;
+  size_t buf_begin;
   unsigned char *lacing;
-  int lacing_size;
-  int lacing_fill;
-  int lacing_begin;
+  size_t lacing_size;
+  size_t lacing_fill;
+  size_t lacing_begin;
   oggp_page *pages;
-  int pages_size;
-  int pages_fill;
+  size_t pages_size;
+  size_t pages_fill;
   oggp_uint64 muxing_delay;
   int is_eos;
   oggp_uint64 curr_granule;
   oggp_uint64 last_granule;
-  int pageno;
+  size_t pageno;
 };
 
 /** Allocates an oggpacker object */
@@ -210,13 +210,11 @@
 }
 
 static void shift_buffer(oggpacker *oggp) {
-  int buf_shift;
-  int lacing_shift;
-  int i;
+  size_t buf_shift;
+  size_t lacing_shift;
+  size_t i;
   buf_shift = oggp->pages_fill ? oggp->pages[0].buf_pos : oggp->buf_begin;
   lacing_shift = oggp->pages_fill ? oggp->pages[0].lacing_pos : oggp->lacing_begin;
-  assert(lacing_shift >= 0);
-  assert(buf_shift >= 0);
   if (4*lacing_shift > oggp->lacing_fill) {
     memmove(&oggp->lacing[0], &oggp->lacing[lacing_shift], oggp->lacing_fill-lacing_shift);
     for (i=0;i<oggp->pages_fill;i++) oggp->pages[i].lacing_pos -= lacing_shift;
@@ -264,8 +262,8 @@
     oggp_get_packet_buffer() has been filled and the number of bytes written
     has to be no more than what was originally asked for. */
 int oggp_commit_packet(oggpacker *oggp, int bytes, oggp_uint64 granulepos, int eos) {
-  int i;
-  int nb_255s;
+  size_t i;
+  size_t nb_255s;
   assert(oggp->user_buf != NULL);
   nb_255s = bytes/255;
   if (oggp->lacing_fill-oggp->lacing_begin+nb_255s+1 > 255 ||
@@ -279,7 +277,7 @@
 
     /* If we didn't shift the values or if we did and there's still not enough room, make some more. */
     if (oggp->lacing_fill + nb_255s + 1 > oggp->lacing_size) {
-      int newsize;
+      size_t newsize;
       unsigned char *newbuf;
       newsize = oggp->lacing_fill + nb_255s + 1;
       /* Making sure we don't need to do that too often. */
@@ -315,7 +313,7 @@
 int oggp_flush_page(oggpacker *oggp) {
   oggp_page *p;
   int cont = 0;
-  int nb_lacing;
+  size_t nb_lacing;
   if (oggp->lacing_fill == oggp->lacing_begin) {
     return 1;
   }
@@ -322,7 +320,7 @@
   nb_lacing = oggp->lacing_fill - oggp->lacing_begin;
   do {
     if (oggp->pages_fill >= oggp->pages_size) {
-      int newsize;
+      size_t newsize;
       oggp_page *newbuf;
       /* Making sure we don't need to do that too often. */
       newsize = 1 + oggp->pages_size*3/2;
@@ -342,7 +340,7 @@
     p->flags = cont;
     p->buf_pos = oggp->buf_begin;
     if (p->lacing_size > 255) {
-      int bytes=0;
+      size_t bytes=0;
       int i;
       for (i=0;i<255;i++) bytes += oggp->lacing[oggp->lacing_begin+1];
       p->buf_size = bytes;
@@ -371,7 +369,7 @@
   oggp_page *p;
   int i;
   unsigned char *ptr;
-  int len;
+  size_t len;
   int header_size;
   oggp_uint64 granule_pos;
   if (oggp->pages_fill == 0) {