Fix some Coverity-detected issues.

This commit is contained in:
Michael R Sweet 2021-10-01 11:38:04 -04:00
parent 1168fd974f
commit d5173d14da
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 - Added `pdfioFileCreateOutput` API to support streaming output of PDF
(Issue #21) (Issue #21)
- Fixed some issues identified by a Coverity scan.
v1.0b1 (August 30, 2021) 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); PDFIO_DEBUG("_pdfioArrayRead(pdf=%p, tb=%p)\n", pdf, tb);
// Create an array... // Create an array...
array = pdfioArrayCreate(pdf); if ((array = pdfioArrayCreate(pdf)) == NULL)
return (NULL);
// Read until we get "]" to end the array... // Read until we get "]" to end the array...
while (_pdfioTokenGet(tb, token, sizeof(token))) 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"); PDFIO_DEBUG("copy_png: Adding %s ColorSpace value.\n", color_type == _PDFIO_PNG_TYPE_GRAY ? "CalGray" : "CalRGB");
if (wx != 0.0) 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 else
pdfioDictSetArray(dict, "ColorSpace", pdfioArrayCreateColorFromStandard(dict->pdf, color_type == _PDFIO_PNG_TYPE_GRAY ? 1 : 3, PDFIO_CS_SRGB)); 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); 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); 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 else
{ {
// Date value... // 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_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_mon = (token[7] - '0') * 10 + token[8] - '0' - 1;
dateval.tm_mday = (token[9] - '0') * 10 + token[10] - '0'; dateval.tm_mday = (token[9] - '0') * 10 + token[10] - '0';

1
ttf.c
View File

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