[xiph-commits] r16016 - in trunk/ogg: . include/ogg src

xiphmont at svn.xiph.org xiphmont at svn.xiph.org
Tue May 19 16:27:38 PDT 2009


Author: xiphmont
Date: 2009-05-19 16:27:38 -0700 (Tue, 19 May 2009)
New Revision: 16016

Modified:
   trunk/ogg/configure.in
   trunk/ogg/include/ogg/ogg.h
   trunk/ogg/src/bitwise.c
   trunk/ogg/src/framing.c
Log:
Update configure script to use new 'legal' names for cache vals (I hate you so much, autofoo)

Update ogg to check the return of all allocs for those on embedded
platforms with guarantees non-ovecommit.  Be aware that these checks
are useless on any modern desktop OS, but that embedded folks with no
MMU and a hard heap boundary will benefit.

Add one new call to bitpacker that will query a write-mode
oggpack_buffer to see if it ran out of memory at some point; there was
no other way to add the error reporting in an ABI-compatible manner
(and it also allows the writepacker to avoid extra checks; it will
just keep going after running out of memory without faulting and state
can be queried later).



Modified: trunk/ogg/configure.in
===================================================================
--- trunk/ogg/configure.in	2009-05-19 22:11:08 UTC (rev 16015)
+++ trunk/ogg/configure.in	2009-05-19 23:27:38 UTC (rev 16016)
@@ -83,7 +83,7 @@
 dnl Check for types
 
 AC_MSG_CHECKING(for int16_t)
-AC_CACHE_VAL(has_int16_t,
+AC_CACHE_VAL(has_cv_int16_t,
 [AC_TRY_RUN([
 #if defined __BEOS__ && !defined __HAIKU__
 #include <inttypes.h>
@@ -92,14 +92,14 @@
 int16_t foo;
 int main() {return 0;}
 ],
-has_int16_t=yes,
-has_int16_t=no,
-has_int16_t=no
+has_cv_int16_t=yes,
+has_cv_int16_t=no,
+has_cv_int16_t=no
 )])
-AC_MSG_RESULT($has_int16_t)
+AC_MSG_RESULT($has_cv_int16_t)
 
 AC_MSG_CHECKING(for int32_t)
-AC_CACHE_VAL(has_int32_t,
+AC_CACHE_VAL(has_cv_int32_t,
 [AC_TRY_RUN([
 #if defined __BEOS__ && !defined __HAIKU__
 #include <inttypes.h>
@@ -108,14 +108,14 @@
 int32_t foo;
 int main() {return 0;}
 ],
-has_int32_t=yes,
-has_int32_t=no,
-has_int32_t=no
+has_cv_int32_t=yes,
+has_cv_int32_t=no,
+has_cv_int32_t=no
 )])
-AC_MSG_RESULT($has_int32_t)
+AC_MSG_RESULT($has_cv_int32_t)
 
 AC_MSG_CHECKING(for uint32_t)
-AC_CACHE_VAL(has_uint32_t,
+AC_CACHE_VAL(has_cv_uint32_t,
 [AC_TRY_RUN([
 #if defined __BEOS__ && !defined __HAIKU__
 #include <inttypes.h>
@@ -124,14 +124,14 @@
 uint32_t foo;
 int main() {return 0;}
 ],
-has_uint32_t=yes,
-has_uint32_t=no,
-has_uint32_t=no
+has_cv_uint32_t=yes,
+has_cv_uint32_t=no,
+has_cv_uint32_t=no
 )])
-AC_MSG_RESULT($has_uint32_t)
+AC_MSG_RESULT($has_cv_uint32_t)
 
 AC_MSG_CHECKING(for uint16_t)
-AC_CACHE_VAL(has_uint16_t,
+AC_CACHE_VAL(has_cv_uint16_t,
 [AC_TRY_RUN([
 #if defined __BEOS__ && !defined __HAIKU__
 #include <inttypes.h>
@@ -140,14 +140,14 @@
 uint16_t foo;
 int main() {return 0;}
 ],
-has_uint16_t=yes,
-has_uint16_t=no,
-has_uint16_t=no
+has_cv_uint16_t=yes,
+has_cv_uint16_t=no,
+has_cv_uint16_t=no
 )])
-AC_MSG_RESULT($has_uint16_t)
+AC_MSG_RESULT($has_cv_uint16_t)
 
 AC_MSG_CHECKING(for u_int32_t)
-AC_CACHE_VAL(has_u_int32_t,
+AC_CACHE_VAL(has_cv_u_int32_t,
 [AC_TRY_RUN([
 #if defined __BEOS__ && !defined __HAIKU__
 #include <inttypes.h>
@@ -156,14 +156,14 @@
 u_int32_t foo;
 int main() {return 0;}
 ],
-has_u_int32_t=yes,
-has_u_int32_t=no,
-has_u_int32_t=no
+has_cv_u_int32_t=yes,
+has_cv_u_int32_t=no,
+has_cv_u_int32_t=no
 )])
-AC_MSG_RESULT($has_u_int32_t)
+AC_MSG_RESULT($has_cv_u_int32_t)
 
 AC_MSG_CHECKING(for u_int16_t)
-AC_CACHE_VAL(has_u_int16_t,
+AC_CACHE_VAL(has_cv_u_int16_t,
 [AC_TRY_RUN([
 #if defined __BEOS__ && !defined __HAIKU__
 #include <inttypes.h>
@@ -172,14 +172,14 @@
 u_int16_t foo;
 int main() {return 0;}
 ],
-has_u_int16_t=yes,
-has_u_int16_t=no,
-has_u_int16_t=no
+has_cv_u_int16_t=yes,
+has_cv_u_int16_t=no,
+has_cv_u_int16_t=no
 )])
-AC_MSG_RESULT($has_u_int16_t)
+AC_MSG_RESULT($has_cv_u_int16_t)
 
 AC_MSG_CHECKING(for int64_t)
-AC_CACHE_VAL(has_int64_t,
+AC_CACHE_VAL(has_cv_int64_t,
 [AC_TRY_RUN([
 #if defined __BEOS__ && !defined __HAIKU__
 #include <inttypes.h>
@@ -188,11 +188,11 @@
 int64_t foo;
 int main() {return 0;}
 ],
-has_int64_t=yes,
-has_int64_t=no,
-has_int64_t=no
+has_cv_int64_t=yes,
+has_cv_int64_t=no,
+has_cv_int64_t=no
 )])
-AC_MSG_RESULT($has_int64_t)
+AC_MSG_RESULT($has_cv_int64_t)
 
 AC_CHECK_SIZEOF(short,2)
 AC_CHECK_SIZEOF(int,4)
@@ -200,7 +200,7 @@
 AC_CHECK_SIZEOF(long long,8)
 
 
-if test x$has_int16_t = "xyes" ; then
+if test x$has_cv_int16_t = "xyes" ; then
         SIZE16="int16_t"
 else
         case 2 in
@@ -209,7 +209,7 @@
         esac
 fi
 
-if test x$has_int32_t = "xyes" ; then
+if test x$has_cv_int32_t = "xyes" ; then
         SIZE32="int32_t"
 else
         case 4 in
@@ -219,10 +219,10 @@
         esac
 fi
 
-if test x$has_uint32_t = "xyes" ; then
+if test x$has_cv_uint32_t = "xyes" ; then
         USIZE32="uint32_t"
 else
-        if test x$has_u_int32_t = "xyes" ; then
+        if test x$has_cv_u_int32_t = "xyes" ; then
                 USIZE32="u_int32_t"
         else
                 case 4 in
@@ -233,10 +233,10 @@
         fi
 fi
 
-if test x$has_uint16_t = "xyes" ; then
+if test x$has_cv_uint16_t = "xyes" ; then
         USIZE16="uint16_t"
 else
-        if test x$has_u_int16_t = "xyes" ; then
+        if test x$has_cv_u_int16_t = "xyes" ; then
                 USIZE16="u_int16_t"
         else
                 case 2 in
@@ -247,7 +247,7 @@
         fi
 fi
 
-if test x$has_int64_t = "xyes" ; then
+if test x$has_cv_int64_t = "xyes" ; then
         SIZE64="int64_t"
 else
 case 8 in

Modified: trunk/ogg/include/ogg/ogg.h
===================================================================
--- trunk/ogg/include/ogg/ogg.h	2009-05-19 22:11:08 UTC (rev 16015)
+++ trunk/ogg/include/ogg/ogg.h	2009-05-19 23:27:38 UTC (rev 16016)
@@ -116,6 +116,7 @@
 /* Ogg BITSTREAM PRIMITIVES: bitstream ************************/
 
 extern void  oggpack_writeinit(oggpack_buffer *b);
+extern int   oggpack_writecheck(oggpack_buffer *b);
 extern void  oggpack_writetrunc(oggpack_buffer *b,long bits);
 extern void  oggpack_writealign(oggpack_buffer *b);
 extern void  oggpack_writecopy(oggpack_buffer *b,void *source,long bits);
@@ -134,6 +135,7 @@
 extern unsigned char *oggpack_get_buffer(oggpack_buffer *b);
 
 extern void  oggpackB_writeinit(oggpack_buffer *b);
+extern int   oggpackB_writecheck(oggpack_buffer *b);
 extern void  oggpackB_writetrunc(oggpack_buffer *b,long bits);
 extern void  oggpackB_writealign(oggpack_buffer *b);
 extern void  oggpackB_writecopy(oggpack_buffer *b,void *source,long bits);

Modified: trunk/ogg/src/bitwise.c
===================================================================
--- trunk/ogg/src/bitwise.c	2009-05-19 22:11:08 UTC (rev 16015)
+++ trunk/ogg/src/bitwise.c	2009-05-19 23:27:38 UTC (rev 16016)
@@ -47,28 +47,48 @@
   oggpack_writeinit(b);
 }
 
+int oggpack_writecheck(oggpack_buffer *b){
+  if(!b->ptr || !b->storage)return -1;
+  return 0;
+}
+
+int oggpackB_writecheck(oggpack_buffer *b){
+  return oggpackB_writecheck(b);
+}
+
 void oggpack_writetrunc(oggpack_buffer *b,long bits){
   long bytes=bits>>3;
-  bits-=bytes*8;
-  b->ptr=b->buffer+bytes;
-  b->endbit=bits;
-  b->endbyte=bytes;
-  *b->ptr&=mask[bits];
+  if(b->ptr){
+    bits-=bytes*8;
+    b->ptr=b->buffer+bytes;
+    b->endbit=bits;
+    b->endbyte=bytes;
+    *b->ptr&=mask[bits];
+  }
 }
 
 void oggpackB_writetrunc(oggpack_buffer *b,long bits){
   long bytes=bits>>3;
-  bits-=bytes*8;
-  b->ptr=b->buffer+bytes;
-  b->endbit=bits;
-  b->endbyte=bytes;
-  *b->ptr&=mask8B[bits];
+  if(b->ptr){
+    bits-=bytes*8;
+    b->ptr=b->buffer+bytes;
+    b->endbit=bits;
+    b->endbyte=bytes;
+    *b->ptr&=mask8B[bits];
+  }
 }
 
 /* Takes only up to 32 bits. */
 void oggpack_write(oggpack_buffer *b,unsigned long value,int bits){
   if(b->endbyte+4>=b->storage){
-    b->buffer=_ogg_realloc(b->buffer,b->storage+BUFFER_INCREMENT);
+    void *ret;
+    if(!b->ptr)return;
+    ret=_ogg_realloc(b->buffer,b->storage+BUFFER_INCREMENT);
+    if(!ret){
+      oggpack_writeclear(b);
+      return;
+    }
+    b->buffer=ret;
     b->storage+=BUFFER_INCREMENT;
     b->ptr=b->buffer+b->endbyte;
   }
@@ -102,7 +122,14 @@
 /* Takes only up to 32 bits. */
 void oggpackB_write(oggpack_buffer *b,unsigned long value,int bits){
   if(b->endbyte+4>=b->storage){
-    b->buffer=_ogg_realloc(b->buffer,b->storage+BUFFER_INCREMENT);
+    void *ret;
+    if(!b->ptr)return;
+    ret=_ogg_realloc(b->buffer,b->storage+BUFFER_INCREMENT);
+    if(!ret){
+      oggpack_writeclear(b);
+      return;
+    }
+    b->buffer=ret;
     b->storage+=BUFFER_INCREMENT;
     b->ptr=b->buffer+b->endbyte;
   }
@@ -165,8 +192,15 @@
   }else{
     /* aligned block copy */
     if(b->endbyte+bytes+1>=b->storage){
+      void *ret;
+      if(!b->ptr)return;
       b->storage=b->endbyte+bytes+BUFFER_INCREMENT;
-      b->buffer=_ogg_realloc(b->buffer,b->storage);
+      ret=_ogg_realloc(b->buffer,b->storage);
+      if(!ret){
+	oggpack_writeclear(b);
+	return;
+      }
+      b->buffer=ret;
       b->ptr=b->buffer+b->endbyte;
     }
 
@@ -193,6 +227,7 @@
 }
 
 void oggpack_reset(oggpack_buffer *b){
+  if(!b->ptr)return;
   b->ptr=b->buffer;
   b->buffer[0]=0;
   b->endbit=b->endbyte=0;
@@ -203,7 +238,7 @@
 }
 
 void oggpack_writeclear(oggpack_buffer *b){
-  _ogg_free(b->buffer);
+  if(b->buffer)_ogg_free(b->buffer);
   memset(b,0,sizeof(*b));
 }
 

Modified: trunk/ogg/src/framing.c
===================================================================
--- trunk/ogg/src/framing.c	2009-05-19 22:11:08 UTC (rev 16015)
+++ trunk/ogg/src/framing.c	2009-05-19 23:27:38 UTC (rev 16016)
@@ -189,12 +189,17 @@
   if(os){
     memset(os,0,sizeof(*os));
     os->body_storage=16*1024;
+    os->lacing_storage=1024;
+
     os->body_data=_ogg_malloc(os->body_storage*sizeof(*os->body_data));
-
-    os->lacing_storage=1024;
     os->lacing_vals=_ogg_malloc(os->lacing_storage*sizeof(*os->lacing_vals));
     os->granule_vals=_ogg_malloc(os->lacing_storage*sizeof(*os->granule_vals));
 
+    if(!os->body_data || !os->lacing_vals || !os->granule_vals){
+      ogg_stream_clear(os);
+      return -1;
+    }
+
     os->serialno=serialno;
 
     return(0);
@@ -225,19 +230,32 @@
 /* Helpers for ogg_stream_encode; this keeps the structure and
    what's happening fairly clear */
 
-static void _os_body_expand(ogg_stream_state *os,int needed){
+static int _os_body_expand(ogg_stream_state *os,int needed){
   if(os->body_storage<=os->body_fill+needed){
+    void *ret;
+    ret=_ogg_realloc(os->body_data,(os->body_storage+needed+1024)*
+		     sizeof(*os->body_data));
+    if(!ret) return -1;
     os->body_storage+=(needed+1024);
-    os->body_data=_ogg_realloc(os->body_data,os->body_storage*sizeof(*os->body_data));
+    os->body_data=ret;
   }
+  return 0;
 }
 
-static void _os_lacing_expand(ogg_stream_state *os,int needed){
+static int _os_lacing_expand(ogg_stream_state *os,int needed){
   if(os->lacing_storage<=os->lacing_fill+needed){
+    void *ret;
+    ret=_ogg_realloc(os->lacing_vals,(os->lacing_storage+needed+32)*
+		     sizeof(*os->lacing_vals));
+    if(!ret)return -1;
+    os->lacing_vals=ret;
+    ret=_ogg_realloc(os->granule_vals,(os->lacing_storage+needed+32)*
+		     sizeof(*os->granule_vals));
+    if(!ret)return -1;
+    os->granule_vals=ret;
     os->lacing_storage+=(needed+32);
-    os->lacing_vals=_ogg_realloc(os->lacing_vals,os->lacing_storage*sizeof(*os->lacing_vals));
-    os->granule_vals=_ogg_realloc(os->granule_vals,os->lacing_storage*sizeof(*os->granule_vals));
   }
+  return 0;
 }
 
 /* checksum the page */
@@ -288,8 +306,8 @@
   }
  
   /* make sure we have the buffer storage */
-  _os_body_expand(os,bytes);
-  _os_lacing_expand(os,lacing_vals);
+  if(_os_body_expand(os,bytes))return -1;
+  if(_os_lacing_expand(os,lacing_vals))return -1;
 
   /* Copy in the submitted packet.  Yes, the copy is a waste; this is
      the liability of overly clean abstraction for the time being.  It
@@ -528,11 +546,14 @@
   if(size>oy->storage-oy->fill){
     /* We need to extend the internal buffer */
     long newsize=size+oy->fill+4096; /* an extra page to be nice */
+    void *ret;
 
     if(oy->data)
-      oy->data=_ogg_realloc(oy->data,newsize);
+      ret=_ogg_realloc(oy->data,newsize);
     else
-      oy->data=_ogg_malloc(newsize);
+      ret=_ogg_malloc(newsize);
+    if(!ret)return NULL;
+    oy->data=ret;
     oy->storage=newsize;
   }
 
@@ -729,7 +750,7 @@
   if(serialno!=os->serialno)return(-1);
   if(version>0)return(-1);
 
-  _os_lacing_expand(os,segments+1);
+  if(_os_lacing_expand(os,segments+1))return -1;
 
   /* are we in sequence? */
   if(pageno!=os->pageno){
@@ -766,7 +787,7 @@
   }
   
   if(bodysize){
-    _os_body_expand(os,bodysize);
+    if(_os_body_expand(os,bodysize))return -1;
     memcpy(os->body_data+os->body_fill,body,bodysize);
     os->body_fill+=bodysize;
   }



More information about the commits mailing list