[xiph-commits] r3861 - liboggz/trunk/src/tools

conrad at svn.annodex.net conrad at svn.annodex.net
Sun Feb 22 20:24:45 PST 2009


Author: conrad
Date: 2009-02-22 20:24:45 -0800 (Sun, 22 Feb 2009)
New Revision: 3861

Modified:
   liboggz/trunk/src/tools/oggz-validate.c
Log:
oggz-validate: handle out-of-memory

Modified: liboggz/trunk/src/tools/oggz-validate.c
===================================================================
--- liboggz/trunk/src/tools/oggz-validate.c	2009-02-23 04:08:47 UTC (rev 3860)
+++ liboggz/trunk/src/tools/oggz-validate.c	2009-02-23 04:24:45 UTC (rev 3861)
@@ -80,6 +80,7 @@
   {0, NULL}
 };
 
+static char * progname;
 static int max_errors = MAX_ERRORS;
 static int multifile = 0;
 static char * current_filename = NULL;
@@ -139,6 +140,13 @@
   printf ("Please report bugs to <ogg-dev at xiph.org>\n");
 }
 
+static void
+exit_out_of_memory (void)
+{
+  fprintf (stderr, "%s: Out of memory\n", progname);
+  exit (1);
+}
+
 static int
 log_error (void)
 {
@@ -187,7 +195,7 @@
   return (timestamp_t)((double)(SUBSECONDS * granule * gr_d) / (double)gr_n);
 }
 
-static void
+static int
 ovdata_init (OVData * ovdata)
 {
   int flags;
@@ -203,8 +211,12 @@
     exit (1);
   }
 
-  ovdata->missing_eos = oggz_table_new ();
-  ovdata->packetno = oggz_table_new ();
+  if ((ovdata->missing_eos = oggz_table_new ()) == NULL)
+    exit_out_of_memory();
+
+  if ((ovdata->packetno = oggz_table_new ()) == NULL)
+    exit_out_of_memory();
+
   ovdata->theora_count = 0;
   ovdata->audio_count = 0;
   ovdata->chain_ended = 0;
@@ -247,7 +259,8 @@
 
   if (ogg_page_bos ((ogg_page *)og)) {
     /* Register this serialno as needing eos */
-    oggz_table_insert (ovdata->missing_eos, serialno, (void *)0x1);
+    if (oggz_table_insert (ovdata->missing_eos, serialno, (void *)0x1) == NULL)
+      exit_out_of_memory();
 
     /* Handle ordering of Theora vs. audio packets */
     content_type = oggz_stream_get_content (oggz, serialno);
@@ -287,7 +300,9 @@
     if (packetno < headers) {
       /* The previous page was headers, and more are expected */
       packetno += packets;
-      oggz_table_insert (ovdata->packetno, serialno, (void *)packetno);
+      if (oggz_table_insert (ovdata->packetno, serialno, (void *)packetno) == NULL)
+        exit_out_of_memory();
+
       if (packetno == headers && gpos != 0) {
         ret = log_error ();
         fprintf (stderr, "serialno %010lu: Terminal header page has non-zero granulepos\n", serialno);
@@ -303,7 +318,8 @@
       }
 
       /* Mark packetno as greater than headers to avoid these checks for this serialno */
-      oggz_table_insert (ovdata->packetno, serialno, (void *)(headers+1));
+      if (oggz_table_insert (ovdata->packetno, serialno, (void *)(headers+1)) == NULL)
+        exit_out_of_memory();
     }
 
   }
@@ -459,7 +475,6 @@
   int opt_prefix = 0;
   int opt_suffix = 0;
 
-  char * progname;
   char * filename;
   int i = 1;
 



More information about the commits mailing list