summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJean-Baptiste Queru <jbq@google.com>2011-06-08 14:56:41 -0700
committerAndroid Git Automerger <android-git-automerger@android.com>2011-06-08 14:56:41 -0700
commitc7f0656886586f88dc9bf5b3a2bcacc0bd17f018 (patch)
tree331fbd61409210997e0216dd95609ebdaebdebd1
parent189fc1d078bf9bb74fa74645b6d6c4e3b58da001 (diff)
parentfc9da699e0155adc1820bd06b72d40276e31a630 (diff)
downloadjhead-c7f0656886586f88dc9bf5b3a2bcacc0bd17f018.tar.gz
am fc9da699: am e5617a0c: Merge "Make create_EXIF allocate enough memory"
* commit 'fc9da699e0155adc1820bd06b72d40276e31a630': Make create_EXIF allocate enough memory
-rw-r--r--exif.c21
1 files changed, 16 insertions, 5 deletions
diff --git a/exif.c b/exif.c
index 3747bf6..7efb6fe 100644
--- a/exif.c
+++ b/exif.c
@@ -1168,12 +1168,8 @@ char* formatStr(int format) {
// Create minimal exif header - just date and thumbnail pointers,
// so that date and thumbnail may be filled later.
//--------------------------------------------------------------------------
-void create_EXIF(ExifElement_t* elements, int exifTagCount, int gpsTagCount)
+static void create_EXIF_internal(ExifElement_t* elements, int exifTagCount, int gpsTagCount, char* Buffer)
{
- // TODO: We need to dynamically allocate this buffer and resize it when
- // necessary while writing so we don't do a buffer overflow.
- char Buffer[1024];
-
unsigned short NumEntries;
int DataWriteIndex;
int DirIndex;
@@ -1384,6 +1380,21 @@ void create_EXIF(ExifElement_t* elements, int exifTagCount, int gpsTagCount)
}
}
+void create_EXIF(ExifElement_t* elements, int exifTagCount, int gpsTagCount)
+{
+ // It is hard to calculate exact necessary size for editing the exif
+ // header dynamically, so we are using the maximum size of EXIF, 64K
+ const int EXIF_MAX_SIZE = 1024*64;
+ char* Buffer = malloc(EXIF_MAX_SIZE);
+
+ if (Buffer != NULL) {
+ create_EXIF_internal(elements, exifTagCount, gpsTagCount, Buffer);
+ free(Buffer);
+ } else {
+ ErrFatal("Could not allocate memory");
+ }
+}
+
//--------------------------------------------------------------------------
// Cler the rotation tag in the exif header to 1.
//--------------------------------------------------------------------------