mirror of
				https://github.com/michaelrsweet/pdfio.git
				synced 2025-10-31 02:15:48 +01:00 
			
		
		
		
	Clean up some compiler warnings.
This commit is contained in:
		| @@ -241,7 +241,7 @@ _pdfioCryptoAESEncrypt( | ||||
|   if (len > 0) | ||||
|   { | ||||
|     // Pad the final buffer with (16 - len)... | ||||
|     memset(outbuffer + len, 16 - len, 16 - len); | ||||
|     memset(outbuffer + len, (int)(16 - len), 16 - len); | ||||
|  | ||||
|     xor_with_iv(outbuffer, iv); | ||||
|     cipher((state_t*)outbuffer, ctx); | ||||
|   | ||||
| @@ -98,7 +98,7 @@ _pdfioFileFlush(pdfio_file_t *pdf)	// I - PDF file | ||||
|     if (!write_buffer(pdf, pdf->buffer, (size_t)(pdf->bufptr - pdf->buffer))) | ||||
|       return (false); | ||||
|  | ||||
|     pdf->bufpos += pdf->bufptr - pdf->buffer; | ||||
|     pdf->bufpos += (off_t)(pdf->bufptr - pdf->buffer); | ||||
|   } | ||||
|  | ||||
|   pdf->bufptr = pdf->buffer; | ||||
| @@ -216,7 +216,7 @@ _pdfioFilePeek(pdfio_file_t *pdf,	// I - PDF file | ||||
|     PDFIO_DEBUG("_pdfioFilePeek: Sliding buffer, total=%ld\n", (long)total); | ||||
|  | ||||
|     memmove(pdf->buffer, pdf->bufptr, total); | ||||
|     pdf->bufpos += pdf->bufptr - pdf->buffer; | ||||
|     pdf->bufpos += (off_t)(pdf->bufptr - pdf->buffer); | ||||
|     pdf->bufptr = pdf->buffer; | ||||
|     pdf->bufend = pdf->buffer + total; | ||||
|  | ||||
| @@ -317,14 +317,14 @@ _pdfioFileRead(pdfio_file_t *pdf,	// I - PDF file | ||||
|       // Advance current position in file as needed... | ||||
|       if (pdf->bufend) | ||||
|       { | ||||
| 	pdf->bufpos += pdf->bufend - pdf->buffer; | ||||
| 	pdf->bufpos += (off_t)(pdf->bufend - pdf->buffer); | ||||
| 	pdf->bufptr = pdf->bufend = NULL; | ||||
|       } | ||||
|  | ||||
|       // Read directly from the file... | ||||
|       if ((rbytes = read_buffer(pdf, bufptr, bytes)) > 0) | ||||
|       { | ||||
| 	pdf->bufpos += rbytes; | ||||
| 	pdf->bufpos += (off_t)rbytes; | ||||
| 	continue; | ||||
|       } | ||||
|       else if (rbytes < 0 && (errno == EINTR || errno == EAGAIN)) | ||||
| @@ -361,14 +361,14 @@ _pdfioFileSeek(pdfio_file_t *pdf,	// I - PDF file | ||||
|   // Adjust offset for relative seeks... | ||||
|   if (whence == SEEK_CUR) | ||||
|   { | ||||
|     offset += pdf->bufpos + (pdf->bufptr - pdf->buffer); | ||||
|     offset += pdf->bufpos + (off_t)(pdf->bufptr - pdf->buffer); | ||||
|     whence = SEEK_SET; | ||||
|   } | ||||
|  | ||||
|   if (pdf->mode == _PDFIO_MODE_READ) | ||||
|   { | ||||
|     // Reading, see if we already have the data we need... | ||||
|     if (whence != SEEK_END && offset >= pdf->bufpos && pdf->bufend && offset < (pdf->bufpos + pdf->bufend - pdf->buffer)) | ||||
|     if (whence != SEEK_END && offset >= pdf->bufpos && pdf->bufend && offset < (off_t)(pdf->bufpos + pdf->bufend - pdf->buffer)) | ||||
|     { | ||||
|       // Yes, seek within existing buffer... | ||||
|       pdf->bufptr = pdf->buffer + (offset - pdf->bufpos); | ||||
|   | ||||
| @@ -322,7 +322,7 @@ pdfioArrayCreateColorFromPalette( | ||||
|  | ||||
|   pdfioArrayAppendName(indexed_color, "Indexed"); | ||||
|   pdfioArrayAppendName(indexed_color, "DeviceRGB"); | ||||
|   pdfioArrayAppendNumber(indexed_color, num_colors - 1); | ||||
|   pdfioArrayAppendNumber(indexed_color, (double)(num_colors - 1)); | ||||
|   pdfioArrayAppendBinary(indexed_color, colors, num_colors * 3); | ||||
|  | ||||
|   return (indexed_color); | ||||
| @@ -1814,14 +1814,14 @@ pdfioFileCreateFontObjFromFile( | ||||
|       if ((i - start) > 1) | ||||
|       { | ||||
|         // Encode a repeating sequence... | ||||
|         pdfioArrayAppendNumber(w_array, start); | ||||
|         pdfioArrayAppendNumber(w_array, i - 1); | ||||
|         pdfioArrayAppendNumber(w_array, (double)start); | ||||
|         pdfioArrayAppendNumber(w_array, (double)(i - 1)); | ||||
|         pdfioArrayAppendNumber(w_array, w0); | ||||
|       } | ||||
|       else | ||||
|       { | ||||
|         // Encode a non-repeating sequence... | ||||
|         pdfioArrayAppendNumber(w_array, start); | ||||
|         pdfioArrayAppendNumber(w_array, (double)start); | ||||
|  | ||||
|         if ((temp_array = pdfioArrayCreate(pdf)) == NULL) | ||||
| 	  goto done; | ||||
| @@ -1946,7 +1946,7 @@ pdfioFileCreateICCObjFromData( | ||||
|   if ((dict = pdfioDictCreate(pdf)) == NULL) | ||||
|     return (NULL); | ||||
|  | ||||
|   pdfioDictSetNumber(dict, "N", num_colors); | ||||
|   pdfioDictSetNumber(dict, "N", (double)num_colors); | ||||
|   pdfioDictSetName(dict, "Filter", "FlateDecode"); | ||||
|  | ||||
|   if ((obj = pdfioFileCreateObj(pdf, dict)) == NULL) | ||||
| @@ -2012,7 +2012,7 @@ pdfioFileCreateICCObjFromFile( | ||||
|     return (NULL); | ||||
|   } | ||||
|  | ||||
|   pdfioDictSetNumber(dict, "N", num_colors); | ||||
|   pdfioDictSetNumber(dict, "N", (double)num_colors); | ||||
|   pdfioDictSetName(dict, "Filter", "FlateDecode"); | ||||
|  | ||||
|   if ((obj = pdfioFileCreateObj(pdf, dict)) == NULL) | ||||
| @@ -2095,8 +2095,8 @@ pdfioFileCreateImageObjFromData( | ||||
|   pdfioDictSetName(dict, "Type", "XObject"); | ||||
|   pdfioDictSetName(dict, "Subtype", "Image"); | ||||
|   pdfioDictSetBoolean(dict, "Interpolate", interpolate); | ||||
|   pdfioDictSetNumber(dict, "Width", width); | ||||
|   pdfioDictSetNumber(dict, "Height", height); | ||||
|   pdfioDictSetNumber(dict, "Width", (double)width); | ||||
|   pdfioDictSetNumber(dict, "Height", (double)height); | ||||
|   pdfioDictSetNumber(dict, "BitsPerComponent", 8); | ||||
|  | ||||
|   if (color_data) | ||||
| @@ -2539,7 +2539,7 @@ copy_jpeg(pdfio_dict_t *dict,		// I - Dictionary | ||||
| 	  } | ||||
|  | ||||
|           // Copy from the file buffer to the ICC buffer | ||||
|           if ((bytes = bufend - bufptr) > length) | ||||
|           if ((bytes = bufend - bufptr) > (ssize_t)length) | ||||
| 	    bytes = (ssize_t)length; | ||||
|  | ||||
| 	  memcpy(icc_data + icc_datalen, bufptr, bytes); | ||||
| @@ -2566,7 +2566,7 @@ copy_jpeg(pdfio_dict_t *dict,		// I - Dictionary | ||||
|       { | ||||
|         bytes = bufend - bufptr; | ||||
|  | ||||
|         if (length > bytes) | ||||
|         if (length > (size_t)bytes) | ||||
|         { | ||||
|           // Consume everything we have and grab more... | ||||
|           length -= (size_t)bytes; | ||||
| @@ -2591,7 +2591,10 @@ copy_jpeg(pdfio_dict_t *dict,		// I - Dictionary | ||||
|   } | ||||
|  | ||||
|   if (width == 0 || height == 0 || (num_colors != 1 && num_colors != 3)) | ||||
|     return (NULL); | ||||
|   { | ||||
|     _pdfioFileError(dict->pdf, "Unable to find JPEG dimensions or image data."); | ||||
|     goto finish; | ||||
|   } | ||||
|  | ||||
|   // Create the image object... | ||||
|   pdfioDictSetNumber(dict, "Width", width); | ||||
| @@ -3567,9 +3570,9 @@ create_image( | ||||
|       return (NULL); | ||||
|     } | ||||
|  | ||||
|     pdfioDictSetNumber(decode, "BitsPerComponent", depth); | ||||
|     pdfioDictSetNumber(decode, "BitsPerComponent", (double)depth); | ||||
|     pdfioDictSetNumber(decode, "Colors", 1); | ||||
|     pdfioDictSetNumber(decode, "Columns", width); | ||||
|     pdfioDictSetNumber(decode, "Columns", (double)width); | ||||
|     pdfioDictSetNumber(decode, "Predictor", _PDFIO_PREDICTOR_PNG_AUTO); | ||||
|     pdfioDictSetDict(mask_dict, "DecodeParms", decode); | ||||
|  | ||||
| @@ -3619,9 +3622,9 @@ create_image( | ||||
|     return (NULL); | ||||
|   } | ||||
|  | ||||
|   pdfioDictSetNumber(decode, "BitsPerComponent", depth); | ||||
|   pdfioDictSetNumber(decode, "Colors", num_colors); | ||||
|   pdfioDictSetNumber(decode, "Columns", width); | ||||
|   pdfioDictSetNumber(decode, "BitsPerComponent", (double)depth); | ||||
|   pdfioDictSetNumber(decode, "Colors", (double)num_colors); | ||||
|   pdfioDictSetNumber(decode, "Columns", (double)width); | ||||
|   pdfioDictSetNumber(decode, "Predictor", _PDFIO_PREDICTOR_PNG_AUTO); | ||||
|   pdfioDictSetDict(dict, "DecodeParms", decode); | ||||
|  | ||||
|   | ||||
| @@ -1,7 +1,7 @@ | ||||
| // | ||||
| // Cryptographic support functions for PDFio. | ||||
| // | ||||
| // Copyright © 2021-2023 by Michael R Sweet. | ||||
| // Copyright © 2021-2025 by Michael R Sweet. | ||||
| // | ||||
| // Licensed under Apache License v2.0.  See the file "LICENSE" for more | ||||
| // information. | ||||
| @@ -466,6 +466,7 @@ _pdfioCryptoMakeReader( | ||||
|  | ||||
|       if (memcmp(pdf->password, pdf_user_key, 32) && memcmp(own_user_key, pdf_user_key, 16)) | ||||
|       { | ||||
|         _pdfioFileError(pdf, "Unable to unlock file."); | ||||
| 	*ivlen = 0; | ||||
| 	return (NULL); | ||||
|       } | ||||
| @@ -483,6 +484,7 @@ _pdfioCryptoMakeReader( | ||||
|   switch (pdf->encryption) | ||||
|   { | ||||
|     default : | ||||
|         _pdfioFileError(pdf, "Unsupported encryption algorithm."); | ||||
|         *ivlen = 0; | ||||
|         return (NULL); | ||||
|  | ||||
|   | ||||
							
								
								
									
										14
									
								
								pdfio-file.c
									
									
									
									
									
								
							
							
						
						
									
										14
									
								
								pdfio-file.c
									
									
									
									
									
								
							| @@ -1799,7 +1799,7 @@ load_xref( | ||||
| 	return (false); | ||||
|       } | ||||
|  | ||||
|       if (_pdfioFileSeek(pdf, line_offset + ptr + 3 - line, SEEK_SET) < 0) | ||||
|       if (_pdfioFileSeek(pdf, line_offset + (off_t)(ptr + 3 - line), SEEK_SET) < 0) | ||||
|       { | ||||
|         _pdfioFileError(pdf, "Unable to seek to xref object %lu %u.", (unsigned long)number, (unsigned)generation); | ||||
|         return (false); | ||||
| @@ -1941,7 +1941,7 @@ load_xref( | ||||
|             if (w[0] == 0 || buffer[0] == 1) | ||||
|             { | ||||
|               // Location of object... | ||||
| 	      current->offset = offset; | ||||
| 	      current->offset = (off_t)offset; | ||||
| 	    } | ||||
| 	    else if (number != offset) | ||||
| 	    { | ||||
| @@ -1978,7 +1978,7 @@ load_xref( | ||||
| 	  else if (!current) | ||||
| 	  { | ||||
| 	    // Add this object... | ||||
| 	    if (!add_obj(pdf, (size_t)number, (unsigned short)generation, offset)) | ||||
| 	    if (!add_obj(pdf, (size_t)number, (unsigned short)generation, (off_t)offset)) | ||||
| 	      return (false); | ||||
| 	  } | ||||
|  | ||||
| @@ -2105,7 +2105,7 @@ load_xref( | ||||
| 	  if (pdfioFileFindObj(pdf, (size_t)number)) | ||||
| 	    continue;			// Don't replace newer object... | ||||
|  | ||||
| 	  if (!add_obj(pdf, (size_t)number, (unsigned short)generation, offset)) | ||||
| 	  if (!add_obj(pdf, (size_t)number, (unsigned short)generation, (off_t)offset)) | ||||
| 	    return (false); | ||||
| 	} | ||||
|  | ||||
| @@ -2361,7 +2361,7 @@ write_pages(pdfio_file_t *pdf)		// I - PDF file | ||||
|   for (i = 0; i < pdf->num_pages; i ++) | ||||
|     pdfioArrayAppendObj(kids, pdf->pages[i]); | ||||
|  | ||||
|   pdfioDictSetNumber(pdf->pages_obj->value.value.dict, "Count", pdf->num_pages); | ||||
|   pdfioDictSetNumber(pdf->pages_obj->value.value.dict, "Count", (double)pdf->num_pages); | ||||
|   pdfioDictSetArray(pdf->pages_obj->value.value.dict, "Kids", kids); | ||||
|  | ||||
|   // Write the Pages object... | ||||
| @@ -2438,7 +2438,7 @@ write_trailer(pdfio_file_t *pdf)	// I - PDF file | ||||
|     } | ||||
|  | ||||
|     pdfioDictSetName(xref_dict, "Type", "XRef"); | ||||
|     pdfioDictSetNumber(xref_dict, "Size", pdf->num_objs + 2); | ||||
|     pdfioDictSetNumber(xref_dict, "Size", (double)(pdf->num_objs + 2)); | ||||
|     pdfioDictSetArray(xref_dict, "W", w_array); | ||||
|     pdfioDictSetName(xref_dict, "Filter", "FlateDecode"); | ||||
|     pdfioDictSetObj(xref_dict, "Info", pdf->info_obj); | ||||
| @@ -2586,7 +2586,7 @@ write_trailer(pdfio_file_t *pdf)	// I - PDF file | ||||
|       pdfioDictSetArray(pdf->trailer_dict, "ID", pdf->id_array); | ||||
|     pdfioDictSetObj(pdf->trailer_dict, "Info", pdf->info_obj); | ||||
|     pdfioDictSetObj(pdf->trailer_dict, "Root", pdf->root_obj); | ||||
|     pdfioDictSetNumber(pdf->trailer_dict, "Size", pdf->num_objs + 1); | ||||
|     pdfioDictSetNumber(pdf->trailer_dict, "Size", (double)(pdf->num_objs + 1)); | ||||
|  | ||||
|     if (!_pdfioDictWrite(pdf->trailer_dict, NULL, NULL)) | ||||
|     { | ||||
|   | ||||
| @@ -1,7 +1,7 @@ | ||||
| // | ||||
| // PDF stream functions for PDFio. | ||||
| // | ||||
| // Copyright © 2021-2024 by Michael R Sweet. | ||||
| // Copyright © 2021-2025 by Michael R Sweet. | ||||
| // | ||||
| // Licensed under Apache License v2.0.  See the file "LICENSE" for more | ||||
| // information. | ||||
| @@ -140,7 +140,7 @@ pdfioStreamClose(pdfio_stream_t *st)	// I - Stream | ||||
|     // Update the length as needed... | ||||
|     if (st->length_obj) | ||||
|     { | ||||
|       st->length_obj->value.value.number = st->obj->stream_length; | ||||
|       st->length_obj->value.value.number = (double)st->obj->stream_length; | ||||
|       pdfioObjClose(st->length_obj); | ||||
|     } | ||||
|     else if (st->obj->length_offset) | ||||
| @@ -440,14 +440,14 @@ _pdfioStreamOpen(pdfio_obj_t *obj,	// I - Object | ||||
|  | ||||
|   if ((st->remaining = pdfioObjGetLength(obj)) == 0) | ||||
|   { | ||||
|     free(st); | ||||
|     return (NULL); | ||||
|     _pdfioFileError(obj->pdf, "No stream data."); | ||||
|     goto error; | ||||
|   } | ||||
|  | ||||
|   if (_pdfioFileSeek(st->pdf, obj->stream_offset, SEEK_SET) != obj->stream_offset) | ||||
|   { | ||||
|     free(st); | ||||
|     return (NULL); | ||||
|     _pdfioFileError(obj->pdf, "Unable to seek to stream data."); | ||||
|     goto error; | ||||
|   } | ||||
|  | ||||
|   type = pdfioObjGetType(obj); | ||||
| @@ -460,11 +460,7 @@ _pdfioStreamOpen(pdfio_obj_t *obj,	// I - Object | ||||
|     ivlen = (size_t)_pdfioFilePeek(st->pdf, iv, sizeof(iv)); | ||||
|  | ||||
|     if ((st->crypto_cb = _pdfioCryptoMakeReader(st->pdf, obj, &st->crypto_ctx, iv, &ivlen)) == NULL) | ||||
|     { | ||||
|       // TODO: Add error message? | ||||
|       free(st); | ||||
|       return (NULL); | ||||
|     } | ||||
|       goto error; | ||||
|  | ||||
|     PDFIO_DEBUG("_pdfioStreamOpen: ivlen=%d\n", (int)ivlen); | ||||
|     if (ivlen > 0) | ||||
| @@ -495,8 +491,7 @@ _pdfioStreamOpen(pdfio_obj_t *obj,	// I - Object | ||||
|       { | ||||
| 	// TODO: Implement compound filters... | ||||
| 	_pdfioFileError(st->pdf, "Unsupported compound stream filter."); | ||||
| 	free(st); | ||||
| 	return (NULL); | ||||
| 	goto error; | ||||
|       } | ||||
|  | ||||
|       // No filter, read as-is... | ||||
| @@ -529,8 +524,7 @@ _pdfioStreamOpen(pdfio_obj_t *obj,	// I - Object | ||||
|       else if (bpc < 1 || bpc == 3 || (bpc > 4 && bpc < 8) || (bpc > 8 && bpc < 16) || bpc > 16) | ||||
|       { | ||||
|         _pdfioFileError(st->pdf, "Unsupported BitsPerColor value %d.", bpc); | ||||
|         free(st); | ||||
|         return (NULL); | ||||
| 	goto error; | ||||
|       } | ||||
|  | ||||
|       if (colors == 0) | ||||
| @@ -540,8 +534,7 @@ _pdfioStreamOpen(pdfio_obj_t *obj,	// I - Object | ||||
|       else if (colors < 0 || colors > 4) | ||||
|       { | ||||
|         _pdfioFileError(st->pdf, "Unsupported Colors value %d.", colors); | ||||
|         free(st); | ||||
|         return (NULL); | ||||
| 	goto error; | ||||
|       } | ||||
|  | ||||
|       if (columns == 0) | ||||
| @@ -551,15 +544,13 @@ _pdfioStreamOpen(pdfio_obj_t *obj,	// I - Object | ||||
|       else if (columns < 0) | ||||
|       { | ||||
|         _pdfioFileError(st->pdf, "Unsupported Columns value %d.", columns); | ||||
|         free(st); | ||||
|         return (NULL); | ||||
| 	goto error; | ||||
|       } | ||||
|  | ||||
|       if ((predictor > 2 && predictor < 10) || predictor > 15) | ||||
|       { | ||||
|         _pdfioFileError(st->pdf, "Unsupported Predictor function %d.", predictor); | ||||
|         free(st); | ||||
|         return (NULL); | ||||
| 	goto error; | ||||
|       } | ||||
|       else if (predictor > 1) | ||||
|       { | ||||
| @@ -573,23 +564,19 @@ _pdfioStreamOpen(pdfio_obj_t *obj,	// I - Object | ||||
|         if ((st->prbuffer = calloc(1, st->pbsize - 1)) == NULL || (st->psbuffer = calloc(1, st->pbsize)) == NULL) | ||||
|         { | ||||
|           _pdfioFileError(st->pdf, "Unable to allocate %lu bytes for Predictor buffers.", (unsigned long)st->pbsize); | ||||
| 	  free(st->prbuffer); | ||||
| 	  free(st->psbuffer); | ||||
| 	  free(st); | ||||
| 	  return (NULL); | ||||
| 	  goto error; | ||||
|         } | ||||
|       } | ||||
|       else | ||||
|       { | ||||
|         st->predictor = _PDFIO_PREDICTOR_NONE; | ||||
|       } | ||||
|  | ||||
|       st->cbsize = 4096; | ||||
|       if ((st->cbuffer = malloc(st->cbsize)) == NULL) | ||||
|       { | ||||
| 	_pdfioFileError(st->pdf, "Unable to allocate %lu bytes for Flate compression buffer.", (unsigned long)st->cbsize); | ||||
| 	free(st->prbuffer); | ||||
| 	free(st->psbuffer); | ||||
| 	free(st); | ||||
| 	return (NULL); | ||||
| 	goto error; | ||||
|       } | ||||
|  | ||||
|       PDFIO_DEBUG("_pdfioStreamOpen: pos=%ld\n", (long)_pdfioFileTell(st->pdf)); | ||||
| @@ -601,10 +588,7 @@ _pdfioStreamOpen(pdfio_obj_t *obj,	// I - Object | ||||
|       if (rbytes <= 0) | ||||
|       { | ||||
| 	_pdfioFileError(st->pdf, "Unable to read bytes for stream."); | ||||
| 	free(st->prbuffer); | ||||
| 	free(st->psbuffer); | ||||
| 	free(st); | ||||
| 	return (NULL); | ||||
| 	goto error; | ||||
|       } | ||||
|  | ||||
|       if (st->crypto_cb) | ||||
| @@ -618,10 +602,7 @@ _pdfioStreamOpen(pdfio_obj_t *obj,	// I - Object | ||||
|       if ((status = inflateInit(&(st->flate))) != Z_OK) | ||||
|       { | ||||
| 	_pdfioFileError(st->pdf, "Unable to start Flate filter: %s", zstrerror(status)); | ||||
| 	free(st->prbuffer); | ||||
| 	free(st->psbuffer); | ||||
| 	free(st); | ||||
| 	return (NULL); | ||||
| 	goto error; | ||||
|       } | ||||
|  | ||||
|       st->remaining -= st->flate.avail_in; | ||||
| @@ -635,8 +616,7 @@ _pdfioStreamOpen(pdfio_obj_t *obj,	// I - Object | ||||
|     { | ||||
|       // Something else we don't support | ||||
|       _pdfioFileError(st->pdf, "Unsupported stream filter '/%s'.", filter); | ||||
|       free(st); | ||||
|       return (NULL); | ||||
|       goto error; | ||||
|     } | ||||
|   } | ||||
|   else | ||||
| @@ -646,6 +626,16 @@ _pdfioStreamOpen(pdfio_obj_t *obj,	// I - Object | ||||
|   } | ||||
|  | ||||
|   return (st); | ||||
|  | ||||
|   // If we get here something went wrong... | ||||
|   error: | ||||
|  | ||||
|   free(st->cbuffer); | ||||
|   free(st->prbuffer); | ||||
|   free(st->psbuffer); | ||||
|   free(st); | ||||
|   return (NULL); | ||||
|  | ||||
| } | ||||
|  | ||||
|  | ||||
|   | ||||
		Reference in New Issue
	
	Block a user