pcrs_compile_replacement(): Silence a coverity warning (CID #161203)
[privoxy.git] / miscutil.c
index aebd55f..f5e647c 100644 (file)
@@ -1,4 +1,4 @@
-const char miscutil_rcs[] = "$Id: miscutil.c,v 1.79 2015/08/12 10:34:38 fabiankeil Exp $";
+const char miscutil_rcs[] = "$Id: miscutil.c,v 1.80 2016/01/16 12:33:36 fabiankeil Exp $";
 /*********************************************************************
  *
  * File        :  $Source: /cvsroot/ijbswa/current/miscutil.c,v $
@@ -93,6 +93,40 @@ void *zalloc(size_t size)
 }
 
 
+/*********************************************************************
+ *
+ * Function    :  zalloc_or_die
+ *
+ * Description :  zalloc wrapper that either succeeds or causes
+ *                program termination.
+ *
+ *                Useful in situations were the string length is
+ *                "small" and zalloc() failures couldn't be handled
+ *                better anyway. In case of debug builds, failures
+ *                trigger an assert().
+ *
+ * Parameters  :
+ *          1  :  size = Size of memory chunk to return.
+ *
+ * Returns     :  Pointer to newly malloc'd memory chunk.
+ *
+ *********************************************************************/
+void *zalloc_or_die(size_t size)
+{
+   void *buffer;
+
+   buffer = zalloc(size);
+   if (buffer == NULL)
+   {
+      assert(buffer != NULL);
+      log_error(LOG_LEVEL_FATAL, "Out of memory in zalloc_or_die().");
+      exit(1);
+   }
+
+   return(buffer);
+
+}
+
 /*********************************************************************
  *
  * Function    :  strdup_or_die