Fix some Coverity-detected issues.

This commit is contained in:
Michael R Sweet 2021-10-01 11:38:04 -04:00
parent 85bfab49ab
commit d1e8c966ed
No known key found for this signature in database
GPG Key ID: 999559A027815955
6 changed files with 13 additions and 4 deletions

View File

@ -7,6 +7,7 @@ v1.0.0 (TBD)
- Added `pdfioFileCreateOutput` API to support streaming output of PDF
(Issue #21)
- Fixed some issues identified by a Coverity scan.
v1.0b1 (August 30, 2021)

View File

@ -568,7 +568,8 @@ _pdfioArrayRead(pdfio_file_t *pdf, // I - PDF file
PDFIO_DEBUG("_pdfioArrayRead(pdf=%p, tb=%p)\n", pdf, tb);
// Create an array...
array = pdfioArrayCreate(pdf);
if ((array = pdfioArrayCreate(pdf)) == NULL)
return (NULL);
// Read until we get "]" to end the array...
while (_pdfioTokenGet(tb, token, sizeof(token)))

View File

@ -2358,7 +2358,7 @@ copy_png(pdfio_dict_t *dict, // I - Dictionary
PDFIO_DEBUG("copy_png: Adding %s ColorSpace value.\n", color_type == _PDFIO_PNG_TYPE_GRAY ? "CalGray" : "CalRGB");
if (wx != 0.0)
pdfioDictSetArray(dict, "ColorSpace", pdfioArrayCreateColorFromPrimaries(dict->pdf, color_type == _PDFIO_PNG_TYPE_GRAY ? 1 : 3, gamma, wx, wy, rx, ry, bx, by, gx, gy));
pdfioDictSetArray(dict, "ColorSpace", pdfioArrayCreateColorFromPrimaries(dict->pdf, color_type == _PDFIO_PNG_TYPE_GRAY ? 1 : 3, gamma, wx, wy, rx, ry, gx, gy, bx, by));
else
pdfioDictSetArray(dict, "ColorSpace", pdfioArrayCreateColorFromStandard(dict->pdf, color_type == _PDFIO_PNG_TYPE_GRAY ? 1 : 3, PDFIO_CS_SRGB));
}

View File

@ -1388,7 +1388,11 @@ load_xref(pdfio_file_t *pdf, // I - PDF file
return (false);
}
_pdfioFileSeek(pdf, xref_offset + ptr + 3 - line, SEEK_SET);
if (_pdfioFileSeek(pdf, xref_offset + ptr + 3 - line, SEEK_SET) < 0)
{
_pdfioFileError(pdf, "Unable to seek to xref object %lu %u.", (unsigned long)number, (unsigned)generation);
return (false);
}
PDFIO_DEBUG("load_xref: Loading object %lu %u.\n", (unsigned long)number, (unsigned)generation);

View File

@ -278,6 +278,8 @@ _pdfioValueRead(pdfio_file_t *pdf, // I - PDF file
else
{
// Date value...
memset(&dateval, 0, sizeof(dateval));
dateval.tm_year = (token[3] - '0') * 1000 + (token[4] - '0') * 100 + (token[5] - '0') * 10 + token[6] - '0' - 1900;
dateval.tm_mon = (token[7] - '0') * 10 + token[8] - '0' - 1;
dateval.tm_mday = (token[9] - '0') * 10 + token[10] - '0';

3
ttf.c
View File

@ -513,7 +513,8 @@ ttfDelete(ttf_t *font) // I - Font
return;
// Close the font file...
close(font->fd);
if (font->fd >= 0)
close(font->fd);
// Free all memory used...
free(font->copyright);