Skip to content

Commit

Permalink
Refactor get_info_string to rely on pdfioDictGetString to convert bin…
Browse files Browse the repository at this point in the history
…ary strings to regular ones.
  • Loading branch information
michaelrsweet committed Jun 24, 2024
1 parent 63a7a2c commit a81907b
Showing 1 changed file with 3 additions and 26 deletions.
29 changes: 3 additions & 26 deletions pdfio-file.c
Original file line number Diff line number Diff line change
Expand Up @@ -1412,36 +1412,13 @@ get_info_string(pdfio_file_t *pdf, // I - PDF file
const char *key) // I - Dictionary key
{
pdfio_dict_t *dict; // Info dictionary
_pdfio_value_t *value; // Value


// Range check input...
if (!pdf || !pdf->info_obj || (dict = pdfioObjGetDict(pdf->info_obj)) == NULL || (value = _pdfioDictGetValue(dict, key)) == NULL)
if (!pdf || !pdf->info_obj || (dict = pdfioObjGetDict(pdf->info_obj)) == NULL)
return (NULL);

// If we already have a value, return it...
if (value->type == PDFIO_VALTYPE_NAME || value->type == PDFIO_VALTYPE_STRING)
{
return (value->value.string);
}
else if (value->type == PDFIO_VALTYPE_BINARY && value->value.binary.datalen < 4096)
{
// Convert binary string to regular string...
char temp[4096]; // Temporary string

memcpy(temp, value->value.binary.data, value->value.binary.datalen);
temp[value->value.binary.datalen] = '\0';

free(value->value.binary.data);
value->type = PDFIO_VALTYPE_STRING;
value->value.string = pdfioStringCreate(pdf, temp);

return (value->value.string);
}
else
{
// Something else that is not a string...
return (NULL);
}
return (pdfioDictGetString(dict, key));
}


Expand Down

0 comments on commit a81907b

Please sign in to comment.