1. David Soria Parra
  2. libgd 2.0

Commits

tabe  committed fa004a0

MFH: fix for FS#204

  • Participants
  • Parent commits 624a360
  • Branches GD_2_0

Comments (0)

Files changed (31)

File gd_gd.c

View file
   gdIOCtx *in;
 
   in = gdNewFileCtx (inFile);
+  if (in == NULL) return NULL;
   im = gdImageCreateFromGdCtx (in);
 
   in->gd_free (in);
 BGD_DECLARE(void) gdImageGd (gdImagePtr im, FILE * outFile)
 {
   gdIOCtx *out = gdNewFileCtx (outFile);
+  if (out == NULL) return;
   _gdImageGd (im, out);
   out->gd_free (out);
 }

File gd_gd2.c

View file
   gdIOCtx *in = gdNewFileCtx (inFile);
   gdImagePtr im;
 
+  if (in == NULL) return NULL;
   im = gdImageCreateFromGd2Ctx (in);
 
   in->gd_free (in);
   gdImagePtr im;
   gdIOCtx *in = gdNewFileCtx (inFile);
 
+  if (in == NULL) return NULL;
   im = gdImageCreateFromGd2PartCtx (in, srcx, srcy, w, h);
 
   in->gd_free (in);
 BGD_DECLARE(void) gdImageGd2 (gdImagePtr im, FILE * outFile, int cs, int fmt)
 {
   gdIOCtx *out = gdNewFileCtx (outFile);
+  if (out == NULL) return;
   _gdImageGd2 (im, out, cs, fmt);
   out->gd_free (out);
 }

File gd_gif_in.c

View file
 BGD_DECLARE(gdImagePtr) gdImageCreateFromGif(FILE *fdFile)
 {
         gdIOCtx		*fd = gdNewFileCtx(fdFile);
-        gdImagePtr    	im = 0;
+        gdImagePtr    	im;
 
+        if (fd == NULL) return NULL;
         im = gdImageCreateFromGifCtx(fd);
 
         fd->gd_free(fd);

File gd_gif_out.c

View file
 BGD_DECLARE(void) gdImageGif (gdImagePtr im, FILE * outFile)
 {
   gdIOCtx *out = gdNewFileCtx (outFile);
+  if (out == NULL) return;
   gdImageGifCtx (im, out);
   out->gd_free (out);
 }
 BGD_DECLARE(void) gdImageGifAnimBegin (gdImagePtr im, FILE *outFile, int GlobalCM, int Loops)
 {
   gdIOCtx *out = gdNewFileCtx (outFile);
+  if (out == NULL) return;
   gdImageGifAnimBeginCtx (im, out, GlobalCM, Loops);
   out->gd_free (out);
 }
 BGD_DECLARE(void) gdImageGifAnimAdd (gdImagePtr im, FILE * outFile, int LocalCM, int LeftOfs, int TopOfs, int Delay, int Disposal, gdImagePtr previm)
 {
   gdIOCtx *out = gdNewFileCtx (outFile);
+  if (out == NULL) return;
   gdImageGifAnimAddCtx (im, out, LocalCM, LeftOfs, TopOfs, Delay, Disposal, previm);
   out->gd_free (out);
 }
   putc (';', outFile);
 #else
   gdIOCtx *out = gdNewFileCtx (outFile);
+  if (out == NULL) return;
   gdImageGifAnimEndCtx (out);
   out->gd_free (out);
 #endif

File gd_io_file.c

View file
+
+/*
+   * io_file.c
+   *
+   * Implements the file interface.
+   *
+   * As will all I/O modules, most functions are for local use only (called
+   * via function pointers in the I/O context).
+   *
+   * Most functions are just 'wrappers' for standard file functions.
+   *
+   * Written/Modified 1999, Philip Warner.
+   *
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+/* For platforms with incomplete ANSI defines. Fortunately,
+   SEEK_SET is defined to be zero by the standard. */
+
+#ifndef SEEK_SET
+#define SEEK_SET 0
+#endif /* SEEK_SET */
+
+#include <math.h>
+#include <string.h>
+#include <stdlib.h>
+#include "gd.h"
+#include "gdhelpers.h"
+
+/* this is used for creating images in main memory */
+
+typedef struct fileIOCtx
+{
+  gdIOCtx ctx;
+  FILE *f;
+}
+fileIOCtx;
+
+gdIOCtx *newFileCtx (FILE * f);
+
+static int fileGetbuf (gdIOCtx *, void *, int);
+static int filePutbuf (gdIOCtx *, const void *, int);
+static void filePutchar (gdIOCtx *, int);
+static int fileGetchar (gdIOCtx * ctx);
+
+static int fileSeek (struct gdIOCtx *, const int);
+static long fileTell (struct gdIOCtx *);
+static void gdFreeFileCtx (gdIOCtx * ctx);
+
+/* return data as a dynamic pointer */
+BGD_DECLARE(gdIOCtx *) gdNewFileCtx (FILE * f)
+{
+  fileIOCtx *ctx;
+
+  if (f == NULL) return NULL;
+  ctx = (fileIOCtx *) gdMalloc (sizeof (fileIOCtx));
+  if (ctx == NULL)
+    {
+      return NULL;
+    }
+
+  ctx->f = f;
+
+  ctx->ctx.getC = fileGetchar;
+  ctx->ctx.putC = filePutchar;
+
+  ctx->ctx.getBuf = fileGetbuf;
+  ctx->ctx.putBuf = filePutbuf;
+
+  ctx->ctx.tell = fileTell;
+  ctx->ctx.seek = fileSeek;
+
+  ctx->ctx.gd_free = gdFreeFileCtx;
+
+  return (gdIOCtx *) ctx;
+}
+
+static void
+gdFreeFileCtx (gdIOCtx * ctx)
+{
+  gdFree (ctx);
+}
+
+
+static int
+filePutbuf (gdIOCtx * ctx, const void *buf, int size)
+{
+  fileIOCtx *fctx;
+  fctx = (fileIOCtx *) ctx;
+
+  return fwrite (buf, 1, size, fctx->f);
+
+}
+
+static int
+fileGetbuf (gdIOCtx * ctx, void *buf, int size)
+{
+  fileIOCtx *fctx;
+  fctx = (fileIOCtx *) ctx;
+
+  return (fread (buf, 1, size, fctx->f));
+
+}
+
+static void
+filePutchar (gdIOCtx * ctx, int a)
+{
+  unsigned char b;
+  fileIOCtx *fctx;
+  fctx = (fileIOCtx *) ctx;
+
+  b = a;
+
+  putc (b, fctx->f);
+}
+
+static int
+fileGetchar (gdIOCtx * ctx)
+{
+  fileIOCtx *fctx;
+  fctx = (fileIOCtx *) ctx;
+
+  return getc (fctx->f);
+}
+
+
+static int
+fileSeek (struct gdIOCtx *ctx, const int pos)
+{
+  fileIOCtx *fctx;
+  fctx = (fileIOCtx *) ctx;
+  return (fseek (fctx->f, pos, SEEK_SET) == 0);
+}
+
+static long
+fileTell (struct gdIOCtx *ctx)
+{
+  fileIOCtx *fctx;
+  fctx = (fileIOCtx *) ctx;
+
+  return ftell (fctx->f);
+}

File gd_jpeg.c

View file
 BGD_DECLARE(void) gdImageJpeg (gdImagePtr im, FILE * outFile, int quality)
 {
   gdIOCtx *out = gdNewFileCtx (outFile);
+  if (out == NULL) return;
   gdImageJpegCtx (im, out, quality);
   out->gd_free (out);
 }
 {
   gdImagePtr im;
   gdIOCtx *in = gdNewFileCtx (inFile);
+  if (in == NULL) return NULL;
   im = gdImageCreateFromJpegCtx (in);
   in->gd_free (in);
   return im;

File gd_png.c

View file
 {
   gdImagePtr im;
   gdIOCtx *in = gdNewFileCtx (inFile);
+  if (in == NULL) return NULL;
   im = gdImageCreateFromPngCtx (in);
   in->gd_free (in);
   return im;
 BGD_DECLARE(void) gdImagePngEx (gdImagePtr im, FILE * outFile, int level)
 {
   gdIOCtx *out = gdNewFileCtx (outFile);
+  if (out == NULL) return;
   gdImagePngCtxEx (im, out, level);
   out->gd_free (out);
 }
 BGD_DECLARE(void) gdImagePng (gdImagePtr im, FILE * outFile)
 {
   gdIOCtx *out = gdNewFileCtx (outFile);
+  if (out == NULL) return;
   gdImagePngCtxEx (im, out, -1);
   out->gd_free (out);
 }

File gd_wbmp.c

View file
 {
   gdImagePtr im;
   gdIOCtx *in = gdNewFileCtx (inFile);
+  if (in == NULL) return NULL;
   im = gdImageCreateFromWBMPCtx (in);
   in->gd_free (in);
   return (im);
 BGD_DECLARE(void) gdImageWBMP (gdImagePtr im, int fg, FILE * outFile)
 {
   gdIOCtx *out = gdNewFileCtx (outFile);
+  if (out == NULL) return;
   gdImageWBMPCtx (im, fg, out);
   out->gd_free (out);
 }

File tests/CMakeLists.txt

View file
 	SET(TESTS_DIRS
 		gdtest
 		freetype
+		gd
 		gd2
 		gdimagearc
 		gdimagecolorclosest
 		gdimagesetpixel
 		gdimagestringft
 		gdimagestringftex
+		gdnewfilectx
 		gdtiled
 		gif
 		jpeg
 		png
+		wbmp
 		xpm
 	)
 

File tests/Makefile.am

View file
 
 SUBDIRS = gdtest \
 		freetype \
+		gd \
 		gd2 \
 		gdimagearc \
 		gdimagecolorclosest \
 		gdimagesetpixel \
 		gdimagestringft \
 		gdimagestringftex \
+		gdnewfilectx \
 		gdtiled \
 		gif \
 		jpeg \
 		png \
+		wbmp \
 		xpm
 
 EXTRA_DIST = CMakeLists.txt

File tests/gd/CMakeLists.txt

View file
+
+SET(TESTS_FILES
+	gd_null
+)
+
+FOREACH(test_name ${TESTS_FILES})
+	add_executable(${test_name} "${test_name}.c")
+	target_link_libraries (${test_name} gdTest ${GD_LIB})
+	get_target_property(test_path ${test_name} LOCATION)
+	ADD_TEST(${test_name} ${test_path})
+ENDFOREACH(test_name)

File tests/gd/Makefile.am

View file
+## Process this file with automake to produce Makefile.in -*-Makefile-*-
+
+EXTRA_DIST = CMakeLists.txt gd_null.c

File tests/gd/gd_null.c

View file
+#include <gd.h>
+
+int main()
+{
+	gdImagePtr im;
+
+	im = gdImageCreateFromGd(NULL);
+	if (im != NULL) {
+		gdImageDestroy(im);
+		return 1;
+	}
+	gdImageGd(im, NULL); /* noop safely */
+	return 0;
+}

File tests/gd2/CMakeLists.txt

View file
 SET(TESTS_FILES
 	gd2_read
 	gd2_empty_file
+	gd2_null
 )
 
 FOREACH(test_name ${TESTS_FILES})

File tests/gd2/Makefile.am

View file
 ## Process this file with automake to produce Makefile.in -*-Makefile-*-
 
-EXTRA_DIST = CMakeLists.txt  conv_gd2_exp.gd2  conv_test_exp.png  conv_test.gd2  empty.gd2  gd2_empty_file.c  gd2_read.c 
+EXTRA_DIST = CMakeLists.txt conv_gd2_exp.gd2 conv_test_exp.png conv_test.gd2 empty.gd2 gd2_empty_file.c gd2_read.c gd2_null.c
 

File tests/gd2/gd2_null.c

View file
+#include <gd.h>
+
+int main()
+{
+	gdImagePtr im;
+
+	im = gdImageCreateFromGd2(NULL);
+	if (im != NULL) {
+		gdImageDestroy(im);
+		return 1;
+	}
+	gdImageGd2(im, NULL, 0, GD2_FMT_RAW); /* noop safely */
+	return 0;
+}

File tests/gdnewfilectx/CMakeLists.txt

View file
+SET(TESTS_FILES
+	gdnewfilectx_null
+)
+
+FOREACH(test_name ${TESTS_FILES})
+	add_executable(${test_name} "${test_name}.c")
+	target_link_libraries (${test_name} gdTest ${GD_LIB})
+	get_target_property(test_path ${test_name} LOCATION)
+	ADD_TEST(${test_name} ${test_path})
+ENDFOREACH(test_name)

File tests/gdnewfilectx/Makefile.am

View file
+## Process this file with automake to produce Makefile.in -*-Makefile-*-
+
+EXTRA_DIST = CMakeLists.txt gdnewfilectx_null.c

File tests/gdnewfilectx/gdnewfilectx_null.c

View file
+#include <gd.h>
+
+int main()
+{
+	if (gdNewFileCtx(NULL) != NULL) return 1;
+	return 0;
+}

File tests/gif/CMakeLists.txt

View file
 
 SET(TESTS_FILES
+	gif_null
 	bug00005
 	bug00005_2
 	bug00006

File tests/gif/Makefile.am

View file
 ## Process this file with automake to produce Makefile.in -*-Makefile-*-
 
-EXTRA_DIST = CMakeLists.txt bug00005_0.gif bug00005_2.c bug00005_2.gif bug00005.c bug00060.c bug00066.c bug00066.gif bug00005_1.gif  bug00005_2_exp.png  bug00005_3.gif  bug00006.c  bug00060.gif  bug00066_exp.png bug00181.c
+EXTRA_DIST = CMakeLists.txt gif_null.c bug00005_0.gif bug00005_2.c bug00005_2.gif bug00005.c bug00060.c bug00066.c bug00066.gif bug00005_1.gif  bug00005_2_exp.png  bug00005_3.gif  bug00006.c  bug00060.gif  bug00066_exp.png bug00181.c

File tests/gif/gif_null.c

View file
+#include <gd.h>
+
+int main()
+{
+	gdImagePtr im;
+
+	im = gdImageCreateFromGif(NULL);
+	if (im != NULL) {
+		gdImageDestroy(im);
+		return 1;
+	}
+	gdImageGif(im, NULL); /* noop safely */
+	return 0;
+}

File tests/jpeg/CMakeLists.txt

View file
 SET(TESTS_FILES
 	jpeg_read
 	jpeg_empty_file
+	jpeg_null
 )
 
 FOREACH(test_name ${TESTS_FILES})

File tests/jpeg/Makefile.am

View file
 ## Process this file with automake to produce Makefile.in -*-Makefile-*-
 
-EXTRA_DIST = CMakeLists.txt conv_test_exp.png conv_test.jpeg empty.jpeg jpeg_empty_file.c jpeg_read.c
+EXTRA_DIST = CMakeLists.txt conv_test_exp.png conv_test.jpeg empty.jpeg jpeg_empty_file.c jpeg_null.c jpeg_read.c

File tests/jpeg/jpeg_null.c

View file
+#include <gd.h>
+
+int main()
+{
+	gdImagePtr im;
+
+	im = gdImageCreateFromJpeg(NULL);
+	if (im != NULL) {
+		gdImageDestroy(im);
+		return 1;
+	}
+	gdImageJpeg(im, NULL, 100); /* noop safely */
+	return 0;
+}

File tests/png/CMakeLists.txt

View file
 
 SET(TESTS_FILES
+	png_null
 	bug00011
 	bug00033
 	bug00086

File tests/png/Makefile.am

View file
 ## Process this file with automake to produce Makefile.in -*-Makefile-*-
 
-EXTRA_DIST = CMakeLists.txt bug00011.c bug00033.png bug00088_1_exp.png bug00088_2_exp.png bug00088.c bug00033.c bug00086.c bug00088_1.png bug00088_2.png bug00193.c emptyfile
+EXTRA_DIST = CMakeLists.txt png_null.c bug00011.c bug00033.png bug00088_1_exp.png bug00088_2_exp.png bug00088.c bug00033.c bug00086.c bug00088_1.png bug00088_2.png bug00193.c emptyfile

File tests/png/png_null.c

View file
+#include <gd.h>
+
+int main()
+{
+	gdImagePtr im;
+
+	im = gdImageCreateFromPng(NULL);
+	if (im != NULL) {
+		gdImageDestroy(im);
+		return 1;
+	}
+	gdImagePng(im, NULL); /* noop safely */
+	return 0;
+}

File tests/wbmp/CMakeLists.txt

View file
+
+SET(TESTS_FILES
+	wbmp_null
+)
+
+FOREACH(test_name ${TESTS_FILES})
+	add_executable(${test_name} "${test_name}.c")
+	target_link_libraries (${test_name} gdTest ${GD_LIB})
+	get_target_property(test_path ${test_name} LOCATION)
+	ADD_TEST(${test_name} ${test_path})
+ENDFOREACH(test_name)

File tests/wbmp/Makefile.am

View file
+## Process this file with automake to produce Makefile.in -*-Makefile-*-
+
+EXTRA_DIST = CMakeLists.txt wbmp_null.c

File tests/wbmp/wbmp_null.c

View file
+#include <gd.h>
+
+int main()
+{
+	gdImagePtr im;
+
+	im = gdImageCreateFromWBMP(NULL);
+	if (im != NULL) {
+		gdImageDestroy(im);
+		return 1;
+	}
+	gdImageWBMP(im, 0, NULL); /* noop safely */
+	return 0;
+}