Skip to content

Commit

Permalink
replaced realloc and removed stderr
Browse files Browse the repository at this point in the history
  • Loading branch information
golsch committed Aug 29, 2020
1 parent 9ed6427 commit 67f00fd
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 326 deletions.
19 changes: 0 additions & 19 deletions src/gd.c
Original file line number Diff line number Diff line change
Expand Up @@ -75,25 +75,6 @@ extern const int gdSinT[];

void gd_stderr_error(int priority, const char *format, va_list args)
{
switch (priority) {
case GD_ERROR:
fputs("GD Error: ", stderr);
break;
case GD_WARNING:
fputs("GD Warning: ", stderr);
break;
case GD_NOTICE:
fputs("GD Notice: ", stderr);
break;
case GD_INFO:
fputs("GD Info: ", stderr);
break;
case GD_DEBUG:
fputs("GD Debug: ", stderr);
break;
}
vfprintf(stderr, format, args);
fflush(stderr);
}

static gdErrorMethod gd_error_method = gd_stderr_error;
Expand Down
10 changes: 1 addition & 9 deletions src/gd_intern.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,7 @@
# endif
#endif

#ifdef HAVE_STDINT_H
# include <stdint.h>
#else
# if defined(HAVE_INTTYPES_H)
# include <inttypes.h>
# else
# include "msinttypes/inttypes.h"
# endif
#endif
#include <stdint.h>

#include "gd.h"

Expand Down
23 changes: 22 additions & 1 deletion src/gdhelpers.c
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,31 @@ gdMalloc (size_t size)
return malloc (size);
}


size_t
getsize(void * p) {
size_t * in = p;
if (in) {
--in;
return *in;
}
return -1;
}


void *
gdRealloc (void *ptr, size_t size)
{
return realloc (ptr, size);
void *newptr;
int msize;
msize = getsize(ptr);
if (size <= msize) {
return ptr;
}
newptr = malloc(size);
memcpy(newptr, ptr, msize);
free(ptr);
return newptr;
}

void *
Expand Down
8 changes: 4 additions & 4 deletions src/gdtest.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,12 @@ main (int argc, char **argv)
int foreground;
int i;
if (argc != 2) {
fprintf(stderr, "Usage: gdtest filename.png\n");
printf("Usage: gdtest filename.png\n");
exit (1);
}
in = fopen (argv[1], "rb");
if (!in) {
fprintf(stderr, "Input file does not exist!\n");
printf("Input file does not exist!\n");
exit (1);
}
im = gdImageCreateFromPng (in);
Expand All @@ -50,11 +50,11 @@ main (int argc, char **argv)

fclose (in);
if (!im) {
fprintf(stderr, "gdImageCreateFromPng failed.\n");
printf("gdImageCreateFromPng failed.\n");
exit (1);
}
if (!ref) {
fprintf(stderr, "gdImageCreateFromPng failed.\n");
printf("gdImageCreateFromPng failed.\n");
exit (1);
}

Expand Down
293 changes: 0 additions & 293 deletions src/webpng.c

This file was deleted.

0 comments on commit 67f00fd

Please sign in to comment.