diff options
author | Robin Watts <robin.watts@artifex.com> | 2016-01-04 14:14:35 +0000 |
---|---|---|
committer | Robin Watts <robin.watts@artifex.com> | 2016-01-04 14:14:58 +0000 |
commit | 7795f0f1f8700651d2a79f979a5d40885569dd11 (patch) | |
tree | c35ff0edd79a34e46350db4b34d7766099e72f60 /base | |
parent | 998c8bf7a2e409b6c4c29b8e535028a24404e7c5 (diff) | |
download | ghostpdl-7795f0f1f8700651d2a79f979a5d40885569dd11.tar.gz |
Squash warnings: ICC code.
Various bits of the ICC code collects return values only to not
check them. Fix that here.
In some cases this is because functions have a 'void' return type
so there isn't a way to return an error. Change those return types
and ensure that all callers check and propogate the errors.
Diffstat (limited to 'base')
-rw-r--r-- | base/gdevdevn.c | 5 | ||||
-rw-r--r-- | base/gscms.h | 16 | ||||
-rw-r--r-- | base/gsdevice.c | 4 | ||||
-rw-r--r-- | base/gsequivc.c | 21 | ||||
-rw-r--r-- | base/gsequivc.h | 2 | ||||
-rw-r--r-- | base/gsicc_cache.c | 61 | ||||
-rw-r--r-- | base/gsicc_cache.h | 2 | ||||
-rw-r--r-- | base/gsicc_cms.h | 18 | ||||
-rw-r--r-- | base/gsicc_lcms.c | 4 | ||||
-rw-r--r-- | base/gsicc_lcms2.c | 13 | ||||
-rw-r--r-- | base/gsicc_manage.c | 49 | ||||
-rw-r--r-- | base/gsicc_monitorcm.c | 118 | ||||
-rw-r--r-- | base/gsicc_nocm.c | 7 | ||||
-rw-r--r-- | base/gsicc_replacecm.c | 9 | ||||
-rw-r--r-- | base/gspaint.c | 2 | ||||
-rw-r--r-- | base/gxclimag.c | 10 |
16 files changed, 216 insertions, 125 deletions
diff --git a/base/gdevdevn.c b/base/gdevdevn.c index 66a459c99..029de40f7 100644 --- a/base/gdevdevn.c +++ b/base/gdevdevn.c @@ -1142,9 +1142,8 @@ gx_devn_prn_update_spot_equivalent_colors(gx_device *dev, const gs_state * pgs) { gx_devn_prn_device *pdev = (gx_devn_prn_device *)dev; - update_spot_equivalent_cmyk_colors(dev, pgs, &pdev->devn_params, - &pdev->equiv_cmyk_colors); - return 0; + return update_spot_equivalent_cmyk_colors(dev, pgs, &pdev->devn_params, + &pdev->equiv_cmyk_colors); } /* diff --git a/base/gscms.h b/base/gscms.h index c05d64f57..ed08d0360 100644 --- a/base/gscms.h +++ b/base/gscms.h @@ -98,14 +98,14 @@ typedef struct gsicc_bufferdesc_s { /* Mapping procedures to allow easy vectoring depending upon if we are using the CMM or doing "dumb" color transforms */ -typedef void (*gscms_trans_color_proc_t) (gx_device * dev, gsicc_link_t *icclink, - void *inputcolor, void *outputcolor, - int num_bytes); - -typedef void (*gscms_trans_buffer_proc_t) (gx_device * dev, gsicc_link_t *icclink, - gsicc_bufferdesc_t *input_buff_desc, - gsicc_bufferdesc_t *output_buff_desc, - void *inputbuffer, void *outputbuffer); +typedef int (*gscms_trans_color_proc_t) (gx_device * dev, gsicc_link_t *icclink, + void *inputcolor, void *outputcolor, + int num_bytes); + +typedef int (*gscms_trans_buffer_proc_t) (gx_device * dev, gsicc_link_t *icclink, + gsicc_bufferdesc_t *input_buff_desc, + gsicc_bufferdesc_t *output_buff_desc, + void *inputbuffer, void *outputbuffer); typedef void (*gscms_link_free_proc_t) (gsicc_link_t *icclink); diff --git a/base/gsdevice.c b/base/gsdevice.c index 81e339cdb..362d0f562 100644 --- a/base/gsdevice.c +++ b/base/gsdevice.c @@ -207,9 +207,11 @@ gs_output_page(gs_state * pgs, int num_copies, int flush) return code; code = dev_proc(dev, get_profile)(dev, &(dev_profile)); + if (code < 0) + return code; if (dev_profile->graydetection && !dev_profile->pageneutralcolor) { dev_profile->pageneutralcolor = true; /* start detecting again */ - gsicc_mcm_begin_monitor(pgs->icc_link_cache, dev); + code = gsicc_mcm_begin_monitor(pgs->icc_link_cache, dev); } return code; } diff --git a/base/gsequivc.c b/base/gsequivc.c index 5fab64ea2..abbb37db0 100644 --- a/base/gsequivc.c +++ b/base/gsequivc.c @@ -152,7 +152,7 @@ update_Separation_spot_equivalent_cmyk_colors(gx_device * pdev, /* This is used for getting the equivalent CMYK values for the spots that may exist in a DeviceN output ICC profile */ -static void +static int update_ICC_spot_equivalent_cmyk_colors(gx_device * pdev, const gs_state * pgs, const gs_color_space * pcs, gs_devn_params * pdevn_params, @@ -165,6 +165,8 @@ update_ICC_spot_equivalent_cmyk_colors(gx_device * pdev, code = dev_proc(pdev, get_profile)(pdev, &dev_profile); + if (code < 0) + return code; /* * Check if the ICC spot names matche any of the * separations for which we need an equivalent CMYK color. @@ -197,6 +199,7 @@ update_ICC_spot_equivalent_cmyk_colors(gx_device * pdev, } } } + return 0; } static void @@ -281,7 +284,7 @@ static bool check_all_colors_known(int num_spot, } /* If possible, update the equivalent CMYK color for a spot color */ -void +int update_spot_equivalent_cmyk_colors(gx_device * pdev, const gs_state * pgs, gs_devn_params * pdevn_params, equivalent_cmyk_color_params * pparams) { @@ -291,16 +294,16 @@ update_spot_equivalent_cmyk_colors(gx_device * pdev, const gs_state * pgs, code = dev_proc(pdev, get_profile)(pdev, &dev_profile); if (code < 0) - return; + return code; /* If all of the color_info is valid then there is nothing to do. */ if (pparams->all_color_info_valid) - return; + return 0; /* Verify that we really have some separations. */ if (pdevn_params->separations.num_separations == 0) { pparams->all_color_info_valid = true; - return; + return 0; } /* * Verify that the given color space is a Separation or a DeviceN color @@ -324,12 +327,16 @@ update_spot_equivalent_cmyk_colors(gx_device * pdev, const gs_state * pgs, dev_profile->spotnames != NULL) { /* In this case, we are trying to set up the equivalent colors for the spots in the output ICC profile */ - update_ICC_spot_equivalent_cmyk_colors(pdev, pgs, pcs, pdevn_params, - pparams); + code = update_ICC_spot_equivalent_cmyk_colors(pdev, pgs, pcs, + pdevn_params, + pparams); + if (code < 0) + return code; pparams->all_color_info_valid = check_all_colors_known (pdevn_params->separations.num_separations, pparams); } } + return 0; } static void diff --git a/base/gsequivc.h b/base/gsequivc.h index ebd50fb49..7a7a1e5ac 100644 --- a/base/gsequivc.h +++ b/base/gsequivc.h @@ -48,7 +48,7 @@ typedef struct equivalent_cmyk_color_params_s { /* * If possible, update the equivalent CMYK color for spot colors. */ -void update_spot_equivalent_cmyk_colors(gx_device * pdev, +int update_spot_equivalent_cmyk_colors(gx_device * pdev, const gs_state * pgs, gs_devn_params * pdevn_params, equivalent_cmyk_color_params * pparams); diff --git a/base/gsicc_cache.c b/base/gsicc_cache.c index a17b9f1dd..9eee24316 100644 --- a/base/gsicc_cache.c +++ b/base/gsicc_cache.c @@ -50,18 +50,18 @@ static gsicc_link_t * gsicc_alloc_link(gs_memory_t *memory, gsicc_hashlink_t hashcode); -static void gsicc_get_cspace_hash(gsicc_manager_t *icc_manager, gx_device *dev, - cmm_profile_t *profile, int64_t *hash); +static int gsicc_get_cspace_hash(gsicc_manager_t *icc_manager, gx_device *dev, + cmm_profile_t *profile, int64_t *hash); -static void gsicc_compute_linkhash(gsicc_manager_t *icc_manager, gx_device *dev, - cmm_profile_t *input_profile, - cmm_profile_t *output_profile, - gsicc_rendering_param_t *rendering_params, - gsicc_hashlink_t *hash); +static int gsicc_compute_linkhash(gsicc_manager_t *icc_manager, gx_device *dev, + cmm_profile_t *input_profile, + cmm_profile_t *output_profile, + gsicc_rendering_param_t *rendering_params, + gsicc_hashlink_t *hash); static gsicc_link_t* gsicc_find_zeroref_cache(gsicc_link_cache_t *icc_link_cache); -static void gsicc_remove_link(gsicc_link_t *link, gs_memory_t *memory); +static void gsicc_remove_link(gsicc_link_t *link, const gs_memory_t *memory); static void gsicc_get_buff_hash(unsigned char *data, int64_t *hash, unsigned int num_bytes); @@ -324,7 +324,7 @@ gsicc_link_free_contents(gsicc_link_t *icc_link) } void -gsicc_link_free(gsicc_link_t *icc_link, gs_memory_t *memory) +gsicc_link_free(gsicc_link_t *icc_link, const gs_memory_t *memory) { gsicc_link_free_contents(icc_link); @@ -398,16 +398,24 @@ gsicc_get_buff_hash(unsigned char *data, int64_t *hash, unsigned int num_bytes) This just computes a 64bit xor of upper and lower portions of md5 for the input, output and rendering params structure. We may change this later */ -static void +static int gsicc_compute_linkhash(gsicc_manager_t *icc_manager, gx_device *dev, cmm_profile_t *input_profile, cmm_profile_t *output_profile, gsicc_rendering_param_t *rendering_params, gsicc_hashlink_t *hash) { - /* first get the hash codes for the color spaces */ - gsicc_get_cspace_hash(icc_manager, dev, input_profile, &(hash->src_hash)); - gsicc_get_cspace_hash(icc_manager, dev, output_profile, &(hash->des_hash)); + int code; + + /* first get the hash codes for the color spaces */ + code = gsicc_get_cspace_hash(icc_manager, dev, input_profile, + &(hash->src_hash)); + if (code < 0) + return code; + code = gsicc_get_cspace_hash(icc_manager, dev, output_profile, + &(hash->des_hash)); + if (code < 0) + return code; /* now for the rendering paramaters, just use the word itself. At this point in time, we only include the black point setting, the intent @@ -419,11 +427,12 @@ gsicc_compute_linkhash(gsicc_manager_t *icc_manager, gx_device *dev, hash->rend_hash = ((rendering_params->black_point_comp) << BP_SHIFT) + ((rendering_params->rendering_intent) << REND_SHIFT) + ((rendering_params->preserve_black) << PRESERVE_SHIFT); - /* for now, mash all of these into a link hash */ - gsicc_mash_hash(hash); + /* for now, mash all of these into a link hash */ + gsicc_mash_hash(hash); + return 0; } -static void +static int gsicc_get_cspace_hash(gsicc_manager_t *icc_manager, gx_device *dev, cmm_profile_t *cmm_icc_profile_data, int64_t *hash) { @@ -434,22 +443,23 @@ gsicc_get_cspace_hash(gsicc_manager_t *icc_manager, gx_device *dev, if (cmm_icc_profile_data == NULL ) { code = dev_proc(dev, get_profile)(dev, &dev_profile); + if (code < 0) + return code; gsicc_extract_profile(dev->graphics_type_tag, dev_profile, &(icc_profile), &render_cond); *hash = icc_profile->hashcode; - return; + return 0; } if (cmm_icc_profile_data->hash_is_valid ) { *hash = cmm_icc_profile_data->hashcode; - return; } else { /* We need to compute for this color space */ gsicc_get_icc_buff_hash(cmm_icc_profile_data->buffer, hash, cmm_icc_profile_data->buffer_size); cmm_icc_profile_data->hashcode = *hash; cmm_icc_profile_data->hash_is_valid = true; - return; } + return 0; } gsicc_link_t* @@ -527,7 +537,7 @@ gsicc_find_zeroref_cache(gsicc_link_cache_t *icc_link_cache) /* Remove link from cache. Notify CMS and free */ static void -gsicc_remove_link(gsicc_link_t *link, gs_memory_t *memory) +gsicc_remove_link(gsicc_link_t *link, const gs_memory_t *memory) { gsicc_link_t *curr, *prev; gsicc_link_cache_t *icc_link_cache = link->icc_link_cache; @@ -594,6 +604,8 @@ gsicc_get_link(const gs_imager_state *pis, gx_device *dev_in, gs_input_profile = input_colorspace->cmm_icc_profile_data; } code = dev_proc(dev, get_profile)(dev, &dev_profile); + if (code < 0) + return NULL; /* If present, use an graphic object defined source profile */ if (pis->icc_manager != NULL && pis->icc_manager->srcgtag_profile != NULL) { @@ -824,6 +836,8 @@ gsicc_get_link_profile(const gs_imager_state *pis, gx_device *dev, /* Determine if we are using a soft proof or device link profile */ if (dev != NULL ) { code = dev_proc(dev, get_profile)(dev, &dev_profile); + if (code < 0) + return NULL; if (dev_profile != NULL) { proof_profile = dev_profile->proof_profile; devlink_profile = dev_profile->link_profile; @@ -844,8 +858,11 @@ gsicc_get_link_profile(const gs_imager_state *pis, gx_device *dev, } /* First compute the hash code for the incoming case. If the output color space is NULL we will use the device profile for the output color space */ - gsicc_compute_linkhash(icc_manager, dev, gs_input_profile, gs_output_profile, - rendering_params, &hash); + code = gsicc_compute_linkhash(icc_manager, dev, gs_input_profile, + gs_output_profile, + rendering_params, &hash); + if (code < 0) + return NULL; /* Check the cache for a hit. Need to check if softproofing was used */ found_link = gsicc_findcachelink(hash, icc_link_cache, include_softproof, include_devicelink); diff --git a/base/gsicc_cache.h b/base/gsicc_cache.h index 9cc0495a3..955ae31ec 100644 --- a/base/gsicc_cache.h +++ b/base/gsicc_cache.h @@ -57,7 +57,7 @@ gsicc_link_t* gsicc_get_link_profile(const gs_imager_state *pis, gx_device *dev, gsicc_rendering_param_t *rendering_params, gs_memory_t *memory, bool devicegraytok); void gsicc_release_link(gsicc_link_t *icclink); -void gsicc_link_free(gsicc_link_t *icc_link, gs_memory_t *memory); +void gsicc_link_free(gsicc_link_t *icc_link, const gs_memory_t *memory); void gsicc_get_icc_buff_hash(unsigned char *buffer, int64_t *hash, unsigned int buff_size); int64_t gsicc_get_hash(cmm_profile_t *profile); int gsicc_transform_named_color(const float tint_values[], diff --git a/base/gsicc_cms.h b/base/gsicc_cms.h index bf07601c9..cf6cb5f6e 100644 --- a/base/gsicc_cms.h +++ b/base/gsicc_cms.h @@ -37,8 +37,8 @@ bool gsicc_mcm_monitor_rgb(void *inputcolor, int num_bytes); bool gsicc_mcm_monitor_cmyk(void *inputcolor, int num_bytes); bool gsicc_mcm_monitor_lab(void *inputcolor, int num_bytes); void gsicc_mcm_set_link(gsicc_link_t* link); -void gsicc_mcm_end_monitor(gsicc_link_cache_t *cache, gx_device *dev); -void gsicc_mcm_begin_monitor(gsicc_link_cache_t *cache, gx_device *dev); +int gsicc_mcm_end_monitor(gsicc_link_cache_t *cache, gx_device *dev); +int gsicc_mcm_begin_monitor(gsicc_link_cache_t *cache, gx_device *dev); gsicc_link_t* gsicc_rcm_get_link(const gs_imager_state *pis, gx_device *dev, gsicc_colorbuffer_t data_cs); gsicc_link_t* gsicc_nocm_get_link(const gs_imager_state *pis, gx_device *dev, @@ -48,11 +48,11 @@ gcmmhprofile_t gscms_get_profile_handle_mem(gs_memory_t *mem, unsigned int input_size); gcmmhprofile_t gscms_get_profile_handle_file(gs_memory_t *mem, const char *filename); -void gscms_transform_color_buffer(gx_device *dev, gsicc_link_t *icclink, - gsicc_bufferdesc_t *input_buff_desc, - gsicc_bufferdesc_t *output_buff_desc, - void *inputbuffer, - void *outputbuffer); +int gscms_transform_color_buffer(gx_device *dev, gsicc_link_t *icclink, + gsicc_bufferdesc_t *input_buff_desc, + gsicc_bufferdesc_t *output_buff_desc, + void *inputbuffer, + void *outputbuffer); int gscms_get_channel_count(gcmmhprofile_t profile); int gscms_get_pcs_channel_count(gcmmhprofile_t profile); char* gscms_get_clrtname(gcmmhprofile_t profile, int colorcount, gs_memory_t *memory); @@ -61,8 +61,8 @@ bool gscms_is_device_link(gcmmhprofile_t profile); int gscms_get_device_class(gcmmhprofile_t profile); bool gscms_is_input(gcmmhprofile_t profile); gsicc_colorbuffer_t gscms_get_profile_data_space(gcmmhprofile_t profile); -void gscms_transform_color(gx_device *dev, gsicc_link_t *icclink, void *inputcolor, - void *outputcolor, int num_bytes); +int gscms_transform_color(gx_device *dev, gsicc_link_t *icclink, void *inputcolor, + void *outputcolor, int num_bytes); gcmmhlink_t gscms_get_link(gcmmhprofile_t lcms_srchandle, gcmmhprofile_t lcms_deshandle, gsicc_rendering_param_t *rendering_params, diff --git a/base/gsicc_lcms.c b/base/gsicc_lcms.c index 5716fd79d..119e6ab83 100644 --- a/base/gsicc_lcms.c +++ b/base/gsicc_lcms.c @@ -128,7 +128,7 @@ gscms_get_profile_handle_file(gs_memory_t *mem, const char *filename) } /* Transform an entire buffer */ -void +int gscms_transform_color_buffer(gx_device *dev, gsicc_link_t *icclink, gsicc_bufferdesc_t *input_buff_desc, gsicc_bufferdesc_t *output_buff_desc, @@ -242,6 +242,7 @@ gscms_transform_color_buffer(gx_device *dev, gsicc_link_t *icclink, fclose(fid_out); #endif } + return 0; } /* Transform a single color. We assume we have passed to us the proper number @@ -267,6 +268,7 @@ gscms_transform_color(gx_device *dev, gsicc_link_t *icclink, void *inputcolor, cmsChangeBuffersFormat(hTransform,dwInputFormat,dwOutputFormat); /* Do conversion */ cmsDoTransform(hTransform,inputcolor,outputcolor,1); + return 0; } /* Get the link from the CMS. TODO: Add error checking */ diff --git a/base/gsicc_lcms2.c b/base/gsicc_lcms2.c index e9aa5f69a..a4a4f0640 100644 --- a/base/gsicc_lcms2.c +++ b/base/gsicc_lcms2.c @@ -292,7 +292,7 @@ gscms_get_profile_handle_file(gs_memory_t *mem, const char *filename) } /* Transform an entire buffer */ -void +int gscms_transform_color_buffer(gx_device *dev, gsicc_link_t *icclink, gsicc_bufferdesc_t *input_buff_desc, gsicc_bufferdesc_t *output_buff_desc, @@ -344,7 +344,7 @@ gscms_transform_color_buffer(gx_device *dev, gsicc_link_t *icclink, if (num_src_lcms != input_buff_desc->num_chan || num_des_lcms != output_buff_desc->num_chan) { /* We can't transform this. Someone is doing something odd */ - return; + return gs_error_unknownerror; } dwInputFormat = dwInputFormat | CHANNELS_SH(num_src_lcms); dwOutputFormat = dwOutputFormat | CHANNELS_SH(num_des_lcms); @@ -391,12 +391,12 @@ gscms_transform_color_buffer(gx_device *dev, gsicc_link_t *icclink, source_size * input_buff_desc->num_chan, "gscms_transform_color_buffer"); if (temp_src == NULL) - return; + return gs_error_VMerror; temp_des = (byte*) gs_alloc_bytes(dev->memory->non_gc_memory, des_size * output_buff_desc->num_chan, "gscms_transform_color_buffer"); if (temp_des == NULL) - return; + return gs_error_VMerror; for (y = 0; y < input_buff_desc->num_rows; y++) { byte *src_cm = temp_src; byte *src_buff = inputpos; @@ -445,12 +445,13 @@ gscms_transform_color_buffer(gx_device *dev, gsicc_link_t *icclink, fclose(fid_in); fclose(fid_out); #endif + return 0; } /* Transform a single color. We assume we have passed to us the proper number of elements of size gx_device_color. It is up to the caller to make sure the proper allocations for the colors are there. */ -void +int gscms_transform_color(gx_device *dev, gsicc_link_t *icclink, void *inputcolor, void *outputcolor, int num_bytes) { @@ -469,6 +470,8 @@ gscms_transform_color(gx_device *dev, gsicc_link_t *icclink, void *inputcolor, cmsChangeBuffersFormat(hTransform,dwInputFormat,dwOutputFormat); /* Do conversion */ cmsDoTransform(hTransform,inputcolor,outputcolor,1); + + return 0; } /* Get the flag to avoid having to the cmm do any white fix up, it such a flag diff --git a/base/gsicc_manage.c b/base/gsicc_manage.c index ca22191e1..988c6cf18 100644 --- a/base/gsicc_manage.c +++ b/base/gsicc_manage.c @@ -489,34 +489,39 @@ gsicc_profile_from_ps(cmm_profile_t *profile_data) } /* Fill in the actual source structure rending information */ -static void +static int gsicc_fill_srcgtag_item(gsicc_rendering_param_t *r_params, char **pstrlast, bool cmyk) { char *curr_ptr; int blackptcomp; int or_icc, preserve_k; - int ri, count = 0; + int ri; /* Get the intent */ curr_ptr = gs_strtok(NULL, "\t,\32\n\r", pstrlast); - count = sscanf(curr_ptr, "%d", &ri); + if (sscanf(curr_ptr, "%d", &ri) != 1) + return gs_error_unknownerror; r_params->rendering_intent = ri | gsRI_OVERRIDE; /* Get the black point compensation setting */ curr_ptr = gs_strtok(NULL, "\t,\32\n\r", pstrlast); - count = sscanf(curr_ptr, "%d", &blackptcomp); + if (sscanf(curr_ptr, "%d", &blackptcomp) != 1) + return gs_error_unknownerror; r_params->black_point_comp = blackptcomp | gsBP_OVERRIDE; /* Get the over-ride embedded ICC boolean */ curr_ptr = gs_strtok(NULL, "\t,\32\n\r", pstrlast); - count = sscanf(curr_ptr, "%d", &or_icc); + if (sscanf(curr_ptr, "%d", &or_icc) != 1) + return gs_error_unknownerror; r_params->override_icc = or_icc; if (cmyk) { /* Get the preserve K control */ curr_ptr = gs_strtok(NULL, "\t,\32\n\r", pstrlast); - count = sscanf(curr_ptr, "%d", &preserve_k); + if (sscanf(curr_ptr, "%d", &preserve_k) < 1) + return gs_error_unknownerror; r_params->preserve_black = preserve_k | gsKP_OVERRIDE; } else { r_params->preserve_black = gsBKPRESNOTSPECIFIED; } + return 0; } static int @@ -570,8 +575,12 @@ gsicc_set_srcgtag_struct(gsicc_manager_t *icc_manager, const char* pname, if (str != NULL) { /* Get the information in the file */ code = sfseek(str,0,SEEK_END); + if (code < 0) + return code; info_size = sftell(str); code = srewind(str); + if (code < 0) + return code; if (info_size > (GSICC_NUM_SRCGTAG_KEYS + 1) * FILENAME_MAX) { return gs_throw1(-1, "setting of %s src obj color info failed", pname); @@ -585,6 +594,8 @@ gsicc_set_srcgtag_struct(gsicc_manager_t *icc_manager, const char* pname, } num_bytes = sfread(buffer_ptr,sizeof(unsigned char), info_size, str); code = sfclose(str); + if (code < 0) + return code; buffer_ptr[info_size] = 0; if (num_bytes != info_size) { gs_free_object(mem, buffer_ptr, "gsicc_set_srcgtag_struct"); @@ -643,6 +654,8 @@ gsicc_set_srcgtag_struct(gsicc_manager_t *icc_manager, const char* pname, icc_profile = gsicc_profile_new(str, mem, curr_ptr, strlen(curr_ptr)); code = sfclose(str); + if (code < 0) + return code; } if (str != NULL && icc_profile != NULL) { gsicc_init_profile_info(icc_profile); @@ -673,42 +686,54 @@ gsicc_set_srcgtag_struct(gsicc_manager_t *icc_manager, const char* pname, srcgtag->cmyk_profiles[gsSRC_GRAPPRO] = icc_profile; srcgtag->cmyk_rend_cond[gsSRC_GRAPPRO].cmm = cmm; if (cmm == gsCMM_DEFAULT) { - gsicc_fill_srcgtag_item(&(srcgtag->cmyk_rend_cond[gsSRC_GRAPPRO]), &last, true); + code = gsicc_fill_srcgtag_item(&(srcgtag->cmyk_rend_cond[gsSRC_GRAPPRO]), &last, true); + if (code < 0) + return code; } break; case IMAGE_CMYK: srcgtag->cmyk_profiles[gsSRC_IMAGPRO] = icc_profile; srcgtag->cmyk_rend_cond[gsSRC_IMAGPRO].cmm = cmm; if (cmm == gsCMM_DEFAULT) { - gsicc_fill_srcgtag_item(&(srcgtag->cmyk_rend_cond[gsSRC_IMAGPRO]), &last, true); + code = gsicc_fill_srcgtag_item(&(srcgtag->cmyk_rend_cond[gsSRC_IMAGPRO]), &last, true); + if (code < 0) + return code; } break; case TEXT_CMYK: srcgtag->cmyk_profiles[gsSRC_TEXTPRO] = icc_profile; srcgtag->cmyk_rend_cond[gsSRC_TEXTPRO].cmm = cmm; if (cmm == gsCMM_DEFAULT) { - gsicc_fill_srcgtag_item(&(srcgtag->cmyk_rend_cond[gsSRC_TEXTPRO]), &last, true); + code = gsicc_fill_srcgtag_item(&(srcgtag->cmyk_rend_cond[gsSRC_TEXTPRO]), &last, true); + if (code < 0) + return code; } break; case GRAPHIC_RGB: srcgtag->rgb_profiles[gsSRC_GRAPPRO] = icc_profile; srcgtag->rgb_rend_cond[gsSRC_GRAPPRO].cmm = cmm; if (cmm == gsCMM_DEFAULT) { - gsicc_fill_srcgtag_item(&(srcgtag->rgb_rend_cond[gsSRC_GRAPPRO]), &last, false); + code = gsicc_fill_srcgtag_item(&(srcgtag->rgb_rend_cond[gsSRC_GRAPPRO]), &last, false); + if (code < 0) + return code; } break; case IMAGE_RGB: srcgtag->rgb_profiles[gsSRC_IMAGPRO] = icc_profile; srcgtag->rgb_rend_cond[gsSRC_IMAGPRO].cmm = cmm; if (cmm == gsCMM_DEFAULT) { - gsicc_fill_srcgtag_item(&(srcgtag->rgb_rend_cond[gsSRC_IMAGPRO]), &last, false); + code = gsicc_fill_srcgtag_item(&(srcgtag->rgb_rend_cond[gsSRC_IMAGPRO]), &last, false); + if (code < 0) + return code; } break; case TEXT_RGB: srcgtag->rgb_profiles[gsSRC_TEXTPRO] = icc_profile; srcgtag->rgb_rend_cond[gsSRC_TEXTPRO].cmm = cmm; if (cmm == gsCMM_DEFAULT) { - gsicc_fill_srcgtag_item(&(srcgtag->rgb_rend_cond[gsSRC_TEXTPRO]), &last, false); + code = gsicc_fill_srcgtag_item(&(srcgtag->rgb_rend_cond[gsSRC_TEXTPRO]), &last, false); + if (code < 0) + return code; } break; case GSICC_NUM_SRCGTAG_KEYS: diff --git a/base/gsicc_monitorcm.c b/base/gsicc_monitorcm.c index 812a4e48d..1d00aab81 100644 --- a/base/gsicc_monitorcm.c +++ b/base/gsicc_monitorcm.c @@ -30,14 +30,14 @@ #include "string_.h" #include <stdlib.h> /* abs() */ -static void gsicc_mcm_transform_general(gx_device *dev, gsicc_link_t *icclink, - void *inputcolor, void *outputcolor, - int num_bytes_in, int num_bytes_out); +static int gsicc_mcm_transform_general(gx_device *dev, gsicc_link_t *icclink, + void *inputcolor, void *outputcolor, + int num_bytes_in, int num_bytes_out); /* Functions that should be optimized later to do planar/chunky with color conversions. Just putting in something that should work right now */ -static void +static int gsicc_mcm_planar_to_planar(gx_device *dev, gsicc_link_t *icclink, gsicc_bufferdesc_t *input_buff_desc, gsicc_bufferdesc_t *output_buff_desc, @@ -49,6 +49,7 @@ gsicc_mcm_planar_to_planar(gx_device *dev, gsicc_link_t *icclink, byte *in_buffer_ptr = (byte *) inputbuffer; byte *out_buffer_ptr = (byte *) outputbuffer; byte in_color[4], out_color[4]; + int code; for (k = 0; k < input_buff_desc->num_chan; k++) { inputpos[k] = in_buffer_ptr + k * input_buff_desc->plane_stride; @@ -64,29 +65,32 @@ gsicc_mcm_planar_to_planar(gx_device *dev, gsicc_link_t *icclink, in_color[j] = *(inputpos[j]); inputpos[j] += input_buff_desc->bytes_per_chan; } - gsicc_mcm_transform_general(dev, icclink, (void*) &(in_color[0]), - (void*) &(out_color[0]), 1, 1); + code = gsicc_mcm_transform_general(dev, icclink, + (void*) &(in_color[0]), + (void*) &(out_color[0]), 1, 1); + if (code < 0) + return code; for (j = 0; j < output_buff_desc->num_chan; j++) { *(outputpos[j]) = out_color[j]; outputpos[j] += output_buff_desc->bytes_per_chan; } } + return 0; } /* This is not really used yet */ -static void +static int gsicc_mcm_planar_to_chunky(gx_device *dev, gsicc_link_t *icclink, gsicc_bufferdesc_t *input_buff_desc, gsicc_bufferdesc_t *output_buff_desc, void *inputbuffer, void *outputbuffer) { - - + return 0; } /* This is used with the fast thresholding code when doing -dUseFastColor and going out to a planar device */ -static void +static int gsicc_mcm_chunky_to_planar(gx_device *dev, gsicc_link_t *icclink, gsicc_bufferdesc_t *input_buff_desc, gsicc_bufferdesc_t *output_buff_desc, @@ -103,6 +107,7 @@ gsicc_mcm_chunky_to_planar(gx_device *dev, gsicc_link_t *icclink, int num_bytes_out = output_buff_desc->bytes_per_chan; int pixel_in_step = num_bytes_in * input_buff_desc->num_chan; int plane_stride = output_buff_desc->plane_stride; + int code; /* Do row by row. */ for (k = 0; k < input_buff_desc->num_rows ; k++) { @@ -112,9 +117,13 @@ gsicc_mcm_chunky_to_planar(gx_device *dev, gsicc_link_t *icclink, /* split the 2 byte 1 byte case here to avoid decision in inner loop */ if (output_buff_desc->bytes_per_chan == 1) { for (j = 0; j < input_buff_desc->pixels_per_row; j++) { - gsicc_mcm_transform_general(dev, icclink, (void*) inputcolor, - (void*) &(outputcolor[0]), num_bytes_in, - num_bytes_out); + code = gsicc_mcm_transform_general(dev, icclink, + (void*) inputcolor, + (void*) &(outputcolor[0]), + num_bytes_in, + num_bytes_out); + if (code < 0) + return code; /* Stuff the output in the proper planar location */ for (m = 0; m < output_buff_desc->num_chan; m++) { *(output_loc + m * plane_stride + j) = outputcolor[m]; @@ -125,9 +134,13 @@ gsicc_mcm_chunky_to_planar(gx_device *dev, gsicc_link_t *icclink, outputpos += output_buff_desc->row_stride; } else { for (j = 0; j < input_buff_desc->pixels_per_row; j++) { - gsicc_mcm_transform_general(dev, icclink, (void*) inputcolor, - (void*) &(outputcolor[0]), num_bytes_in, - num_bytes_out); + code = gsicc_mcm_transform_general(dev, icclink, + (void*) inputcolor, + (void*) &(outputcolor[0]), + num_bytes_in, + num_bytes_out); + if (code < 0) + return code; /* Stuff the output in the proper planar location */ pos_in_short = (unsigned short*) &(outputcolor[0]); pos_out_short = (unsigned short*) (output_loc); @@ -140,9 +153,10 @@ gsicc_mcm_chunky_to_planar(gx_device *dev, gsicc_link_t *icclink, outputpos += output_buff_desc->row_stride; } } + return 0; } -static void +static int gsicc_mcm_chunky_to_chunky(gx_device *dev, gsicc_link_t *icclink, gsicc_bufferdesc_t *input_buff_desc, gsicc_bufferdesc_t *output_buff_desc, @@ -156,25 +170,31 @@ gsicc_mcm_chunky_to_chunky(gx_device *dev, gsicc_link_t *icclink, int num_bytes_out = output_buff_desc->bytes_per_chan; int pixel_in_step = num_bytes_in * input_buff_desc->num_chan; int pixel_out_step = num_bytes_out * output_buff_desc->num_chan; + int code; /* Do row by row. */ for (k = 0; k < input_buff_desc->num_rows ; k++) { inputcolor = inputpos; outputcolor = outputpos; for (j = 0; j < input_buff_desc->pixels_per_row; j++) { - gsicc_mcm_transform_general(dev, icclink, (void*) inputcolor, - (void*) outputcolor, num_bytes_in, - num_bytes_out); + code = gsicc_mcm_transform_general(dev, icclink, + (void*) inputcolor, + (void*) outputcolor, + num_bytes_in, + num_bytes_out); + if (code < 0) + return code; inputcolor += pixel_in_step; outputcolor += pixel_out_step; } inputpos += input_buff_desc->row_stride; outputpos += output_buff_desc->row_stride; } + return 0; } /* Transform an entire buffer monitoring and transforming the colors */ -static void +static int gsicc_mcm_transform_color_buffer(gx_device *dev, gsicc_link_t *icclink, gsicc_bufferdesc_t *input_buff_desc, gsicc_bufferdesc_t *output_buff_desc, @@ -182,30 +202,29 @@ gsicc_mcm_transform_color_buffer(gx_device *dev, gsicc_link_t *icclink, { if (input_buff_desc->is_planar) { if (output_buff_desc->is_planar) { - gsicc_mcm_planar_to_planar(dev, icclink, input_buff_desc, - output_buff_desc, inputbuffer, - outputbuffer); + return gsicc_mcm_planar_to_planar(dev, icclink, input_buff_desc, + output_buff_desc, inputbuffer, + outputbuffer); } else { - gsicc_mcm_planar_to_chunky(dev, icclink, input_buff_desc, - output_buff_desc, inputbuffer, - outputbuffer); + return gsicc_mcm_planar_to_chunky(dev, icclink, input_buff_desc, + output_buff_desc, inputbuffer, + outputbuffer); } } else { if (output_buff_desc->is_planar) { - gsicc_mcm_chunky_to_planar(dev, icclink, input_buff_desc, - output_buff_desc, inputbuffer, - outputbuffer); + return gsicc_mcm_chunky_to_planar(dev, icclink, input_buff_desc, + output_buff_desc, inputbuffer, + outputbuffer); } else { - gsicc_mcm_chunky_to_chunky(dev, icclink, input_buff_desc, - output_buff_desc, inputbuffer, - outputbuffer); + return gsicc_mcm_chunky_to_chunky(dev, icclink, input_buff_desc, + output_buff_desc, inputbuffer, + outputbuffer); } } - return; } /* This is where we do the monitoring and the conversion if needed */ -static void +static int gsicc_mcm_transform_general(gx_device *dev, gsicc_link_t *icclink, void *inputcolor, void *outputcolor, int num_bytes_in, int num_bytes_out) @@ -218,6 +237,8 @@ gsicc_mcm_transform_general(gx_device *dev, gsicc_link_t *icclink, int k; code = dev_proc(dev, get_profile)(dev, &dev_profile); + if (code < 0) + return code; /* Monitor only if gray detection is still true */ if (dev_profile->pageneutralcolor) @@ -230,7 +251,11 @@ gsicc_mcm_transform_general(gx_device *dev, gsicc_link_t *icclink, /* Reset all links so that they will no longer monitor. This one will finish the buffer but we will not have any additional ones */ if (!dev_profile->pageneutralcolor) - gsicc_mcm_end_monitor(icclink->icc_link_cache, dev); + { + code = gsicc_mcm_end_monitor(icclink->icc_link_cache, dev); + if (code < 0) + return code; + } /* Now apply the color transform using the original color procs, but don't do this if we had the identity. We also have to worry about 8 and 16 bit @@ -239,7 +264,6 @@ gsicc_mcm_transform_general(gx_device *dev, gsicc_link_t *icclink, if (num_bytes_in == num_bytes_out) { /* The easy case */ memcpy(outputcolor, inputcolor, num_bytes_in * icclink->num_input); - return; } else { if (num_bytes_in == 2) { unsigned short *in_ptr = (unsigned short*) inputcolor; @@ -254,13 +278,11 @@ gsicc_mcm_transform_general(gx_device *dev, gsicc_link_t *icclink, out_ptr[k] = gx_color_value_to_byte(in_ptr[k]); } } - return; } } else { if (num_bytes_in == num_bytes_out) { icclink->orig_procs.map_color(dev, icclink, inputcolor, outputcolor, num_bytes_in); - return; } else { icclink->orig_procs.map_color(dev, icclink, inputcolor, outputcolor_cm_ptr, num_bytes_in); @@ -277,18 +299,18 @@ gsicc_mcm_transform_general(gx_device *dev, gsicc_link_t *icclink, out_ptr[k] = gx_color_value_to_byte(in_ptr[k]); } } - return; } } + return 0; } /* Monitor for color */ -static void +static int gsicc_mcm_transform_color(gx_device *dev, gsicc_link_t *icclink, void *inputcolor, void *outputcolor, int num_bytes) { - gsicc_mcm_transform_general(dev, icclink, inputcolor, outputcolor, - num_bytes, num_bytes); + return gsicc_mcm_transform_general(dev, icclink, inputcolor, outputcolor, + num_bytes, num_bytes); } bool gsicc_mcm_monitor_rgb(void *inputcolor, int num_bytes) @@ -384,7 +406,7 @@ gsicc_mcm_set_link(gsicc_link_t* link) } /* This gets rid of the monitoring */ -void +int gsicc_mcm_end_monitor(gsicc_link_cache_t *cache, gx_device *dev) { gx_monitor_t *lock = cache->lock; @@ -397,6 +419,8 @@ gsicc_mcm_end_monitor(gsicc_link_cache_t *cache, gx_device *dev) /* Get the device profile */ code = dev_proc(dev, get_profile)(dev, &dev_profile); + if (code < 0) + return code; dev_profile->pageneutralcolor = false; /* If this device is a pdf14 device, then we may need to take care of the profile in the target device also. This is a special case since the @@ -421,12 +445,13 @@ gsicc_mcm_end_monitor(gsicc_link_cache_t *cache, gx_device *dev) curr = curr->next; } gx_monitor_leave(lock); /* done with updating, let everyone run */ + return 0; } /* Conversely to the above, this gets restores monitoring, needed after * monitoring was turned off above (for the next page) */ -void +int gsicc_mcm_begin_monitor(gsicc_link_cache_t *cache, gx_device *dev) { gx_monitor_t *lock = cache->lock; @@ -439,6 +464,8 @@ gsicc_mcm_begin_monitor(gsicc_link_cache_t *cache, gx_device *dev) /* Get the device profile */ code = dev_proc(dev, get_profile)(dev, &dev_profile); + if (code < 0) + return code; dev_profile->pageneutralcolor = true; /* If this device is a pdf14 device, then we may need to take care of the profile in the target device also. This is a special case since the @@ -459,4 +486,5 @@ gsicc_mcm_begin_monitor(gsicc_link_cache_t *cache, gx_device *dev) curr = curr->next; } gx_monitor_leave(lock); /* done with updating, let everyone run */ + return 0; } diff --git a/base/gsicc_nocm.c b/base/gsicc_nocm.c index 5fc4edc23..a82d96686 100644 --- a/base/gsicc_nocm.c +++ b/base/gsicc_nocm.c @@ -188,7 +188,7 @@ gsicc_nocm_chunky_to_chunky(gx_device *dev, gsicc_link_t *icclink, /* Transform an entire buffer using the generic (non color managed) transformations */ -static void +static int gsicc_nocm_transform_color_buffer(gx_device *dev, gsicc_link_t *icclink, gsicc_bufferdesc_t *input_buff_desc, gsicc_bufferdesc_t *output_buff_desc, @@ -219,7 +219,7 @@ gsicc_nocm_transform_color_buffer(gx_device *dev, gsicc_link_t *icclink, outputbuffer); } } - return; + return 0; } /* Shared function between the single and buffer conversions */ @@ -282,13 +282,14 @@ gsicc_nocm_transform_general(gx_device *dev, gsicc_link_t *icclink, /* Transform a single color using the generic (non color managed) transformations */ -static void +static int gsicc_nocm_transform_color(gx_device *dev, gsicc_link_t *icclink, void *inputcolor, void *outputcolor, int num_bytes) { gsicc_nocm_transform_general(dev, icclink, inputcolor, outputcolor, num_bytes, num_bytes); + return 0; } static void diff --git a/base/gsicc_replacecm.c b/base/gsicc_replacecm.c index 19b2c277a..278880a88 100644 --- a/base/gsicc_replacecm.c +++ b/base/gsicc_replacecm.c @@ -184,7 +184,7 @@ gsicc_rcm_chunky_to_chunky(gx_device *dev, gsicc_link_t *icclink, } /* Transform an entire buffer using replacement method */ -static void +static int gsicc_rcm_transform_color_buffer(gx_device *dev, gsicc_link_t *icclink, gsicc_bufferdesc_t *input_buff_desc, gsicc_bufferdesc_t *output_buff_desc, @@ -215,7 +215,7 @@ gsicc_rcm_transform_color_buffer(gx_device *dev, gsicc_link_t *icclink, outputbuffer); } } - return; + return 0; } /* Shared function between the single and buffer conversions. This is where @@ -279,12 +279,13 @@ gsicc_rcm_transform_general(gx_device *dev, gsicc_link_t *icclink, /* Transform a single color using the generic (non color managed) transformations */ -static void +static int gsicc_rcm_transform_color(gx_device *dev, gsicc_link_t *icclink, void *inputcolor, void *outputcolor, int num_bytes) { gsicc_rcm_transform_general(dev, icclink, inputcolor, outputcolor, num_bytes, num_bytes); + return 0; } static void @@ -313,6 +314,8 @@ gsicc_rcm_get_link(const gs_imager_state *pis, gx_device *dev, /* Need to check if we need to monitor for color */ if (dev != NULL ) { code = dev_proc(dev, get_profile)(dev, &dev_profile); + if (code < 0) + return NULL; if (dev_profile != NULL) { pageneutralcolor = dev_profile->pageneutralcolor; } diff --git a/base/gspaint.c b/base/gspaint.c index 1835168c6..cb193960f 100644 --- a/base/gspaint.c +++ b/base/gspaint.c @@ -103,7 +103,7 @@ gs_fillpage(gs_state * pgs) if (dev->icc_struct != NULL && dev->icc_struct->graydetection && !dev->icc_struct->pageneutralcolor) { dev->icc_struct->pageneutralcolor = true; /* start detecting again */ - gsicc_mcm_begin_monitor(pgs->icc_link_cache, dev); + code = gsicc_mcm_begin_monitor(pgs->icc_link_cache, dev); } if (code < 0) return code; diff --git a/base/gxclimag.c b/base/gxclimag.c index 549fc53c6..2cded9cab 100644 --- a/base/gxclimag.c +++ b/base/gxclimag.c @@ -813,7 +813,9 @@ clist_begin_typed_image(gx_device * dev, const gs_imager_state * pis, if (pie->decode.unpack == NULL) { /* If we cant unpack, then end monitoring now. Treat as has color */ dev_profile->pageneutralcolor = false; - gsicc_mcm_end_monitor(pis->icc_link_cache, dev); + code = gsicc_mcm_end_monitor(pis->icc_link_cache, dev); + if (code < 0) + return code; } else { /* We need to allocate the buffer for unpacking during monitoring. This is mainly for the 12bit case */ @@ -831,7 +833,9 @@ clist_begin_typed_image(gx_device * dev, const gs_imager_state * pis, if (palette_has_color(pim->ColorSpace, pim)) { /* Has color. We are done monitoring */ dev_profile->pageneutralcolor = false; - gsicc_mcm_end_monitor(pis->icc_link_cache, dev); + code = gsicc_mcm_end_monitor(pis->icc_link_cache, dev); + if (code < 0) + return code; } } } else { @@ -1206,7 +1210,7 @@ clist_image_plane_data(gx_image_enum_common_t * info, cmm_dev_profile_t *dev_profile; code = dev_proc(dev, get_profile)(dev, &dev_profile); dev_profile->pageneutralcolor = false; - gsicc_mcm_end_monitor(pie->pis->icc_link_cache, dev); + code |= gsicc_mcm_end_monitor(pie->pis->icc_link_cache, dev); pie->monitor_color = false; } } else { |