summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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.
//--------------------------------------------------------------------------