--- embedaddon/php/ext/fileinfo/libmagic/is_tar.c 2012/02/21 23:47:56 1.1 +++ embedaddon/php/ext/fileinfo/libmagic/is_tar.c 2012/05/29 12:34:39 1.1.1.2 @@ -2,7 +2,7 @@ * Copyright (c) Ian F. Darwin 1986-1995. * Software written by Ian F. Darwin and others; * maintained 1995-present by Christos Zoulas and others. - * + * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: @@ -12,7 +12,7 @@ * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * + * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE @@ -40,7 +40,7 @@ #include "file.h" #ifndef lint -FILE_RCSID("@(#)$File: is_tar.c,v 1.36 2009/02/03 20:27:51 christos Exp $") +FILE_RCSID("@(#)$File: is_tar.c,v 1.37 2010/11/30 14:58:53 rrt Exp $") #endif #include "magic.h" @@ -83,8 +83,8 @@ file_is_tar(struct magic_set *ms, const unsigned char } /* - * Return - * 0 if the checksum is bad (i.e., probably not a tar archive), + * Return + * 0 if the checksum is bad (i.e., probably not a tar archive), * 1 for old UNIX tar file, * 2 for Unix Std (POSIX) tar file, * 3 for GNU tar file. @@ -95,7 +95,7 @@ is_tar(const unsigned char *buf, size_t nbytes) const union record *header = (const union record *)(const void *)buf; int i; int sum, recsum; - const char *p; + const unsigned char *p; if (nbytes < sizeof(union record)) return 0; @@ -104,25 +104,20 @@ is_tar(const unsigned char *buf, size_t nbytes) sum = 0; p = header->charptr; - for (i = sizeof(union record); --i >= 0;) { - /* - * We cannot use unsigned char here because of old compilers, - * e.g. V7. - */ - sum += 0xFF & *p++; - } + for (i = sizeof(union record); --i >= 0;) + sum += *p++; /* Adjust checksum to count the "chksum" field as blanks. */ for (i = sizeof(header->header.chksum); --i >= 0;) - sum -= 0xFF & header->header.chksum[i]; - sum += ' '* sizeof header->header.chksum; + sum -= header->header.chksum[i]; + sum += ' ' * sizeof header->header.chksum; if (sum != recsum) return 0; /* Not a tar archive */ - - if (strcmp(header->header.magic, GNUTMAGIC) == 0) + + if (strcmp(header->header.magic, GNUTMAGIC) == 0) return 3; /* GNU Unix Standard tar archive */ - if (strcmp(header->header.magic, TMAGIC) == 0) + if (strcmp(header->header.magic, TMAGIC) == 0) return 2; /* Unix Standard tar archive */ return 1; /* Old fashioned tar archive */ @@ -132,7 +127,7 @@ is_tar(const unsigned char *buf, size_t nbytes) /* * Quick and dirty octal conversion. * - * Result is -1 if the field is invalid (all blank, or nonoctal). + * Result is -1 if the field is invalid (all blank, or non-octal). */ private int from_oct(int digs, const char *where) @@ -145,13 +140,13 @@ from_oct(int digs, const char *where) return -1; /* All blank field */ } value = 0; - while (digs > 0 && isodigit(*where)) { /* Scan til nonoctal */ + while (digs > 0 && isodigit(*where)) { /* Scan til non-octal */ value = (value << 3) | (*where++ - '0'); --digs; } if (digs > 0 && *where && !isspace((unsigned char)*where)) - return -1; /* Ended on non-space/nul */ + return -1; /* Ended on non-(space/NUL) */ return value; }