png_ptr->palette = (png_colorp)png_zalloc(png_ptr, (uInt)256, sizeof (png_color)); if (png_ptr->palette == NULL) png_error(png_ptr, "Unable to malloc palette"); png_memcpy(png_ptr->palette, palette, num_palette * sizeof (png_color));
png_ptr->palette = (png_colorp)png_malloc(png_ptr, 256 * png_sizeof(png_color)); png_memset(png_ptr->palette, 0, 256 * png_sizeof(png_color)); png_memcpy(png_ptr->palette, palette, num_palette * png_sizeof (png_color));
png_set_PLTE(png_structp png_ptr, png_infop info_ptr,   png_colorp palette, int num_palette){   png_debug1(1, "in %s storage function\n", "PLTE");   if (png_ptr == NULL || info_ptr == NULL)      return;   /*    * It may not actually be necessary to set png_ptr->palette here;    * we do it for backward compatibility with the way the png_handle_tRNS    * function used to do the allocation.    */#ifdef PNG_FREE_ME_SUPPORTED   png_free_data(png_ptr, info_ptr, PNG_FREE_PLTE, 0);#endif   /* Changed in libpng-1.2.1 to allocate 256 instead of num_palette entries,      in case of an invalid PNG file that has too-large sample values. */   png_ptr->palette = (png_colorp)png_zalloc(png_ptr, (uInt)256,      sizeof (png_color));   if (png_ptr->palette == NULL)      png_error(png_ptr, "Unable to malloc palette");   png_memcpy(png_ptr->palette, palette, num_palette * sizeof (png_color));   info_ptr->palette = png_ptr->palette;   info_ptr->num_palette = png_ptr->num_palette = (png_uint_16)num_palette;#ifdef PNG_FREE_ME_SUPPORTED   info_ptr->free_me |= PNG_FREE_PLTE;#else   png_ptr->flags |= PNG_FLAG_FREE_PLTE;#endif   info_ptr->valid |= PNG_INFO_PLTE;}