Skip to content

Commit

Permalink
formats: setjmp
Browse files Browse the repository at this point in the history
  • Loading branch information
mrannanj committed Dec 9, 2024
1 parent 197bed4 commit 196d640
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions src/formats/vga_image.c
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,6 @@ int sd_vga_image_decode(sd_rgba_image *dst, const sd_vga_image *src, const vga_p
}

int sd_vga_image_from_png(sd_vga_image *img, const char *filename) {
png_structp png_ptr;
png_infop info_ptr;
int ret = SD_SUCCESS;
int got = 0;
png_bytep *row_pointers;
Expand All @@ -86,19 +84,20 @@ int sd_vga_image_from_png(sd_vga_image *img, const char *filename) {
goto error_1;
}

png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
png_structp png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
if(!png_ptr) {
ret = SD_OUT_OF_MEMORY;
goto error_1;
}

info_ptr = png_create_info_struct(png_ptr);
png_infop info_ptr = png_create_info_struct(png_ptr);
if(!info_ptr) {
ret = SD_OUT_OF_MEMORY;
goto error_2;
}

if(setjmp(png_jmpbuf(png_ptr))) {
png_destroy_read_struct(&png_ptr, &info_ptr, NULL);
ret = SD_FILE_INVALID_TYPE;
goto error_2;
}
Expand Down Expand Up @@ -129,6 +128,7 @@ int sd_vga_image_from_png(sd_vga_image *img, const char *filename) {
}

if(setjmp(png_jmpbuf(png_ptr))) {
png_destroy_read_struct(&png_ptr, &info_ptr, NULL);
ret = SD_FILE_INVALID_TYPE;
goto error_3;
}
Expand All @@ -154,7 +154,6 @@ int sd_vga_image_from_png(sd_vga_image *img, const char *filename) {
}
omf_free(row_pointers);
error_2:
png_destroy_read_struct(&png_ptr, NULL, NULL);
error_1:
fclose(handle);
error_0:
Expand Down

0 comments on commit 196d640

Please sign in to comment.