Mercurial > hg > dmlib
comparison src/libgfx.c @ 858:e7019bd83cca
Fix potential longjmp clobbering of variable.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Fri, 21 Nov 2014 17:37:25 +0200 |
parents | 9623b9b548d4 |
children | c6c480e8e1c8 |
comparison
equal
deleted
inserted
replaced
857:16aa5955dfb5 | 858:e7019bd83cca |
---|---|
367 | 367 |
368 int dmWritePNGImageFILE(FILE *fp, DMImage *img, DMImageSpec *spec) | 368 int dmWritePNGImageFILE(FILE *fp, DMImage *img, DMImageSpec *spec) |
369 { | 369 { |
370 png_structp png_ptr = NULL; | 370 png_structp png_ptr = NULL; |
371 png_infop info_ptr = NULL; | 371 png_infop info_ptr = NULL; |
372 png_colorp palette = NULL; | |
373 int fmt, res = DMERR_OK; | 372 int fmt, res = DMERR_OK; |
374 | 373 |
375 // Create PNG structures | 374 // Create PNG structures |
376 png_ptr = png_create_write_struct( | 375 png_ptr = png_create_write_struct( |
377 PNG_LIBPNG_VER_STRING, | 376 PNG_LIBPNG_VER_STRING, |
429 | 428 |
430 // Palette | 429 // Palette |
431 if (spec->format == DM_IFMT_PALETTE) | 430 if (spec->format == DM_IFMT_PALETTE) |
432 { | 431 { |
433 int i; | 432 int i; |
434 | 433 png_colorp palette = png_malloc(png_ptr, PNG_MAX_PALETTE_LENGTH * sizeof(png_color)); |
435 palette = png_malloc(png_ptr, PNG_MAX_PALETTE_LENGTH * sizeof(png_color)); | 434 |
436 if (palette == NULL) | 435 if (palette == NULL) |
437 { | 436 { |
438 dmError("PNG: Could not allocate palette structure."); | 437 dmError("PNG: Could not allocate palette structure."); |
439 res = DMERR_MALLOC; | 438 res = DMERR_MALLOC; |
440 goto error; | 439 goto error; |
462 | 461 |
463 // Write footer | 462 // Write footer |
464 png_write_end(png_ptr, NULL); | 463 png_write_end(png_ptr, NULL); |
465 | 464 |
466 error: | 465 error: |
467 png_free(png_ptr, palette); | 466 if (info_ptr->palette) |
468 palette = NULL; | 467 png_free(png_ptr, info_ptr->palette); |
469 | 468 |
470 if (png_ptr && info_ptr) | 469 if (png_ptr && info_ptr) |
471 png_destroy_write_struct(&png_ptr, &info_ptr); | 470 png_destroy_write_struct(&png_ptr, &info_ptr); |
472 | 471 |
473 return res; | 472 return res; |