Purge FLAC__STRINGS_IN_UTF8 from VC project files.
[platform/upstream/flac.git] / src / libFLAC / ogg_helper.c
index 80f7528..700d183 100644 (file)
@@ -1,5 +1,5 @@
 /* libFLAC - Free Lossless Audio Codec
- * Copyright (C) 2004,2005,2006  Josh Coalson
+ * Copyright (C) 2004,2005,2006,2007,2008,2009  Josh Coalson
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -36,6 +36,7 @@
 #include <stdlib.h> /* for malloc() */
 #include <string.h> /* for memcmp(), memcpy() */
 #include "FLAC/assert.h"
+#include "share/alloc.h"
 #include "private/ogg_helper.h"
 #include "protected/stream_encoder.h"
 
@@ -112,7 +113,7 @@ FLAC__bool simple_ogg_page__get_at(FLAC__StreamEncoder *encoder, FLAC__uint64 po
        }
 
        /* allocate space for the page header */
-       if(0 == (page->header = (unsigned char *)malloc(OGG_MAX_HEADER_LEN))) {
+       if(0 == (page->header = safe_malloc_(OGG_MAX_HEADER_LEN))) {
                encoder->protected_->state = FLAC__STREAM_ENCODER_MEMORY_ALLOCATION_ERROR;
                return false;
        }
@@ -150,11 +151,11 @@ FLAC__bool simple_ogg_page__get_at(FLAC__StreamEncoder *encoder, FLAC__uint64 po
                        }
                }
 
-               page->body_len = 255 * i + page->header[i];
+               page->body_len = 255 * i + page->header[i + OGG_HEADER_FIXED_PORTION_LEN];
        }
 
        /* allocate space for the page body */
-       if(0 == (page->body = (unsigned char *)malloc(page->body_len))) {
+       if(0 == (page->body = safe_malloc_(page->body_len))) {
                encoder->protected_->state = FLAC__STREAM_ENCODER_MEMORY_ALLOCATION_ERROR;
                return false;
        }
@@ -199,6 +200,10 @@ FLAC__bool simple_ogg_page__set_at(FLAC__StreamEncoder *encoder, FLAC__uint64 po
                encoder->protected_->state = FLAC__STREAM_ENCODER_CLIENT_ERROR;
                return false;
        }
+       if(write_callback((FLAC__StreamEncoder*)encoder, page->body, page->body_len, 0, 0, client_data) != FLAC__STREAM_ENCODER_WRITE_STATUS_OK) {
+               encoder->protected_->state = FLAC__STREAM_ENCODER_CLIENT_ERROR;
+               return false;
+       }
 
        return true;
 }