Fix some minor Coverity-reported issues (added a check to suppress a warning,

removed an unnecessary check, and removed some dead code)
This commit is contained in:
Michael R Sweet 2021-10-31 07:04:17 -04:00
parent b3ca129a58
commit 9014ab7a20
No known key found for this signature in database
GPG Key ID: BE67C75EC81F3244
3 changed files with 15 additions and 14 deletions

View File

@ -68,7 +68,7 @@ static const uint8_t rsbox[256] = // Reverse S-box lookup table
0x17, 0x2b, 0x04, 0x7e, 0xba, 0x77, 0xd6, 0x26, 0xe1, 0x69, 0x14, 0x63, 0x55, 0x21, 0x0c, 0x7d
};
// The round constant word array, Rcon[i], contains the values given by
// The round constant word array, Rcon[i], contains the values given by
// x to the power (i-1) being powers of x (x is denoted as {02}) in the field GF(2^8)
static const uint8_t Rcon[11] = // Round constants
{
@ -222,6 +222,9 @@ _pdfioCryptoAESEncrypt(
size_t outbytes = 0; // Output bytes
if (len == 0)
return (0);
if (inbuffer != outbuffer)
{
// Not the most efficient, but we can optimize later - the sample AES code
@ -295,14 +298,14 @@ ShiftRows(state_t *state)
uint8_t temp; // Temporary value
// Rotate first row 1 columns to left
// Rotate first row 1 columns to left
temp = sptr[1];
sptr[1] = sptr[5];
sptr[5] = sptr[9];
sptr[9] = sptr[13];
sptr[13] = temp;
// Rotate second row 2 columns to left
// Rotate second row 2 columns to left
temp = sptr[2];
sptr[2] = sptr[10];
sptr[10] = temp;
@ -336,7 +339,7 @@ MixColumns(state_t *state)
uint8_t Tmp, Tm, t; // Temporary values
for (i = 4; i > 0; i --, sptr += 4)
{
{
t = sptr[0];
Tmp = sptr[0] ^ sptr[1] ^ sptr[2] ^ sptr[3];
Tm = sptr[0] ^ sptr[1];
@ -384,7 +387,7 @@ InvMixColumns(state_t *state)
for (i = 4; i > 0; i --)
{
{
a = sptr[0];
b = sptr[1];
c = sptr[2];
@ -419,14 +422,14 @@ InvShiftRows(state_t *state)
uint8_t temp; // Temporary value
// Rotate first row 1 columns to right
// Rotate first row 1 columns to right
temp = sptr[13];
sptr[13] = sptr[9];
sptr[9] = sptr[5];
sptr[5] = sptr[1];
sptr[1] = temp;
// Rotate second row 2 columns to right
// Rotate second row 2 columns to right
temp = sptr[2];
sptr[2] = sptr[10];
sptr[10] = temp;

View File

@ -366,9 +366,7 @@ _pdfioArrayDelete(pdfio_array_t *a) // I - Array
free(a->values[i].value.binary.data);
}
if (a)
free(a->values);
free(a->values);
free(a);
}

View File

@ -81,7 +81,7 @@
// V6+R6 handler:
//
// TODO: document V6+R6 handler
//
//
//
// Local globals...
@ -177,7 +177,7 @@ _pdfioCryptoLock(
pdfioDictSetNumber(dict, "R", encryption == PDFIO_ENCRYPTION_RC4_128 ? 3 : 4);
pdfioDictSetNumber(dict, "V", encryption == PDFIO_ENCRYPTION_RC4_128 ? 2 : 4);
pdfioDictSetBinary(dict, "U", pdf->user_key, sizeof(pdf->user_key));
if (encryption == PDFIO_ENCRYPTION_AES_128)
{
if ((cf_dict = pdfioDictCreate(pdf)) == NULL)
@ -193,7 +193,7 @@ _pdfioCryptoLock(
}
pdfioDictSetName(filter_dict, "Type", "CryptFilter");
pdfioDictSetName(filter_dict, "CFM", encryption == PDFIO_ENCRYPTION_RC4_128 ? "V2" : "AESV2");
pdfioDictSetName(filter_dict, "CFM", "AESV2");
pdfioDictSetDict(cf_dict, "PDFio", filter_dict);
pdfioDictSetDict(dict, "CF", cf_dict);
pdfioDictSetName(dict, "StmF", "PDFio");
@ -658,7 +658,7 @@ _pdfioCryptoUnlock(
_pdfioCryptoMD5Append(&md5, pdf_passpad, 32);
_pdfioCryptoMD5Append(&md5, file_id, file_idlen);
_pdfioCryptoMD5Finish(&md5, file_digest);
// Now try to unlock the PDF...
for (tries = 0; tries < 4; tries ++)
{