summaryrefslogtreecommitdiff
path: root/pcl
diff options
context:
space:
mode:
authorChris Liddell <chris.liddell@artifex.com>2022-08-25 09:43:18 +0100
committerChris Liddell <chris.liddell@artifex.com>2022-08-26 10:51:20 +0100
commitaa6b1865f902a05d88590a8e4bdf5896ef6938f9 (patch)
tree282795b97522a265cbee2b63932e8a308b5ed698 /pcl
parentee290c1aebaa172c812f21024af2dbf721fa5865 (diff)
downloadghostpdl-aa6b1865f902a05d88590a8e4bdf5896ef6938f9.tar.gz
Coverity 380510/380513: Avoid redundant ID type check
Since we've already checked the font and macro ID types are string, coverity spots that the type checks in the ID accessor macros are redundant. So, add accessors for when we already know the ID is a string ID. Secondly, tidy up macro naming, so it's not so easily confused with a variable or constant value.
Diffstat (limited to 'pcl')
-rw-r--r--pcl/pcl/pcmacros.c22
-rw-r--r--pcl/pcl/pcsfont.c60
-rw-r--r--pcl/pcl/pcstate.h23
3 files changed, 55 insertions, 50 deletions
diff --git a/pcl/pcl/pcmacros.c b/pcl/pcl/pcmacros.c
index fc174fb5e..abcbe4095 100644
--- a/pcl/pcl/pcmacros.c
+++ b/pcl/pcl/pcmacros.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 2001-2021 Artifex Software, Inc.
+/* Copyright (C) 2001-2022 Artifex Software, Inc.
All Rights Reserved.
This software is provided AS-IS with no warranty, either express or
@@ -32,8 +32,8 @@ pcl_dump_current_macro(pcl_state_t * pcs, const char *msg)
dmputs(pcs->memory, msg);
dmputs(pcs->memory, " ");
- for (i = 0; i < current_macro_id_size; i++)
- dmprintf1(pcs->memory, "%02x", current_macro_id[i]);
+ for (i = 0; i < CURRENT_MACRO_ID_SIZE; i++)
+ dmprintf1(pcs->memory, "%02x", CURRENT_MACRO_ID[i]);
dmputs(pcs->memory, "\n");
return;
}
@@ -133,8 +133,8 @@ pcl_macro_control(pcl_args_t * pargs, pcl_state_t * pcs)
/* in the macro_definition, so we can finish things up. */
int code;
- code = pl_dict_put(&pcs->macros, current_macro_id,
- current_macro_id_size, pcs->macro_definition);
+ code = pl_dict_put(&pcs->macros, CURRENT_MACRO_ID,
+ CURRENT_MACRO_ID_SIZE, pcs->macro_definition);
pcs->defining_macro = false;
pcs->macro_definition = 0;
#ifdef DEBUG
@@ -183,7 +183,7 @@ pcl_macro_control(pcl_args_t * pargs, pcl_state_t * pcs)
void *value;
if (!pl_dict_find
- (&pcs->macros, current_macro_id, current_macro_id_size,
+ (&pcs->macros, CURRENT_MACRO_ID, CURRENT_MACRO_ID_SIZE,
&value)
)
return 0;
@@ -196,7 +196,7 @@ pcl_macro_control(pcl_args_t * pargs, pcl_state_t * pcs)
void *value;
if (!pl_dict_find
- (&pcs->macros, current_macro_id, current_macro_id_size,
+ (&pcs->macros, CURRENT_MACRO_ID, CURRENT_MACRO_ID_SIZE,
&value)
)
return 0;
@@ -231,14 +231,14 @@ pcl_macro_control(pcl_args_t * pargs, pcl_state_t * pcs)
}
case 8:
{ /* Delete <macro_id>. */
- pl_dict_undef_purge_synonyms(&pcs->macros, current_macro_id,
- current_macro_id_size);
+ pl_dict_undef_purge_synonyms(&pcs->macros, CURRENT_MACRO_ID,
+ CURRENT_MACRO_ID_SIZE);
return 0;
}
case 9:
{ /* Make <macro_id> temporary. */
if (pl_dict_find
- (&pcs->macros, current_macro_id, current_macro_id_size,
+ (&pcs->macros, CURRENT_MACRO_ID, CURRENT_MACRO_ID_SIZE,
&value))
((pcl_macro_t *) value)->storage = pcds_temporary;
return 0;
@@ -246,7 +246,7 @@ pcl_macro_control(pcl_args_t * pargs, pcl_state_t * pcs)
case 10:
{ /* Make <macro_id> permanent. */
if (pl_dict_find
- (&pcs->macros, current_macro_id, current_macro_id_size,
+ (&pcs->macros, CURRENT_MACRO_ID, CURRENT_MACRO_ID_SIZE,
&value))
((pcl_macro_t *) value)->storage = pcds_permanent;
return 0;
diff --git a/pcl/pcl/pcsfont.c b/pcl/pcl/pcsfont.c
index 1d418a517..2bed2ad79 100644
--- a/pcl/pcl/pcsfont.c
+++ b/pcl/pcl/pcsfont.c
@@ -119,11 +119,11 @@ pcl_make_resident_font_copy(pcl_state_t * pcs)
/* first check for a duplicate key, if found remove it */
if (pl_dict_lookup
- (&pcs->built_in_fonts, current_font_id, current_font_id_size, &value,
+ (&pcs->built_in_fonts, CURRENT_FONT_ID, CURRENT_FONT_ID_SIZE, &value,
false, (pl_dict_t **) 0))
if (pl_dict_undef
- (&pcs->built_in_fonts, current_font_id,
- current_font_id_size) == false)
+ (&pcs->built_in_fonts, CURRENT_FONT_ID,
+ CURRENT_FONT_ID_SIZE) == false)
/* shouldn't fail */
return -1;
@@ -137,7 +137,7 @@ pcl_make_resident_font_copy(pcl_state_t * pcs)
if (found == false)
return -1;
return pl_dict_put_synonym(&pcs->built_in_fonts, key.data,
- key.size, current_font_id, current_font_id_size);
+ key.size, CURRENT_FONT_ID, CURRENT_FONT_ID_SIZE);
}
static int /* ESC * c <fc_enum> F */
@@ -178,7 +178,7 @@ pcl_font_control(pcl_args_t * pargs, pcl_state_t * pcs)
break;
case 2:
/* Delete soft font <font_id>. */
- code = pcl_delete_soft_font(pcs, current_font_id, current_font_id_size,
+ code = pcl_delete_soft_font(pcs, CURRENT_FONT_ID, CURRENT_FONT_ID_SIZE,
NULL);
/* decache the currently selected font in case we deleted it. */
pcl_decache_font(pcs, -1, true);
@@ -187,7 +187,7 @@ pcl_font_control(pcl_args_t * pargs, pcl_state_t * pcs)
case 3:
/* Delete character <font_id, character_code>. */
if (pl_dict_find_no_stack
- (&pcs->soft_fonts, current_font_id, current_font_id_size,
+ (&pcs->soft_fonts, CURRENT_FONT_ID, CURRENT_FONT_ID_SIZE,
&value))
pl_font_remove_glyph((pl_font_t *) value,
pcs->character_code);
@@ -197,7 +197,7 @@ pcl_font_control(pcl_args_t * pargs, pcl_state_t * pcs)
case 4:
/* Make soft font <font_id> temporary. */
if (pl_dict_find_no_stack
- (&pcs->soft_fonts, current_font_id, current_font_id_size,
+ (&pcs->soft_fonts, CURRENT_FONT_ID, CURRENT_FONT_ID_SIZE,
&value))
((pl_font_t *) value)->storage = pcds_temporary;
@@ -205,7 +205,7 @@ pcl_font_control(pcl_args_t * pargs, pcl_state_t * pcs)
case 5:
/* Make soft font <font_id> permanent. */
if (pl_dict_find_no_stack
- (&pcs->soft_fonts, current_font_id, current_font_id_size,
+ (&pcs->soft_fonts, CURRENT_FONT_ID, CURRENT_FONT_ID_SIZE,
&value)) {
((pl_font_t *) value)->storage = pcds_permanent;
((pl_font_t *) value)->params.pjl_font_number =
@@ -238,14 +238,14 @@ pcl_font_control(pcl_args_t * pargs, pcl_state_t * pcs)
if (code < 0)
return code;
- code = pcl_delete_soft_font(pcs, current_font_id,
- current_font_id_size, NULL);
+ code = pcl_delete_soft_font(pcs, CURRENT_FONT_ID,
+ CURRENT_FONT_ID_SIZE, NULL);
if (code < 0)
return code;
plfont->storage = pcds_temporary;
plfont->data_are_permanent = false;
- code = pl_dict_put(&pcs->soft_fonts, current_font_id,
- current_font_id_size, plfont);
+ code = pl_dict_put(&pcs->soft_fonts, CURRENT_FONT_ID,
+ CURRENT_FONT_ID_SIZE, plfont);
}
}
break;
@@ -330,7 +330,7 @@ pcl_font_header(pcl_args_t * pargs, pcl_state_t * pcs)
}
}
/* Delete any previous font with this ID. */
- code = pcl_delete_soft_font(pcs, current_font_id, current_font_id_size, NULL);
+ code = pcl_delete_soft_font(pcs, CURRENT_FONT_ID, CURRENT_FONT_ID_SIZE, NULL);
if (code < 0)
return code;
/* Create the generic font information. */
@@ -514,8 +514,8 @@ pcl_font_header(pcl_args_t * pargs, pcl_state_t * pcs)
(pfh->TypefaceMSB << 8) + pfh->TypefaceLSB;
plfont->params.pjl_font_number = pcs->pjl_dlfont_number++;
- code = pl_dict_put(&pcs->soft_fonts, current_font_id,
- current_font_id_size, plfont);
+ code = pl_dict_put(&pcs->soft_fonts, CURRENT_FONT_ID,
+ CURRENT_FONT_ID_SIZE, plfont);
if (code < 0) {
/* on error, pl_dict_put consumes plfont */
return code;
@@ -563,8 +563,8 @@ pcl_character_data(pcl_args_t * pargs, pcl_state_t * pcs)
}
#endif
- if (!pl_dict_find_no_stack(&pcs->soft_fonts, current_font_id,
- current_font_id_size, &value))
+ if (!pl_dict_find_no_stack(&pcs->soft_fonts, CURRENT_FONT_ID,
+ CURRENT_FONT_ID_SIZE, &value))
return 0; /* font not found */
plfont = ((pl_font_t *) value);
@@ -865,17 +865,17 @@ pcl_find_resource(pcl_state_t * pcs,
downloaded in the recursive interpreter invocation above, so we
don't need to add (put) it in the dictionary. */
if (resource_type == macro_resource) {
- code = pl_dict_put(&pcs->macros, current_macro_id, current_macro_id_size, value);
+ code = pl_dict_put(&pcs->macros, CURRENT_MACRO_ID, CURRENT_MACRO_ID_SIZE, value);
if (code == 0)
- code = pl_dict_put_synonym(&pcs->macros, current_macro_id,
- current_macro_id_size, sid, sid_size);
+ code = pl_dict_put_synonym(&pcs->macros, CURRENT_MACRO_ID,
+ CURRENT_MACRO_ID_SIZE, sid, sid_size);
if (code < 0) {
gs_free_object(pcs->memory, value, "resource");
return_error(code);
}
} else {
- code = pl_dict_put_synonym(&pcs->soft_fonts, current_font_id,
- current_font_id_size, sid, sid_size);
+ code = pl_dict_put_synonym(&pcs->soft_fonts, CURRENT_FONT_ID,
+ CURRENT_FONT_ID_SIZE, sid, sid_size);
/* font was constructed separately, don't need the
original PCL commands from which the font was
constructed. */
@@ -938,8 +938,8 @@ pcl_alphanumeric_id_data(pcl_args_t * pargs, pcl_state_t * pcs)
/* simple case the font is in the dictionary */
if (pl_dict_find_no_stack(&pcs->soft_fonts, alpha_data->string_id, string_id_size, &value)) {
return pl_dict_put_synonym(&pcs->soft_fonts, alpha_data->string_id,
- string_id_size, current_font_id,
- current_font_id_size);
+ string_id_size, CURRENT_FONT_ID,
+ CURRENT_FONT_ID_SIZE);
} else {
/* search the PJL file system for a font resource */
return pcl_find_resource(pcs, alpha_data->string_id,
@@ -1009,8 +1009,8 @@ pcl_alphanumeric_id_data(pcl_args_t * pargs, pcl_state_t * pcs)
/* simple case - the macro is in the dictionary */
if (pl_dict_find_no_stack(&pcs->macros, alpha_data->string_id, string_id_size, &value)) {
return pl_dict_put_synonym(&pcs->macros, alpha_data->string_id,
- string_id_size, current_macro_id,
- current_macro_id_size);
+ string_id_size, CURRENT_MACRO_ID,
+ CURRENT_MACRO_ID_SIZE);
} else {
/* search the PJL file system for a macro resource */
return pcl_find_resource(pcs, alpha_data->string_id,
@@ -1021,14 +1021,14 @@ pcl_alphanumeric_id_data(pcl_args_t * pargs, pcl_state_t * pcs)
case 20:
/* deletes the font association named by the current Font ID */
if (pcs->font_id_type == string_id)
- return pcl_delete_soft_font(pcs, current_font_id,
- current_font_id_size, NULL);
+ return pcl_delete_soft_font(pcs, CURRENT_FONT_STRING_ID,
+ CURRENT_FONT_STRING_ID_SIZE, NULL);
break;
case 21:
/* deletes the macro association named the the current macro id */
if (pcs->macro_id_type == string_id)
- pl_dict_undef(&pcs->macros, current_macro_id,
- current_macro_id_size);
+ pl_dict_undef(&pcs->macros, CURRENT_MACRO_ID,
+ CURRENT_MACRO_ID_SIZE);
break;
case 100:
/* media select */
diff --git a/pcl/pcl/pcstate.h b/pcl/pcl/pcstate.h
index 4fb6b8755..37512d6b0 100644
--- a/pcl/pcl/pcstate.h
+++ b/pcl/pcl/pcstate.h
@@ -1,4 +1,4 @@
-/* Copyright (C) 2001-2021 Artifex Software, Inc.
+/* Copyright (C) 2001-2022 Artifex Software, Inc.
All Rights Reserved.
This software is provided AS-IS with no warranty, either express or
@@ -210,12 +210,15 @@ struct pcl_state_s
alphanumeric_string_id_t alpha_font_id;
id_type_t font_id_type;
-#define current_font_id \
- ( ((pcs->font_id_type == string_id) ? (pcs->alpha_font_id.id) \
+
+#define CURRENT_FONT_STRING_ID (pcs->alpha_font_id.id)
+#define CURRENT_FONT_ID \
+ ( ((pcs->font_id_type == string_id) ? CURRENT_FONT_STRING_ID \
: (id_key(pcs->font_id))) )
-#define current_font_id_size \
- ( ((pcs->font_id_type == string_id) ? (pcs->alpha_font_id.size) : (2)) )
+#define CURRENT_FONT_STRING_ID_SIZE (pcs->alpha_font_id.size)
+#define CURRENT_FONT_ID_SIZE \
+ ( ((pcs->font_id_type == string_id) ? CURRENT_FONT_STRING_ID_SIZE : (2)) )
/* Chapter 12 (pcmacros.c) */
pcl_id_t macro_id;
@@ -232,12 +235,14 @@ struct pcl_state_s
alphanumeric_string_id_t alpha_macro_id;
id_type_t macro_id_type;
-#define current_macro_id \
- ( ((pcs->macro_id_type == string_id) ? (pcs->alpha_macro_id.id) \
+#define CURRENT_MACRO_STRING_ID (pcs->alpha_macro_id.id)
+#define CURRENT_MACRO_ID \
+ ( ((pcs->macro_id_type == string_id) ? CURRENT_MACRO_STRING_ID \
: (id_key(pcs->macro_id))) )
-#define current_macro_id_size \
- ( ((pcs->macro_id_type == string_id) ? (pcs->alpha_macro_id.size) : (2)) )
+#define CURRENT_MACRO_STRING_ID_SIZE (pcs->alpha_macro_id.size)
+#define CURRENT_MACRO_ID_SIZE \
+ ( ((pcs->macro_id_type == string_id) ? CURRENT_MACRO_STRING_ID_SIZE : (2)) )
/* Chapter 13 (pcprint.c) */
gs_point pat_ref_pt; /* active pattern reference point,