Fix Coverity-discovered issues.

This commit is contained in:
Michael R Sweet 2021-06-04 10:56:23 -04:00
parent caf398d72c
commit ee5fcc2a4a
No known key found for this signature in database
GPG Key ID: 999559A027815955
5 changed files with 136 additions and 95 deletions

View File

@ -157,7 +157,10 @@ _pdfioFileGets(pdfio_file_t *pdf, // I - PDF file
{ {
// Check for a LF after CR // Check for a LF after CR
if (pdf->bufptr >= pdf->bufend) if (pdf->bufptr >= pdf->bufend)
fill_buffer(pdf); {
if (!fill_buffer(pdf))
break;
}
if (pdf->bufptr < pdf->bufend && *(pdf->bufptr) == '\n') if (pdf->bufptr < pdf->bufend && *(pdf->bufptr) == '\n')
pdf->bufptr ++; pdf->bufptr ++;

View File

@ -1144,7 +1144,6 @@ pdfioImageGetBytesPerLine(
{ {
pdfio_dict_t *params; // DecodeParms value pdfio_dict_t *params; // DecodeParms value
int width, // Width of image int width, // Width of image
height, // Height of image
bpc, // BitsPerComponent of image bpc, // BitsPerComponent of image
colors; // Number of colors in image colors; // Number of colors in image
@ -1156,7 +1155,6 @@ pdfioImageGetBytesPerLine(
bpc = (int)pdfioDictGetNumber(params, "BitsPerComponent"); bpc = (int)pdfioDictGetNumber(params, "BitsPerComponent");
colors = (int)pdfioDictGetNumber(params, "Colors"); colors = (int)pdfioDictGetNumber(params, "Colors");
width = (int)pdfioDictGetNumber(params, "Columns"); width = (int)pdfioDictGetNumber(params, "Columns");
height = (int)pdfioDictGetNumber(obj->value.value.dict, "Height");
if (width == 0) if (width == 0)
width = (int)pdfioDictGetNumber(obj->value.value.dict, "Width"); width = (int)pdfioDictGetNumber(obj->value.value.dict, "Width");

View File

@ -628,7 +628,12 @@ pdfioFileOpen(
pdf->version = strdup(line + 5); pdf->version = strdup(line + 5);
// Grab the last 32 characters of the file to find the start of the xref table... // Grab the last 32 characters of the file to find the start of the xref table...
_pdfioFileSeek(pdf, -32, SEEK_END); if (_pdfioFileSeek(pdf, -32, SEEK_END) < 0)
{
_pdfioFileError(pdf, "Unable to read startxref data.");
goto error;
}
if (_pdfioFileRead(pdf, line, 32) < 32) if (_pdfioFileRead(pdf, line, 32) < 32)
{ {
_pdfioFileError(pdf, "Unable to read startxref data."); _pdfioFileError(pdf, "Unable to read startxref data.");
@ -1357,14 +1362,14 @@ write_trailer(pdfio_file_t *pdf) // I - PDF file
if ((fd = open("/dev/urandom", O_RDONLY)) >= 0) if ((fd = open("/dev/urandom", O_RDONLY)) >= 0)
{ {
// Load ID array with random values from /dev/urandom... // Load ID array with random values from /dev/urandom...
memset(id_values, 0, sizeof(id_values)); if (read(fd, id_values[0], sizeof(id_values[0])) == (ssize_t)sizeof(id_values[0]) && read(fd, id_values[1], sizeof(id_values[1])) == (ssize_t)sizeof(id_values[1]))
read(fd, id_values[0], sizeof(id_values[0])); {
read(fd, id_values[1], sizeof(id_values[1])); pdf->id_array = pdfioArrayCreate(pdf);
close(fd); pdfioArrayAppendBinary(pdf->id_array, id_values[0], sizeof(id_values[0]));
pdfioArrayAppendBinary(pdf->id_array, id_values[1], sizeof(id_values[1]));
}
pdf->id_array = pdfioArrayCreate(pdf); close(fd);
pdfioArrayAppendBinary(pdf->id_array, id_values[0], sizeof(id_values[0]));
pdfioArrayAppendBinary(pdf->id_array, id_values[1], sizeof(id_values[1]));
} }
pdf->trailer = pdfioDictCreate(pdf); pdf->trailer = pdfioDictCreate(pdf);

View File

@ -336,7 +336,11 @@ _pdfioStreamOpen(pdfio_obj_t *obj, // I - Object
st->pdf = obj->pdf; st->pdf = obj->pdf;
st->obj = obj; st->obj = obj;
_pdfioFileSeek(st->pdf, obj->stream_offset, SEEK_SET); if (_pdfioFileSeek(st->pdf, obj->stream_offset, SEEK_SET) != obj->stream_offset)
{
free(st);
return (NULL);
}
if ((st->remaining = pdfioObjGetLength(obj)) == 0) if ((st->remaining = pdfioObjGetLength(obj)) == 0)
{ {
@ -646,15 +650,11 @@ pdfioStreamWrite(
const void *buffer, // I - Data to write const void *buffer, // I - Data to write
size_t bytes) // I - Number of bytes to write size_t bytes) // I - Number of bytes to write
{ {
size_t pbpixel = st->pbpixel, size_t pbpixel, // Size of pixel in bytes
// Size of pixel in bytes pbline, // Bytes per line
pbline = st->pbsize - 1,
// Bytes per line
remaining; // Remaining bytes on this line remaining; // Remaining bytes on this line
const unsigned char *bufptr = (const unsigned char *)buffer, const unsigned char *bufptr, // Pointer into buffer
// Pointer into buffer *bufsecond; // Pointer to second pixel in buffer
*bufsecond = buffer + pbpixel;
// Pointer to second pixel in buffer
unsigned char *sptr, // Pointer into sbuffer unsigned char *sptr, // Pointer into sbuffer
*pptr; // Previous raw buffer *pptr; // Previous raw buffer
@ -672,6 +672,8 @@ pdfioStreamWrite(
return (_pdfioFileWrite(st->pdf, buffer, bytes)); return (_pdfioFileWrite(st->pdf, buffer, bytes));
} }
pbline = st->pbsize - 1;
if (st->predictor == _PDFIO_PREDICTOR_NONE) if (st->predictor == _PDFIO_PREDICTOR_NONE)
{ {
// No predictor, just write it out straight... // No predictor, just write it out straight...
@ -683,6 +685,10 @@ pdfioStreamWrite(
return (false); return (false);
} }
pbpixel = st->pbpixel;
bufptr = (const unsigned char *)buffer;
bufsecond = buffer + pbpixel;
while (bytes > 0) while (bytes > 0)
{ {
// Store the PNG predictor in the first byte of the buffer... // Store the PNG predictor in the first byte of the buffer...

View File

@ -761,205 +761,205 @@ write_color_test(pdfio_file_t *pdf, // I - PDF file
if (pdfioContentSetFillColorDeviceGray(st, 0.0)) if (pdfioContentSetFillColorDeviceGray(st, 0.0))
puts("PASS"); puts("PASS");
else else
return (1); goto error;
fputs("pdfioContentTextBegin(): ", stdout); fputs("pdfioContentTextBegin(): ", stdout);
if (pdfioContentTextBegin(st)) if (pdfioContentTextBegin(st))
puts("PASS"); puts("PASS");
else else
return (1); goto error;
fputs("pdfioContentSetTextFont(\"F1\", 12.0): ", stdout); fputs("pdfioContentSetTextFont(\"F1\", 12.0): ", stdout);
if (pdfioContentSetTextFont(st, "F1", 12.0)) if (pdfioContentSetTextFont(st, "F1", 12.0))
puts("PASS"); puts("PASS");
else else
return (1); goto error;
fputs("pdfioContentTextMoveTo(550.0, 36.0): ", stdout); fputs("pdfioContentTextMoveTo(550.0, 36.0): ", stdout);
if (pdfioContentTextMoveTo(st, 550.0, 36.0)) if (pdfioContentTextMoveTo(st, 550.0, 36.0))
puts("PASS"); puts("PASS");
else else
return (1); goto error;
printf("pdfioContentTextShowf(\"%d\"): ", number); printf("pdfioContentTextShowf(\"%d\"): ", number);
if (pdfioContentTextShowf(st, "%d", number)) if (pdfioContentTextShowf(st, "%d", number))
puts("PASS"); puts("PASS");
else else
return (1); goto error;
fputs("pdfioContentTextEnd(): ", stdout); fputs("pdfioContentTextEnd(): ", stdout);
if (pdfioContentTextEnd(st)) if (pdfioContentTextEnd(st))
puts("PASS"); puts("PASS");
else else
return (1); goto error;
fputs("pdfioContentTextBegin(): ", stdout); fputs("pdfioContentTextBegin(): ", stdout);
if (pdfioContentTextBegin(st)) if (pdfioContentTextBegin(st))
puts("PASS"); puts("PASS");
else else
return (1); goto error;
fputs("pdfioContentSetTextFont(\"F1\", 18.0): ", stdout); fputs("pdfioContentSetTextFont(\"F1\", 18.0): ", stdout);
if (pdfioContentSetTextFont(st, "F1", 18.0)) if (pdfioContentSetTextFont(st, "F1", 18.0))
puts("PASS"); puts("PASS");
else else
return (1); goto error;
fputs("pdfioContentTextMoveTo(82, 360): ", stdout); fputs("pdfioContentTextMoveTo(82, 360): ", stdout);
if (pdfioContentTextMoveTo(st, 82, 360)) if (pdfioContentTextMoveTo(st, 82, 360))
puts("PASS"); puts("PASS");
else else
return (1); goto error;
fputs("pdfioContentTextShow(\"AdobeRGB\"): ", stdout); fputs("pdfioContentTextShow(\"AdobeRGB\"): ", stdout);
if (pdfioContentTextShow(st, "AdobeRGB")) if (pdfioContentTextShow(st, "AdobeRGB"))
puts("PASS"); puts("PASS");
else else
return (1); goto error;
fputs("pdfioContentTextMoveTo(234, 0): ", stdout); fputs("pdfioContentTextMoveTo(234, 0): ", stdout);
if (pdfioContentTextMoveTo(st, 234, 0)) if (pdfioContentTextMoveTo(st, 234, 0))
puts("PASS"); puts("PASS");
else else
return (1); goto error;
fputs("pdfioContentTextShow(\"DisplayP3\"): ", stdout); fputs("pdfioContentTextShow(\"DisplayP3\"): ", stdout);
if (pdfioContentTextShow(st, "DisplayP3")) if (pdfioContentTextShow(st, "DisplayP3"))
puts("PASS"); puts("PASS");
else else
return (1); goto error;
fputs("pdfioContentTextMoveTo(-234, 252): ", stdout); fputs("pdfioContentTextMoveTo(-234, 252): ", stdout);
if (pdfioContentTextMoveTo(st, -234, 252)) if (pdfioContentTextMoveTo(st, -234, 252))
puts("PASS"); puts("PASS");
else else
return (1); goto error;
fputs("pdfioContentTextShow(\"sRGB\"): ", stdout); fputs("pdfioContentTextShow(\"sRGB\"): ", stdout);
if (pdfioContentTextShow(st, "sRGB")) if (pdfioContentTextShow(st, "sRGB"))
puts("PASS"); puts("PASS");
else else
return (1); goto error;
fputs("pdfioContentTextMoveTo(234, 0): ", stdout); fputs("pdfioContentTextMoveTo(234, 0): ", stdout);
if (pdfioContentTextMoveTo(st, 234, 0)) if (pdfioContentTextMoveTo(st, 234, 0))
puts("PASS"); puts("PASS");
else else
return (1); goto error;
fputs("pdfioContentTextShow(\"DeviceCMYK\"): ", stdout); fputs("pdfioContentTextShow(\"DeviceCMYK\"): ", stdout);
if (pdfioContentTextShow(st, "DeviceCMYK")) if (pdfioContentTextShow(st, "DeviceCMYK"))
puts("PASS"); puts("PASS");
else else
return (1); goto error;
fputs("pdfioContentTextEnd(): ", stdout); fputs("pdfioContentTextEnd(): ", stdout);
if (pdfioContentTextEnd(st)) if (pdfioContentTextEnd(st))
puts("PASS"); puts("PASS");
else else
return (1); goto error;
fputs("pdfioContentSave(): ", stdout); fputs("pdfioContentSave(): ", stdout);
if (pdfioContentSave(st)) if (pdfioContentSave(st))
puts("PASS"); puts("PASS");
else else
return (1); goto error;
fputs("pdfioContentSetFillColorSpace(AdobeRGB): ", stdout); fputs("pdfioContentSetFillColorSpace(AdobeRGB): ", stdout);
if (pdfioContentSetFillColorSpace(st, "AdobeRGB")) if (pdfioContentSetFillColorSpace(st, "AdobeRGB"))
puts("PASS"); puts("PASS");
else else
return (1); goto error;
fputs("pdfioContentMatrixTranslate(82, 162): ", stdout); fputs("pdfioContentMatrixTranslate(82, 162): ", stdout);
if (pdfioContentMatrixTranslate(st, 82, 162)) if (pdfioContentMatrixTranslate(st, 82, 162))
puts("PASS"); puts("PASS");
else else
return (1); goto error;
if (write_color_patch(st, false)) if (write_color_patch(st, false))
return (1); goto error;
fputs("pdfioContentRestore(): ", stdout); fputs("pdfioContentRestore(): ", stdout);
if (pdfioContentRestore(st)) if (pdfioContentRestore(st))
puts("PASS"); puts("PASS");
else else
return (1); goto error;
fputs("pdfioContentSave(): ", stdout); fputs("pdfioContentSave(): ", stdout);
if (pdfioContentSave(st)) if (pdfioContentSave(st))
puts("PASS"); puts("PASS");
else else
return (1); goto error;
fputs("pdfioContentSetFillColorSpace(DisplayP3): ", stdout); fputs("pdfioContentSetFillColorSpace(DisplayP3): ", stdout);
if (pdfioContentSetFillColorSpace(st, "DisplayP3")) if (pdfioContentSetFillColorSpace(st, "DisplayP3"))
puts("PASS"); puts("PASS");
else else
return (1); goto error;
fputs("pdfioContentMatrixTranslate(316, 162): ", stdout); fputs("pdfioContentMatrixTranslate(316, 162): ", stdout);
if (pdfioContentMatrixTranslate(st, 316, 162)) if (pdfioContentMatrixTranslate(st, 316, 162))
puts("PASS"); puts("PASS");
else else
return (1); goto error;
if (write_color_patch(st, false)) if (write_color_patch(st, false))
return (1); goto error;
fputs("pdfioContentRestore(): ", stdout); fputs("pdfioContentRestore(): ", stdout);
if (pdfioContentRestore(st)) if (pdfioContentRestore(st))
puts("PASS"); puts("PASS");
else else
return (1); goto error;
fputs("pdfioContentSave(): ", stdout); fputs("pdfioContentSave(): ", stdout);
if (pdfioContentSave(st)) if (pdfioContentSave(st))
puts("PASS"); puts("PASS");
else else
return (1); goto error;
fputs("pdfioContentSetFillColorSpace(sRGB): ", stdout); fputs("pdfioContentSetFillColorSpace(sRGB): ", stdout);
if (pdfioContentSetFillColorSpace(st, "sRGB")) if (pdfioContentSetFillColorSpace(st, "sRGB"))
puts("PASS"); puts("PASS");
else else
return (1); goto error;
fputs("pdfioContentMatrixTranslate(82, 414): ", stdout); fputs("pdfioContentMatrixTranslate(82, 414): ", stdout);
if (pdfioContentMatrixTranslate(st, 82, 414)) if (pdfioContentMatrixTranslate(st, 82, 414))
puts("PASS"); puts("PASS");
else else
return (1); goto error;
if (write_color_patch(st, false)) if (write_color_patch(st, false))
return (1); goto error;
fputs("pdfioContentRestore(): ", stdout); fputs("pdfioContentRestore(): ", stdout);
if (pdfioContentRestore(st)) if (pdfioContentRestore(st))
puts("PASS"); puts("PASS");
else else
return (1); goto error;
fputs("pdfioContentSave(): ", stdout); fputs("pdfioContentSave(): ", stdout);
if (pdfioContentSave(st)) if (pdfioContentSave(st))
puts("PASS"); puts("PASS");
else else
return (1); goto error;
fputs("pdfioContentMatrixTranslate(316, 414): ", stdout); fputs("pdfioContentMatrixTranslate(316, 414): ", stdout);
if (pdfioContentMatrixTranslate(st, 316, 414)) if (pdfioContentMatrixTranslate(st, 316, 414))
puts("PASS"); puts("PASS");
else else
return (1); goto error;
if (write_color_patch(st, true)) if (write_color_patch(st, true))
return (1); goto error;
fputs("pdfioContentRestore(): ", stdout); fputs("pdfioContentRestore(): ", stdout);
if (pdfioContentRestore(st)) if (pdfioContentRestore(st))
puts("PASS"); puts("PASS");
else else
return (1); goto error;
fputs("pdfioStreamClose: ", stdout); fputs("pdfioStreamClose: ", stdout);
if (pdfioStreamClose(st)) if (pdfioStreamClose(st))
@ -968,6 +968,11 @@ write_color_test(pdfio_file_t *pdf, // I - PDF file
return (1); return (1);
return (0); return (0);
error:
pdfioStreamClose(st);
return (1);
} }
@ -1028,7 +1033,10 @@ write_image_object(
} }
if (!pdfioStreamWrite(st, buffer, sizeof(buffer))) if (!pdfioStreamWrite(st, buffer, sizeof(buffer)))
{
pdfioStreamClose(st);
return (NULL); return (NULL);
}
} }
pdfioStreamClose(st); pdfioStreamClose(st);
@ -1112,41 +1120,41 @@ write_images(pdfio_file_t *pdf, // I - PDF file
if (pdfioContentSetFillColorDeviceGray(st, 0.0)) if (pdfioContentSetFillColorDeviceGray(st, 0.0))
puts("PASS"); puts("PASS");
else else
return (1); goto error;
fputs("pdfioContentTextBegin(): ", stdout); fputs("pdfioContentTextBegin(): ", stdout);
if (pdfioContentTextBegin(st)) if (pdfioContentTextBegin(st))
puts("PASS"); puts("PASS");
else else
return (1); goto error;
fputs("pdfioContentSetTextFont(\"F1\", 12.0): ", stdout); fputs("pdfioContentSetTextFont(\"F1\", 12.0): ", stdout);
if (pdfioContentSetTextFont(st, "F1", 12.0)) if (pdfioContentSetTextFont(st, "F1", 12.0))
puts("PASS"); puts("PASS");
else else
return (1); goto error;
fputs("pdfioContentTextMoveTo(550.0, 36.0): ", stdout); fputs("pdfioContentTextMoveTo(550.0, 36.0): ", stdout);
if (pdfioContentTextMoveTo(st, 550.0, 36.0)) if (pdfioContentTextMoveTo(st, 550.0, 36.0))
puts("PASS"); puts("PASS");
else else
return (1); goto error;
printf("pdfioContentTextShowf(\"%d\"): ", number); printf("pdfioContentTextShowf(\"%d\"): ", number);
if (pdfioContentTextShowf(st, "%d", number)) if (pdfioContentTextShowf(st, "%d", number))
puts("PASS"); puts("PASS");
else else
return (1); goto error;
fputs("pdfioContentTextEnd(): ", stdout); fputs("pdfioContentTextEnd(): ", stdout);
if (pdfioContentTextEnd(st)) if (pdfioContentTextEnd(st))
puts("PASS"); puts("PASS");
else else
return (1); goto error;
// Draw images // Draw images
if (draw_image(st, "IM1", 36, 558, 144, 144, "No Predictor")) if (draw_image(st, "IM1", 36, 558, 144, 144, "No Predictor"))
return (1); goto error;
for (p = _PDFIO_PREDICTOR_PNG_NONE; p <= _PDFIO_PREDICTOR_PNG_AUTO; p ++) for (p = _PDFIO_PREDICTOR_PNG_NONE; p <= _PDFIO_PREDICTOR_PNG_AUTO; p ++)
{ {
@ -1155,7 +1163,8 @@ write_images(pdfio_file_t *pdf, // I - PDF file
snprintf(pname, sizeof(pname), "IM%d", p); snprintf(pname, sizeof(pname), "IM%d", p);
snprintf(plabel, sizeof(plabel), "PNG Predictor %d", p); snprintf(plabel, sizeof(plabel), "PNG Predictor %d", p);
draw_image(st, pname, 36 + 180 * (i % 3), 342 - 216 * (i / 3), 144, 144, plabel); if (draw_image(st, pname, 36 + 180 * (i % 3), 342 - 216 * (i / 3), 144, 144, plabel))
goto error;
} }
// Wrap up... // Wrap up...
@ -1166,6 +1175,11 @@ write_images(pdfio_file_t *pdf, // I - PDF file
return (1); return (1);
return (0); return (0);
error:
pdfioStreamClose(st);
return (1);
} }
@ -1222,61 +1236,61 @@ write_page(pdfio_file_t *pdf, // I - PDF file
"54 54 487 688 re 90 90 415 612 re B*\n")) "54 54 487 688 re 90 90 415 612 re B*\n"))
puts("PASS"); puts("PASS");
else else
return (1); goto error;
fputs("pdfioContentSetFillColorDeviceGray(0.0): ", stdout); fputs("pdfioContentSetFillColorDeviceGray(0.0): ", stdout);
if (pdfioContentSetFillColorDeviceGray(st, 0.0)) if (pdfioContentSetFillColorDeviceGray(st, 0.0))
puts("PASS"); puts("PASS");
else else
return (1); goto error;
fputs("pdfioContentTextBegin(): ", stdout); fputs("pdfioContentTextBegin(): ", stdout);
if (pdfioContentTextBegin(st)) if (pdfioContentTextBegin(st))
puts("PASS"); puts("PASS");
else else
return (1); goto error;
fputs("pdfioContentSetTextFont(\"F1\", 12.0): ", stdout); fputs("pdfioContentSetTextFont(\"F1\", 12.0): ", stdout);
if (pdfioContentSetTextFont(st, "F1", 12.0)) if (pdfioContentSetTextFont(st, "F1", 12.0))
puts("PASS"); puts("PASS");
else else
return (1); goto error;
fputs("pdfioContentTextMoveTo(550.0, 36.0): ", stdout); fputs("pdfioContentTextMoveTo(550.0, 36.0): ", stdout);
if (pdfioContentTextMoveTo(st, 550.0, 36.0)) if (pdfioContentTextMoveTo(st, 550.0, 36.0))
puts("PASS"); puts("PASS");
else else
return (1); goto error;
printf("pdfioContentTextShowf(\"%d\"): ", number); printf("pdfioContentTextShowf(\"%d\"): ", number);
if (pdfioContentTextShowf(st, "%d", number)) if (pdfioContentTextShowf(st, "%d", number))
puts("PASS"); puts("PASS");
else else
return (1); goto error;
fputs("pdfioContentTextEnd(): ", stdout); fputs("pdfioContentTextEnd(): ", stdout);
if (pdfioContentTextEnd(st)) if (pdfioContentTextEnd(st))
puts("PASS"); puts("PASS");
else else
return (1); goto error;
fputs("pdfioContentSave(): ", stdout); fputs("pdfioContentSave(): ", stdout);
if (pdfioContentSave(st)) if (pdfioContentSave(st))
puts("PASS"); puts("PASS");
else else
return (1); goto error;
fputs("pdfioImageGetWidth(): ", stdout); fputs("pdfioImageGetWidth(): ", stdout);
if ((width = pdfioImageGetWidth(image)) > 0.0) if ((width = pdfioImageGetWidth(image)) > 0.0)
puts("PASS"); puts("PASS");
else else
return (1); goto error;
fputs("pdfioImageGetHeight(): ", stdout); fputs("pdfioImageGetHeight(): ", stdout);
if ((height = pdfioImageGetHeight(image)) > 0.0) if ((height = pdfioImageGetHeight(image)) > 0.0)
puts("PASS"); puts("PASS");
else else
return (1); goto error;
swidth = 400.0; swidth = 400.0;
sheight = swidth * height / width; sheight = swidth * height / width;
@ -1293,13 +1307,13 @@ write_page(pdfio_file_t *pdf, // I - PDF file
if (pdfioContentDrawImage(st, "IM1", tx, ty, swidth, sheight)) if (pdfioContentDrawImage(st, "IM1", tx, ty, swidth, sheight))
puts("PASS"); puts("PASS");
else else
return (1); goto error;
fputs("pdfioContentRestore(): ", stdout); fputs("pdfioContentRestore(): ", stdout);
if (pdfioContentRestore(st)) if (pdfioContentRestore(st))
puts("PASS"); puts("PASS");
else else
return (1); goto error;
fputs("pdfioStreamClose: ", stdout); fputs("pdfioStreamClose: ", stdout);
if (pdfioStreamClose(st)) if (pdfioStreamClose(st))
@ -1308,6 +1322,11 @@ write_page(pdfio_file_t *pdf, // I - PDF file
return (1); return (1);
return (0); return (0);
error:
pdfioStreamClose(st);
return (1);
} }
@ -1386,49 +1405,49 @@ write_text(pdfio_file_t *pdf, // I - PDF file
if (pdfioContentSetFillColorDeviceGray(st, 0.0)) if (pdfioContentSetFillColorDeviceGray(st, 0.0))
puts("PASS"); puts("PASS");
else else
return (1); goto error;
fputs("pdfioContentTextBegin(): ", stdout); fputs("pdfioContentTextBegin(): ", stdout);
if (pdfioContentTextBegin(st)) if (pdfioContentTextBegin(st))
puts("PASS"); puts("PASS");
else else
return (1); goto error;
fputs("pdfioContentSetTextFont(\"F1\", 12.0): ", stdout); fputs("pdfioContentSetTextFont(\"F1\", 12.0): ", stdout);
if (pdfioContentSetTextFont(st, "F1", 12.0)) if (pdfioContentSetTextFont(st, "F1", 12.0))
puts("PASS"); puts("PASS");
else else
return (1); goto error;
fputs("pdfioContentTextMoveTo(36.0, 36.0): ", stdout); fputs("pdfioContentTextMoveTo(36.0, 36.0): ", stdout);
if (pdfioContentTextMoveTo(st, 36, 36.0)) if (pdfioContentTextMoveTo(st, 36, 36.0))
puts("PASS"); puts("PASS");
else else
return (1); goto error;
printf("pdfioContentTextShowf(\"\\\"%s\\\"\"): ", filename); printf("pdfioContentTextShowf(\"\\\"%s\\\"\"): ", filename);
if (pdfioContentTextShowf(st, "\"%s\"", filename)) if (pdfioContentTextShowf(st, "\"%s\"", filename))
puts("PASS"); puts("PASS");
else else
return (1); goto error;
fputs("pdfioContentTextMoveTo(514.0, 0.0): ", stdout); fputs("pdfioContentTextMoveTo(514.0, 0.0): ", stdout);
if (pdfioContentTextMoveTo(st, 514.0, 0.0)) if (pdfioContentTextMoveTo(st, 514.0, 0.0))
puts("PASS"); puts("PASS");
else else
return (1); goto error;
printf("pdfioContentTextShowf(\"%d\"): ", page); printf("pdfioContentTextShowf(\"%d\"): ", page);
if (pdfioContentTextShowf(st, "%d", page)) if (pdfioContentTextShowf(st, "%d", page))
puts("PASS"); puts("PASS");
else else
return (1); goto error;
fputs("pdfioContentTextEnd(): ", stdout); fputs("pdfioContentTextEnd(): ", stdout);
if (pdfioContentTextEnd(st)) if (pdfioContentTextEnd(st))
puts("PASS"); puts("PASS");
else else
return (1); goto error;
page ++; page ++;
plinenum ++; plinenum ++;
@ -1437,31 +1456,35 @@ write_text(pdfio_file_t *pdf, // I - PDF file
if (pdfioContentTextBegin(st)) if (pdfioContentTextBegin(st))
puts("PASS"); puts("PASS");
else else
return (1); goto error;
fputs("pdfioContentSetTextFont(\"F2\", 10.0): ", stdout); fputs("pdfioContentSetTextFont(\"F2\", 10.0): ", stdout);
if (pdfioContentSetTextFont(st, "F2", 10.0)) if (pdfioContentSetTextFont(st, "F2", 10.0))
puts("PASS"); puts("PASS");
else else
return (1); goto error;
fputs("pdfioContentSetTextLeading(12.0): ", stdout); fputs("pdfioContentSetTextLeading(12.0): ", stdout);
if (pdfioContentSetTextLeading(st, 12.0)) if (pdfioContentSetTextLeading(st, 12.0))
puts("PASS"); puts("PASS");
else else
return (1); goto error;
fputs("pdfioContentTextMoveTo(36.0, 756.0): ", stdout); fputs("pdfioContentTextMoveTo(36.0, 756.0): ", stdout);
if (pdfioContentTextMoveTo(st, 36.0, 756.0)) if (pdfioContentTextMoveTo(st, 36.0, 756.0))
puts("PASS"); puts("PASS");
else else
return (1); goto error;
} }
pdfioContentSetFillColorDeviceGray(st, 0.75); if (!pdfioContentSetFillColorDeviceGray(st, 0.75))
pdfioContentTextShowf(st, "%4d ", flinenum); goto error;
pdfioContentSetFillColorDeviceGray(st, 0.0); if (!pdfioContentTextShowf(st, "%4d ", flinenum))
pdfioContentTextShow(st, line); goto error;
if (!pdfioContentSetFillColorDeviceGray(st, 0.0))
goto error;
if (!pdfioContentTextShow(st, line))
goto error;
plinenum ++; plinenum ++;
if (plinenum >= 60) if (plinenum >= 60)
@ -1470,13 +1493,13 @@ write_text(pdfio_file_t *pdf, // I - PDF file
if (pdfioContentTextEnd(st)) if (pdfioContentTextEnd(st))
puts("PASS"); puts("PASS");
else else
return (1); goto error;
fputs("pdfioStreamClose: ", stdout); fputs("pdfioStreamClose: ", stdout);
if (pdfioStreamClose(st)) if (pdfioStreamClose(st))
puts("PASS"); puts("PASS");
else else
return (1); goto error;
st = NULL; st = NULL;
plinenum = 0; plinenum = 0;
@ -1489,7 +1512,7 @@ write_text(pdfio_file_t *pdf, // I - PDF file
if (pdfioContentTextEnd(st)) if (pdfioContentTextEnd(st))
puts("PASS"); puts("PASS");
else else
return (1); goto error;
fputs("pdfioStreamClose: ", stdout); fputs("pdfioStreamClose: ", stdout);
if (pdfioStreamClose(st)) if (pdfioStreamClose(st))
@ -1499,4 +1522,10 @@ write_text(pdfio_file_t *pdf, // I - PDF file
} }
return (0); return (0);
error:
fclose(fp);
pdfioStreamClose(st);
return (1);
} }