mirror of
https://github.com/MidnightCommander/mc
synced 2024-12-22 20:36:50 +03:00
tar: avoid casts in tar_checksum.
* (tar_checksum): recode to avoid casts. * (tar_from_header): likewise. Sync with GNU tar 1521d3dae01f91606c639eb745ea565ef723e38d. Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
This commit is contained in:
parent
7d8deb89c8
commit
b6483b8a47
@ -464,7 +464,10 @@ tar_from_header (const char *where0, size_t digs, char const *type, intmax_t min
|
||||
|
||||
while (TRUE)
|
||||
{
|
||||
value = (value << LG_256) + (unsigned char) *where++;
|
||||
unsigned char uc;
|
||||
|
||||
uc = *where++;
|
||||
value = (value << LG_256) + uc;
|
||||
if (where == lim)
|
||||
break;
|
||||
|
||||
|
@ -327,39 +327,42 @@ tar_available_space_after (const union block *pointer)
|
||||
static read_header
|
||||
tar_checksum (const union block *header)
|
||||
{
|
||||
size_t i;
|
||||
int i;
|
||||
int unsigned_sum = 0; /* the POSIX one :-) */
|
||||
int signed_sum = 0; /* the Sun one :-( */
|
||||
int recorded_sum;
|
||||
int parsed_sum;
|
||||
const char *p = header->buffer;
|
||||
|
||||
for (i = sizeof (*header); i-- != 0;)
|
||||
for (i = 0; i < sizeof (*header); i++)
|
||||
{
|
||||
unsigned_sum += (unsigned char) *p;
|
||||
signed_sum += (signed char) (*p++);
|
||||
unsigned char uc = header->buffer[i];
|
||||
signed char sc = header->buffer[i];
|
||||
|
||||
unsigned_sum += uc;
|
||||
signed_sum += sc;
|
||||
}
|
||||
|
||||
if (unsigned_sum == 0)
|
||||
return HEADER_ZERO_BLOCK;
|
||||
|
||||
/* Adjust checksum to count the "chksum" field as blanks. */
|
||||
for (i = sizeof (header->header.chksum); i-- != 0;)
|
||||
for (i = 0; i < sizeof (header->header.chksum); i++)
|
||||
{
|
||||
unsigned_sum -= (unsigned char) header->header.chksum[i];
|
||||
signed_sum -= (signed char) (header->header.chksum[i]);
|
||||
unsigned char uc = header->header.chksum[i];
|
||||
signed char sc = header->header.chksum[i];
|
||||
|
||||
unsigned_sum -= uc;
|
||||
signed_sum -= sc;
|
||||
}
|
||||
|
||||
unsigned_sum += ' ' * sizeof (header->header.chksum);
|
||||
signed_sum += ' ' * sizeof (header->header.chksum);
|
||||
|
||||
parsed_sum =
|
||||
recorded_sum =
|
||||
tar_from_header (header->header.chksum, sizeof (header->header.chksum), NULL, 0,
|
||||
INT_MAX, TRUE);
|
||||
if (parsed_sum < 0)
|
||||
return HEADER_FAILURE;
|
||||
|
||||
recorded_sum = parsed_sum;
|
||||
if (recorded_sum < 0)
|
||||
return HEADER_FAILURE;
|
||||
|
||||
if (unsigned_sum != recorded_sum && signed_sum != recorded_sum)
|
||||
return HEADER_FAILURE;
|
||||
|
Loading…
Reference in New Issue
Block a user