AC_CHECK_HEADERS([sys/select.h sys/statfs.h sys/statvfs.h sys/sysmacros.h])
AC_CHECK_HEADERS([sys/time.h sys/utime.h sys/utsname.h sys/vfs.h sys/xattr.h])
AC_CHECK_HEADERS([time.h unistd.h utime.h wchar.h wctype.h])
+AC_CHECK_TYPE([suseconds_t])
AC_CHECK_HEADERS([windows.h])
# check windows.h first; the other headers require it.
AC_CHECK_HEADERS([wincrypt.h winioctl.h],[],[],
char *user;
struct passwd *pwent;
- user = (char *)malloc(ue - u + 1);
+ user = malloc(ue - u + 1);
if (user == NULL)
goto alloc_error;
memcpy(user, u, ue - u);
int type, int permset, int tag, int id, const char *name,
size_t len, struct archive_string_conv *sc);
static int archive_acl_text_want_type(struct archive_acl *acl, int flags);
-static ssize_t archive_acl_text_len(struct archive_acl *acl, int want_type,
+static size_t archive_acl_text_len(struct archive_acl *acl, int want_type,
int flags, int wide, struct archive *a,
struct archive_string_conv *sc);
static int isint_w(const wchar_t *start, const wchar_t *end, int *result);
}
/* Add a new entry to the end of the list. */
- ap = (struct archive_acl_entry *)calloc(1, sizeof(*ap));
+ ap = calloc(1, sizeof(*ap));
if (ap == NULL)
return (NULL);
if (aq == NULL)
/*
* Calculate ACL text string length
*/
-static ssize_t
+static size_t
archive_acl_text_len(struct archive_acl *acl, int want_type, int flags,
int wide, struct archive *a, struct archive_string_conv *sc) {
struct archive_acl_entry *ap;
const char *name;
const wchar_t *wname;
int count, idlen, tmp, r;
- ssize_t length;
+ size_t length;
size_t len;
count = 0;
struct archive *a)
{
int count;
- ssize_t length;
+ size_t length;
size_t len;
const wchar_t *wname;
const wchar_t *prefix;
separator = L'\n';
/* Now, allocate the string and actually populate it. */
- wp = ws = (wchar_t *)malloc(length * sizeof(wchar_t));
+ wp = ws = malloc(length * sizeof(*wp));
if (wp == NULL) {
if (errno == ENOMEM)
__archive_errx(1, "No memory");
len = wcslen(ws);
- if ((ssize_t)len > (length - 1))
+ if (len > length - 1)
__archive_errx(1, "Buffer overrun");
if (text_len != NULL)
struct archive_string_conv *sc)
{
int count;
- ssize_t length;
+ size_t length;
size_t len;
const char *name;
const char *prefix;
separator = '\n';
/* Now, allocate the string and actually populate it. */
- p = s = (char *)malloc(length * sizeof(char));
+ p = s = malloc(length * sizeof(*p));
if (p == NULL) {
if (errno == ENOMEM)
__archive_errx(1, "No memory");
len = strlen(s);
- if ((ssize_t)len > (length - 1))
+ if (len > length - 1)
__archive_errx(1, "Buffer overrun");
if (text_len != NULL)
{
struct archive_entry *entry;
- entry = (struct archive_entry *)calloc(1, sizeof(*entry));
+ entry = calloc(1, sizeof(*entry));
if (entry == NULL)
return (NULL);
entry->archive = a;
if (length == 0)
return (NULL);
- string = (char *)malloc(length);
+ string = malloc(length);
if (string == NULL)
return (NULL);
}
}
- if ((sp = (struct ae_sparse *)malloc(sizeof(*sp))) == NULL)
+ if ((sp = malloc(sizeof(*sp))) == NULL)
/* XXX Error XXX */
return;
{
struct ae_xattr *xp;
- if ((xp = (struct ae_xattr *)malloc(sizeof(struct ae_xattr))) == NULL)
+ if ((xp = malloc(sizeof(struct ae_xattr))) == NULL)
__archive_errx(1, "Out of memory");
if ((xp->name = strdup(name)) == NULL)
{
struct archive_match *a;
- a = (struct archive_match *)calloc(1, sizeof(*a));
+ a = calloc(1, sizeof(*a));
if (a == NULL)
return (NULL);
a->archive.magic = ARCHIVE_MATCH_MAGIC;
#include <string.h> /* memset */
static inline EVP_MD_CTX *EVP_MD_CTX_new(void)
{
- EVP_MD_CTX *ctx = (EVP_MD_CTX *)calloc(1, sizeof(EVP_MD_CTX));
+ EVP_MD_CTX *ctx = calloc(1, sizeof(EVP_MD_CTX));
return ctx;
}
#include <string.h> /* memset */
static inline HMAC_CTX *HMAC_CTX_new(void)
{
- HMAC_CTX *ctx = (HMAC_CTX *)calloc(1, sizeof(HMAC_CTX));
+ HMAC_CTX *ctx = calloc(1, sizeof(HMAC_CTX));
return ctx;
}
#else
4 - (size & 3);
#endif
- if ((p->Base = (Byte *)malloc(p->AlignOffset + size
+ if ((p->Base = malloc(p->AlignOffset + size
#ifndef PPMD_32BIT
+ UNIT_SIZE
#endif
#else
4 - (size & 3);
#endif
- if ((p->Base = (Byte *)malloc(p->AlignOffset + size)) == 0)
+ if ((p->Base = malloc(p->AlignOffset + size)) == 0)
return False;
p->Size = size;
}
{
struct archive_read *a;
- a = (struct archive_read *)calloc(1, sizeof(*a));
+ a = calloc(1, sizeof(*a));
if (a == NULL)
return (NULL);
a->archive.magic = ARCHIVE_READ_MAGIC;
}
filter
- = (struct archive_read_filter *)calloc(1, sizeof(*filter));
+ = calloc(1, sizeof(*filter));
if (filter == NULL)
return (ARCHIVE_FATAL);
filter->bidder = best_bidder;
s = t;
}
/* Now s >= min, so allocate a new buffer. */
- p = (char *)malloc(s);
+ p = malloc(s);
if (p == NULL) {
archive_set_error(
&filter->archive->archive,
return (ARCHIVE_FATAL);
}
- filter
- = (struct archive_read_filter *)calloc(1, sizeof(*filter));
+ filter = calloc(1, sizeof(*filter));
if (filter == NULL)
{
archive_set_error(&a->archive, ENOMEM, "Out of memory");
return (ARCHIVE_FATAL);
}
- filter
- = (struct archive_read_filter *)calloc(1, sizeof(*filter));
+ filter = calloc(1, sizeof(*filter));
if (filter == NULL)
{
archive_set_error(&a->archive, ENOMEM, "Out of memory");
{
struct archive_read_disk *a;
- a = (struct archive_read_disk *)calloc(1, sizeof(*a));
+ a = calloc(1, sizeof(*a));
if (a == NULL)
return (NULL);
a->archive.magic = ARCHIVE_READ_DISK_MAGIC;
{
struct archive_read_disk *a;
- a = (struct archive_read_disk *)calloc(1, sizeof(*a));
+ a = calloc(1, sizeof(*a));
if (a == NULL)
return (NULL);
a->archive.magic = ARCHIVE_READ_DISK_MAGIC;
range.FileOffset.QuadPart = 0;
range.Length.QuadPart = entry_size;
outranges_size = 2048;
- outranges = (FILE_ALLOCATED_RANGE_BUFFER *)malloc(outranges_size);
+ outranges = malloc(outranges_size);
if (outranges == NULL) {
archive_set_error(&a->archive, ENOMEM,
"Couldn't allocate memory");
__archive_read_get_extract(struct archive_read *a)
{
if (a->extract == NULL) {
- a->extract = (struct archive_read_extract *)calloc(1, sizeof(*a->extract));
+ a->extract = calloc(1, sizeof(*a->extract));
if (a->extract == NULL) {
archive_set_error(&a->archive, ENOMEM, "Can't extract");
return (NULL);
return (ARCHIVE_FATAL);
}
- mine = (struct read_fd_data *)calloc(1, sizeof(*mine));
+ mine = calloc(1, sizeof(*mine));
b = malloc(block_size);
if (mine == NULL || b == NULL) {
archive_set_error(a, ENOMEM, "No memory");
void *b;
archive_clear_error(a);
- mine = (struct read_FILE_data *)malloc(sizeof(*mine));
+ mine = malloc(sizeof(*mine));
b = malloc(block_size);
if (mine == NULL || b == NULL) {
archive_set_error(a, ENOMEM, "No memory");
{
if (filename == NULL)
filename = "";
- mine = (struct read_file_data *)calloc(1,
+ mine = calloc(1,
sizeof(*mine) + strlen(filename));
if (mine == NULL)
goto no_memory;
{
if (wfilename == NULL)
wfilename = L"";
- mine = (struct read_file_data *)calloc(1,
+ mine = calloc(1,
sizeof(*mine) + wcslen(wfilename) * sizeof(wchar_t));
if (mine == NULL)
goto no_memory;
{
struct read_memory_data *mine;
- mine = (struct read_memory_data *)calloc(1, sizeof(*mine));
+ mine = calloc(1, sizeof(*mine));
if (mine == NULL) {
archive_set_error(a, ENOMEM, "No memory");
return (ARCHIVE_FATAL);
self->code = ARCHIVE_FILTER_BZIP2;
self->name = "bzip2";
- state = (struct private_data *)calloc(1, sizeof(*state));
- out_block = (unsigned char *)malloc(out_block_size);
+ state = calloc(1, sizeof(*state));
+ out_block = malloc(out_block_size);
if (state == NULL || out_block == NULL) {
archive_set_error(&self->archive->archive, ENOMEM,
"Can't allocate data for bzip2 decompression");
self->code = ARCHIVE_FILTER_COMPRESS;
self->name = "compress (.Z)";
- state = (struct private_data *)calloc(1, sizeof(*state));
+ state = calloc(1, sizeof(*state));
out_block = malloc(out_block_size);
if (state == NULL || out_block == NULL) {
free(out_block);
self->code = ARCHIVE_FILTER_GZIP;
self->name = "gzip";
- state = (struct private_data *)calloc(1, sizeof(*state));
- out_block = (unsigned char *)malloc(out_block_size);
+ state = calloc(1, sizeof(*state));
+ out_block = malloc(out_block_size);
if (state == NULL || out_block == NULL) {
free(out_block);
free(state);
self->code = ARCHIVE_FILTER_LZ4;
self->name = "lz4";
- state = (struct private_data *)calloc(1, sizeof(*state));
+ state = calloc(1, sizeof(*state));
if (state == NULL) {
archive_set_error(&self->archive->archive, ENOMEM,
"Can't allocate data for lz4 decompression");
out_block_size += 64 * 1024;
if (state->out_block_size < out_block_size) {
free(state->out_block);
- out_block = (unsigned char *)malloc(out_block_size);
+ out_block = malloc(out_block_size);
state->out_block_size = out_block_size;
if (out_block == NULL) {
archive_set_error(&self->archive->archive, ENOMEM,
if (state->out_block_size < out_block_size) {
free(state->out_block);
- out_block = (unsigned char *)malloc(out_block_size);
+ out_block = malloc(out_block_size);
state->out_block_size = out_block_size;
if (out_block == NULL) {
archive_set_error(&self->archive->archive, ENOMEM,
self->code = ARCHIVE_FILTER_LZOP;
self->name = "lzop";
- state = (struct read_lzop *)calloc(1, sizeof(*state));
+ state = calloc(1, sizeof(*state));
if (state == NULL) {
archive_set_error(&self->archive->archive, ENOMEM,
"Can't allocate data for lzop decompression");
/*
* Allocate our private state.
*/
- state = (struct program_bidder *)calloc(1, sizeof (*state));
+ state = calloc(1, sizeof (*state));
if (state == NULL)
goto memerr;
state->cmd = strdup(cmd);
size_t l;
l = strlen(prefix) + strlen(cmd) + 1;
- state = (struct program_filter *)calloc(1, sizeof(*state));
- out_buf = (char *)malloc(out_buf_len);
+ state = calloc(1, sizeof(*state));
+ out_buf = malloc(out_buf_len);
if (state == NULL || out_buf == NULL ||
archive_string_ensure(&state->description, l) == NULL) {
archive_set_error(&self->archive->archive, ENOMEM,
self->code = ARCHIVE_FILTER_RPM;
self->name = "rpm";
- rpm = (struct rpm *)calloc(1, sizeof(*rpm));
+ rpm = calloc(1, sizeof(*rpm));
if (rpm == NULL) {
archive_set_error(&self->archive->archive, ENOMEM,
"Can't allocate data for rpm");
self->code = ARCHIVE_FILTER_UU;
self->name = "uu";
- uudecode = (struct uudecode *)calloc(1, sizeof(*uudecode));
+ uudecode = calloc(1, sizeof(*uudecode));
out_buff = malloc(OUT_BUFF_SIZE);
in_buff = malloc(IN_BUFF_SIZE);
if (uudecode == NULL || out_buff == NULL || in_buff == NULL) {
struct private_data *state;
int ret;
- state = (struct private_data *)calloc(1, sizeof(*state));
- out_block = (unsigned char *)malloc(out_block_size);
+ state = calloc(1, sizeof(*state));
+ out_block = malloc(out_block_size);
if (state == NULL || out_block == NULL) {
archive_set_error(&self->archive->archive, ENOMEM,
"Can't allocate data for xz decompression");
self->code = ARCHIVE_FILTER_ZSTD;
self->name = "zstd";
- state = (struct private_data *)calloc(1, sizeof(*state));
- out_block = (unsigned char *)malloc(out_block_size);
+ state = calloc(1, sizeof(*state));
+ out_block = malloc(out_block_size);
dstream = ZSTD_createDStream();
if (state == NULL || out_block == NULL || dstream == NULL) {
if (zip_entry->attr & supported_attrs) {
char *fflags_text, *ptr;
- /* allocate for "rdonly,hidden,system," */
- fflags_text = malloc(22 * sizeof(char));
+ /* allocate for ",rdonly,hidden,system" */
+ fflags_text = malloc(22 * sizeof(*fflags_text));
if (fflags_text != NULL) {
ptr = fflags_text;
- if (zip_entry->attr & FILE_ATTRIBUTE_READONLY) {
- strcpy(ptr, "rdonly,");
- ptr = ptr + 7;
- }
- if (zip_entry->attr & FILE_ATTRIBUTE_HIDDEN) {
- strcpy(ptr, "hidden,");
- ptr = ptr + 7;
- }
- if (zip_entry->attr & FILE_ATTRIBUTE_SYSTEM) {
- strcpy(ptr, "system,");
- ptr = ptr + 7;
- }
- if (ptr > fflags_text) {
- /* Delete trailing comma */
- *(ptr - 1) = '\0';
- archive_entry_copy_fflags_text(entry,
- fflags_text);
- }
- free(fflags_text);
+ if (zip_entry->attr & FILE_ATTRIBUTE_READONLY) {
+ strcpy(ptr, ",rdonly");
+ ptr = ptr + 7;
+ }
+ if (zip_entry->attr & FILE_ATTRIBUTE_HIDDEN) {
+ strcpy(ptr, ",hidden");
+ ptr = ptr + 7;
+ }
+ if (zip_entry->attr & FILE_ATTRIBUTE_SYSTEM) {
+ strcpy(ptr, ",system");
+ ptr = ptr + 7;
+ }
+ if (ptr > fflags_text) {
+ archive_entry_copy_fflags_text(entry,
+ fflags_text + 1);
+ }
+ free(fflags_text);
}
}
archive_check_magic(_a, ARCHIVE_READ_MAGIC,
ARCHIVE_STATE_NEW, "archive_read_support_format_ar");
- ar = (struct ar *)calloc(1, sizeof(*ar));
+ ar = calloc(1, sizeof(*ar));
if (ar == NULL) {
archive_set_error(&a->archive, ENOMEM,
"Can't allocate ar data");
return (ARCHIVE_FATAL);
}
/* Store it in the entry. */
- p = (char *)malloc(bsd_name_length + 1);
+ p = malloc(bsd_name_length + 1);
if (p == NULL) {
archive_set_error(&a->archive, ENOMEM,
"Can't allocate fname buffer");
archive_check_magic(_a, ARCHIVE_READ_MAGIC,
ARCHIVE_STATE_NEW, "archive_read_support_format_cab");
- cab = (struct cab *)calloc(1, sizeof(*cab));
+ cab = calloc(1, sizeof(*cab));
if (cab == NULL) {
archive_set_error(&a->archive, ENOMEM,
"Can't allocate CAB data");
/*
* Read CFFOLDER.
*/
- hd->folder_array = (struct cffolder *)calloc(
+ hd->folder_array = calloc(
hd->folder_count, sizeof(struct cffolder));
if (hd->folder_array == NULL)
goto nomem;
cab->cab_offset += skip;
}
/* Allocate memory for CFDATA */
- hd->file_array = (struct cffile *)calloc(
+ hd->file_array = calloc(
hd->file_count, sizeof(struct cffile));
if (hd->file_array == NULL)
goto nomem;
if (cab->uncompressed_buffer == NULL) {
cab->uncompressed_buffer_size = 0x8000;
cab->uncompressed_buffer
- = (unsigned char *)malloc(cab->uncompressed_buffer_size);
+ = malloc(cab->uncompressed_buffer_size);
if (cab->uncompressed_buffer == NULL) {
archive_set_error(&a->archive, ENOMEM,
"No memory for CAB reader");
if (cab->uncompressed_buffer == NULL) {
cab->uncompressed_buffer_size = 0x8000;
cab->uncompressed_buffer
- = (unsigned char *)malloc(cab->uncompressed_buffer_size);
+ = malloc(cab->uncompressed_buffer_size);
if (cab->uncompressed_buffer == NULL) {
archive_set_error(&a->archive, ENOMEM,
"No memory for CAB reader");
archive_check_magic(_a, ARCHIVE_READ_MAGIC,
ARCHIVE_STATE_NEW, "archive_read_support_format_cpio");
- cpio = (struct cpio *)calloc(1, sizeof(*cpio));
+ cpio = calloc(1, sizeof(*cpio));
if (cpio == NULL) {
archive_set_error(&a->archive, ENOMEM, "Can't allocate cpio data");
return (ARCHIVE_FATAL);
}
}
- le = (struct links_entry *)malloc(sizeof(struct links_entry));
+ le = malloc(sizeof(struct links_entry));
if (le == NULL) {
archive_set_error(&a->archive,
ENOMEM, "Out of memory adding file to list");
archive_check_magic(_a, ARCHIVE_READ_MAGIC,
ARCHIVE_STATE_NEW, "archive_read_support_format_iso9660");
- iso9660 = (struct iso9660 *)calloc(1, sizeof(*iso9660));
+ iso9660 = calloc(1, sizeof(*iso9660));
if (iso9660 == NULL) {
archive_set_error(&a->archive, ENOMEM,
"Can't allocate iso9660 data");
}
/* Create a new file entry and copy data from the ISO dir record. */
- file = (struct file_info *)calloc(1, sizeof(*file));
+ file = calloc(1, sizeof(*file));
if (file == NULL) {
archive_set_error(&a->archive, ENOMEM,
"No memory for file entry");
archive_check_magic(_a, ARCHIVE_READ_MAGIC,
ARCHIVE_STATE_NEW, "archive_read_support_format_lha");
- lha = (struct lha *)calloc(1, sizeof(*lha));
+ lha = calloc(1, sizeof(*lha));
if (lha == NULL) {
archive_set_error(&a->archive, ENOMEM,
"Can't allocate lha data");
archive_check_magic(_a, ARCHIVE_READ_MAGIC,
ARCHIVE_STATE_NEW, "archive_read_support_format_mtree");
- mtree = (struct mtree *)calloc(1, sizeof(*mtree));
+ mtree = calloc(1, sizeof(*mtree));
if (mtree == NULL) {
archive_set_error(&a->archive, ENOMEM,
"Can't allocate mtree data");
archive_check_magic(_a, ARCHIVE_READ_MAGIC, ARCHIVE_STATE_NEW,
"archive_read_support_format_rar");
- rar = (struct rar *)calloc(1, sizeof(*rar));
+ rar = calloc(1, sizeof(*rar));
if (rar == NULL)
{
archive_set_error(&a->archive, ENOMEM, "Can't allocate rar data");
else
code->tablesize = code->maxlength;
- code->table =
- (struct huffman_table_entry *)calloc(1, sizeof(*code->table)
- * ((size_t)1 << code->tablesize));
+ code->table = calloc(1U << code->tablesize, sizeof(*code->table));
return make_table_recurse(a, code, 0, code->table, 0, code->tablesize);
}
/* Allocates a new filter descriptor and adds it to the filter array. */
static struct filter_info* add_new_filter(struct rar5* rar) {
- struct filter_info* f =
- (struct filter_info*) calloc(1, sizeof(struct filter_info));
+ struct filter_info* f = calloc(1, sizeof(*f));
if(!f) {
return NULL;
if (file_attr & (ATTR_READONLY | ATTR_HIDDEN | ATTR_SYSTEM)) {
char *fflags_text, *ptr;
- /* allocate for "rdonly,hidden,system," */
- fflags_text = malloc(22 * sizeof(char));
+ /* allocate for ",rdonly,hidden,system" */
+ fflags_text = malloc(22 * sizeof(*fflags_text));
if (fflags_text != NULL) {
ptr = fflags_text;
if (file_attr & ATTR_READONLY) {
- strcpy(ptr, "rdonly,");
+ strcpy(ptr, ",rdonly");
ptr = ptr + 7;
}
if (file_attr & ATTR_HIDDEN) {
- strcpy(ptr, "hidden,");
+ strcpy(ptr, ",hidden");
ptr = ptr + 7;
}
if (file_attr & ATTR_SYSTEM) {
- strcpy(ptr, "system,");
+ strcpy(ptr, ",system");
ptr = ptr + 7;
}
if (ptr > fflags_text) {
- /* Delete trailing comma */
- *(ptr - 1) = '\0';
archive_entry_copy_fflags_text(entry,
- fflags_text);
+ fflags_text + 1);
}
free(fflags_text);
}
archive_check_magic(_a, ARCHIVE_READ_MAGIC,
ARCHIVE_STATE_NEW, "archive_read_support_format_raw");
- info = (struct raw_info *)calloc(1, sizeof(*info));
+ info = calloc(1, sizeof(*info));
if (info == NULL) {
archive_set_error(&a->archive, ENOMEM,
"Can't allocate raw_info data");
archive_check_magic(_a, ARCHIVE_READ_MAGIC,
ARCHIVE_STATE_NEW, "archive_read_support_format_tar");
- tar = (struct tar *)calloc(1, sizeof(*tar));
+ tar = calloc(1, sizeof(*tar));
if (tar == NULL) {
archive_set_error(&a->archive, ENOMEM,
"Can't allocate tar data");
{
struct sparse_block *p;
- p = (struct sparse_block *)calloc(1, sizeof(*p));
+ p = calloc(1, sizeof(*p));
if (p == NULL) {
archive_set_error(&a->archive, ENOMEM, "Out of memory");
return (ARCHIVE_FATAL);
/* Allocate enough space to hold the entire output. */
/* Note that we may not use all of this... */
- out = (char *)malloc(len - len / 4 + 1);
+ out = malloc(len - len / 4 + 1);
if (out == NULL) {
*out_len = 0;
return (NULL);
char *out, *d;
const char *s;
- out = (char *)malloc(length + 1);
+ out = malloc(length + 1);
if (out == NULL)
return (NULL);
for (s = in, d = out; length > 0 && *s != '\0'; ) {
archive_check_magic(_a, ARCHIVE_READ_MAGIC,
ARCHIVE_STATE_NEW, "archive_read_support_format_xar");
- xar = (struct xar *)calloc(1, sizeof(*xar));
+ xar = calloc(1, sizeof(*xar));
if (xar == NULL) {
archive_set_error(&a->archive, ENOMEM,
"Can't allocate xar data");
free(zip->uncompressed_buffer);
zip->uncompressed_buffer_size = 256 * 1024;
- zip->uncompressed_buffer =
- (uint8_t*) malloc(zip->uncompressed_buffer_size);
+ zip->uncompressed_buffer = malloc(zip->uncompressed_buffer_size);
if (zip->uncompressed_buffer == NULL) {
archive_set_error(&a->archive, ENOMEM,
"No memory for xz decompression");
if(!zip->uncompressed_buffer) {
zip->uncompressed_buffer_size = 256 * 1024;
- zip->uncompressed_buffer =
- (uint8_t*) malloc(zip->uncompressed_buffer_size);
+ zip->uncompressed_buffer = malloc(zip->uncompressed_buffer_size);
if (zip->uncompressed_buffer == NULL) {
archive_set_error(&a->archive, ENOMEM,
free(zip->uncompressed_buffer);
zip->uncompressed_buffer_size = 256 * 1024;
- zip->uncompressed_buffer =
- (uint8_t*) malloc(zip->uncompressed_buffer_size);
+ zip->uncompressed_buffer = malloc(zip->uncompressed_buffer_size);
if(zip->uncompressed_buffer == NULL) {
archive_set_error(&a->archive, ENOMEM,
free(zip->uncompressed_buffer);
zip->uncompressed_buffer_size = 256 * 1024;
- zip->uncompressed_buffer =
- (uint8_t*) malloc(zip->uncompressed_buffer_size);
+ zip->uncompressed_buffer = malloc(zip->uncompressed_buffer_size);
if (zip->uncompressed_buffer == NULL) {
archive_set_error(&a->archive, ENOMEM,
"No memory for bzip2 decompression");
free(zip->uncompressed_buffer);
zip->uncompressed_buffer_size = ZSTD_DStreamOutSize();
- zip->uncompressed_buffer =
- (uint8_t*) malloc(zip->uncompressed_buffer_size);
+ zip->uncompressed_buffer = malloc(zip->uncompressed_buffer_size);
if (zip->uncompressed_buffer == NULL) {
archive_set_error(&a->archive, ENOMEM,
"No memory for Zstd decompression");
if (zip->uncompressed_buffer == NULL) {
zip->uncompressed_buffer_size = 256 * 1024;
zip->uncompressed_buffer
- = (unsigned char *)malloc(zip->uncompressed_buffer_size);
+ = malloc(zip->uncompressed_buffer_size);
if (zip->uncompressed_buffer == NULL) {
archive_set_error(&a->archive, ENOMEM,
"No memory for ZIP decompression");
archive_check_magic(_a, ARCHIVE_READ_MAGIC,
ARCHIVE_STATE_NEW, "archive_read_support_format_zip");
- zip = (struct zip *)calloc(1, sizeof(*zip));
+ zip = calloc(1, sizeof(*zip));
if (zip == NULL) {
archive_set_error(&a->archive, ENOMEM,
"Can't allocate zip data");
archive_check_magic(_a, ARCHIVE_READ_MAGIC,
ARCHIVE_STATE_NEW, "archive_read_support_format_zip_seekable");
- zip = (struct zip *)calloc(1, sizeof(*zip));
+ zip = calloc(1, sizeof(*zip));
if (zip == NULL) {
archive_set_error(&a->archive, ENOMEM,
"Can't allocate zip data");
if (new_length < s)
new_length = s;
/* Now we can reallocate the buffer. */
- p = (char *)realloc(as->s, new_length);
+ p = realloc(as->s, new_length);
if (p == NULL) {
/* On failure, wipe the string and return NULL. */
archive_string_free(as);
if (strcmp(strings[i], pivot) < 0)
{
lesser_count++;
- tmp = (char **)realloc(lesser,
- lesser_count * sizeof(char *));
+ tmp = realloc(lesser, lesser_count * sizeof(*tmp));
if (!tmp) {
free(greater);
free(lesser);
else
{
greater_count++;
- tmp = (char **)realloc(greater,
- greater_count * sizeof(char *));
+ tmp = realloc(greater, greater_count * sizeof(*tmp));
if (!tmp) {
free(greater);
free(lesser);
struct archive_write *a;
unsigned char *nulls;
- a = (struct archive_write *)calloc(1, sizeof(*a));
+ a = calloc(1, sizeof(*a));
if (a == NULL)
return (NULL);
a->archive.magic = ARCHIVE_WRITE_MAGIC;
/* Initialize a block of nulls for padding purposes. */
a->null_length = 1024;
- nulls = (unsigned char *)calloc(a->null_length, sizeof(unsigned char));
+ nulls = calloc(a->null_length, sizeof(unsigned char));
if (nulls == NULL) {
free(a);
return (NULL);
archive_write_get_bytes_in_last_block(f->archive);
buffer_size = f->bytes_per_block;
- state = (struct archive_none *)calloc(1, sizeof(*state));
- buffer = (char *)malloc(buffer_size);
+ state = calloc(1, sizeof(*state));
+ buffer = malloc(buffer_size);
if (state == NULL || buffer == NULL) {
free(state);
free(buffer);
archive_check_magic(&a->archive, ARCHIVE_WRITE_MAGIC,
ARCHIVE_STATE_NEW, "archive_write_add_filter_b64encode");
- state = (struct private_b64encode *)calloc(1, sizeof(*state));
+ state = calloc(1, sizeof(*state));
if (state == NULL) {
archive_set_error(f->archive, ENOMEM,
"Can't allocate data for b64encode filter");
bs -= bs % bpb;
}
data->compressed_buffer_size = bs;
- data->compressed
- = (char *)malloc(data->compressed_buffer_size);
+ data->compressed = malloc(data->compressed_buffer_size);
if (data->compressed == NULL) {
archive_set_error(f->archive, ENOMEM,
"Can't allocate data for compression buffer");
f->code = ARCHIVE_FILTER_COMPRESS;
f->name = "compress";
- state = (struct private_data *)calloc(1, sizeof(*state));
+ state = calloc(1, sizeof(*state));
if (state == NULL) {
archive_set_error(f->archive, ENOMEM,
"Can't allocate data for compression");
bs -= bs % bpb;
}
data->compressed_buffer_size = bs;
- data->compressed
- = (unsigned char *)malloc(data->compressed_buffer_size);
+ data->compressed = malloc(data->compressed_buffer_size);
if (data->compressed == NULL) {
archive_set_error(f->archive, ENOMEM,
"Can't allocate data for compression buffer");
archive_check_magic(&a->archive, ARCHIVE_WRITE_MAGIC,
ARCHIVE_STATE_NEW, "archive_write_add_filter_uu");
- state = (struct private_uuencode *)calloc(1, sizeof(*state));
+ state = calloc(1, sizeof(*state));
if (state == NULL) {
archive_set_error(f->archive, ENOMEM,
"Can't allocate data for uuencode filter");
bs -= bs % bpb;
}
data->compressed_buffer_size = bs;
- data->compressed
- = (unsigned char *)malloc(data->compressed_buffer_size);
+ data->compressed = malloc(data->compressed_buffer_size);
if (data->compressed == NULL) {
archive_set_error(f->archive, ENOMEM,
"Can't allocate data for compression buffer");
}
data->out.size = bs;
data->out.pos = 0;
- data->out.dst
- = (unsigned char *)malloc(data->out.size);
+ data->out.dst = malloc(data->out.size);
if (data->out.dst == NULL) {
archive_set_error(f->archive, ENOMEM,
"Can't allocate data for compression buffer");
{
struct archive_write_disk *a;
- a = (struct archive_write_disk *)calloc(1, sizeof(*a));
+ a = calloc(1, sizeof(*a));
if (a == NULL)
return (NULL);
a->archive.magic = ARCHIVE_WRITE_DISK_MAGIC;
{
struct fixup_entry *fe;
- fe = (struct fixup_entry *)calloc(1, sizeof(struct fixup_entry));
+ fe = calloc(1, sizeof(struct fixup_entry));
if (fe == NULL) {
archive_set_error(&a->archive, ENOMEM,
"Can't allocate memory for a fixup");
{
struct archive_write_disk *a;
- a = (struct archive_write_disk *)calloc(1, sizeof(*a));
+ a = calloc(1, sizeof(*a));
if (a == NULL)
return (NULL);
a->archive.magic = ARCHIVE_WRITE_DISK_MAGIC;
{
struct fixup_entry *fe;
- fe = (struct fixup_entry *)calloc(1, sizeof(struct fixup_entry));
+ fe = calloc(1, sizeof(struct fixup_entry));
if (fe == NULL)
return (NULL);
fe->next = a->fixup_list;
{
struct write_fd_data *mine;
- mine = (struct write_fd_data *)malloc(sizeof(*mine));
+ mine = malloc(sizeof(*mine));
if (mine == NULL) {
archive_set_error(a, ENOMEM, "No memory");
return (ARCHIVE_FATAL);
{
struct write_FILE_data *mine;
- mine = (struct write_FILE_data *)malloc(sizeof(*mine));
+ mine = malloc(sizeof(*mine));
if (mine == NULL) {
archive_set_error(a, ENOMEM, "No memory");
return (ARCHIVE_FATAL);
struct write_file_data *mine;
int r;
- mine = (struct write_file_data *)calloc(1, sizeof(*mine));
+ mine = calloc(1, sizeof(*mine));
if (mine == NULL) {
archive_set_error(a, ENOMEM, "No memory");
return (ARCHIVE_FATAL);
{
struct write_memory_data *mine;
- mine = (struct write_memory_data *)calloc(1, sizeof(*mine));
+ mine = calloc(1, sizeof(*mine));
if (mine == NULL) {
archive_set_error(a, ENOMEM, "No memory");
return (ARCHIVE_FATAL);
if (a->format_free != NULL)
(a->format_free)(a);
- ar = (struct ar_w *)calloc(1, sizeof(*ar));
+ ar = calloc(1, sizeof(*ar));
if (ar == NULL) {
archive_set_error(&a->archive, ENOMEM, "Can't allocate ar data");
return (ARCHIVE_FATAL);
return (ARCHIVE_WARN);
}
- se = (char *)malloc(strlen(filename) + 3);
+ se = malloc(strlen(filename) + 3);
if (se == NULL) {
archive_set_error(&a->archive, ENOMEM,
"Can't allocate filename buffer");
return (ARCHIVE_WARN);
}
- ar->strtab = (char *)malloc(s + 1);
+ ar->strtab = malloc(s + 1);
if (ar->strtab == NULL) {
archive_set_error(&a->archive, ENOMEM,
"Can't allocate strtab buffer");
if (a->format_free != NULL)
(a->format_free)(a);
- cpio = (struct cpio *)calloc(1, sizeof(*cpio));
+ cpio = calloc(1, sizeof(*cpio));
if (cpio == NULL) {
archive_set_error(&a->archive, ENOMEM, "Can't allocate cpio data");
return (ARCHIVE_FATAL);
if (a->format_free != NULL)
(a->format_free)(a);
- cpio = (struct cpio *)calloc(1, sizeof(*cpio));
+ cpio = calloc(1, sizeof(*cpio));
if (cpio == NULL) {
archive_set_error(&a->archive, ENOMEM, "Can't allocate cpio data");
return (ARCHIVE_FATAL);
if (a->format_free != NULL)
(a->format_free)(a);
- cpio = (struct cpio *)calloc(1, sizeof(*cpio));
+ cpio = calloc(1, sizeof(*cpio));
if (cpio == NULL) {
archive_set_error(&a->archive, ENOMEM, "Can't allocate cpio data");
return (ARCHIVE_FATAL);
struct archive_write *a = (struct archive_write *)_a;
struct gnutar *gnutar;
- gnutar = (struct gnutar *)calloc(1, sizeof(*gnutar));
+ gnutar = calloc(1, sizeof(*gnutar));
if (gnutar == NULL) {
archive_set_error(&a->archive, ENOMEM,
"Can't allocate gnutar data");
if (a->format_free != NULL)
(a->format_free)(a);
- pax = (struct pax *)calloc(1, sizeof(*pax));
+ pax = calloc(1, sizeof(*pax));
if (pax == NULL) {
archive_set_error(&a->archive, ENOMEM,
"Can't allocate pax data");
}
}
- out = (char *)malloc(out_len + 1);
+ out = malloc(out_len + 1);
if (out == NULL)
return (NULL);
char *d, *out;
/* 3 bytes becomes 4 chars, but round up and allow for trailing NUL */
- out = (char *)malloc((len * 4 + 2) / 3 + 1);
+ out = malloc((len * 4 + 2) / 3 + 1);
if (out == NULL)
return (NULL);
d = out;
{
struct sparse_block *sb;
- sb = (struct sparse_block *)malloc(sizeof(*sb));
+ sb = malloc(sizeof(*sb));
if (sb == NULL)
return (ARCHIVE_FATAL);
sb->next = NULL;
if (a->format_free != NULL)
(a->format_free)(a);
- raw = (struct raw *)calloc(1, sizeof(*raw));
+ raw = calloc(1, sizeof(*raw));
if (raw == NULL) {
archive_set_error(&a->archive, ENOMEM, "Can't allocate raw data");
return (ARCHIVE_FATAL);
if (a->format_free != NULL)
(a->format_free)(a);
- shar = (struct shar *)calloc(1, sizeof(*shar));
+ shar = calloc(1, sizeof(*shar));
if (shar == NULL) {
archive_set_error(&a->archive, ENOMEM, "Can't allocate shar data");
return (ARCHIVE_FATAL);
return (ARCHIVE_FATAL);
}
- ustar = (struct ustar *)calloc(1, sizeof(*ustar));
+ ustar = calloc(1, sizeof(*ustar));
if (ustar == NULL) {
archive_set_error(&a->archive, ENOMEM,
"Can't allocate ustar data");
return (ARCHIVE_FATAL);
}
- v7tar = (struct v7tar *)calloc(1, sizeof(*v7tar));
+ v7tar = calloc(1, sizeof(*v7tar));
if (v7tar == NULL) {
archive_set_error(&a->archive, ENOMEM,
"Can't allocate v7tar data");
if (a->format_free != NULL)
(a->format_free)(a);
- zip = (struct zip *) calloc(1, sizeof(*zip));
+ zip = calloc(1, sizeof(*zip));
if (zip == NULL) {
archive_set_error(&a->archive, ENOMEM,
"Can't allocate zip data");
mydata->fd = open(mydata->filename, O_RDONLY | O_BINARY);
if (mydata->fd >= 0)
{
- if ((mydata->buffer = (void*)calloc(BLOCK_SIZE, 1)) == NULL)
+ if ((mydata->buffer = calloc(BLOCK_SIZE, 1)) == NULL)
return (ARCHIVE_FAILED);
}
}
for (i = 0; filename != NULL;)
{
- assert((mydata = (struct mydata *)calloc(1, sizeof(*mydata))) != NULL);
+ assert((mydata = calloc(1, sizeof(*mydata))) != NULL);
if (mydata == NULL) {
assertEqualInt(ARCHIVE_OK, archive_read_free(a));
return;
}
- assert((mydata->filename =
- (char *)calloc(strlen(filename) + 1, sizeof(char))) != NULL);
- if (mydata->filename == NULL) {
- free(mydata);
- assertEqualInt(ARCHIVE_OK, archive_read_free(a));
- return;
- }
- strcpy(mydata->filename, filename);
+ assert((mydata->filename = strdup(filename)) != NULL);
mydata->fd = -1;
filename = reffiles[++i];
assertA(0 == archive_read_append_callback_data(a, mydata));
}
- assertA(0 == archive_read_set_open_callback(a, file_open));
- assertA(0 == archive_read_set_read_callback(a, file_read));
- assertA(0 == archive_read_set_skip_callback(a, file_skip));
- assertA(0 == archive_read_set_close_callback(a, file_close));
- assertA(0 == archive_read_set_switch_callback(a, file_switch));
+ assertA(0 == archive_read_set_open_callback(a, file_open));
+ assertA(0 == archive_read_set_read_callback(a, file_read));
+ assertA(0 == archive_read_set_skip_callback(a, file_skip));
+ assertA(0 == archive_read_set_close_callback(a, file_close));
+ assertA(0 == archive_read_set_switch_callback(a, file_switch));
assertA(0 == archive_read_set_seek_callback(a, file_seek));
assertA(0 == archive_read_open1(a));
srand((unsigned int)time(NULL));
size = sizeof(strings) / sizeof(char *);
- assert((test_strings = (char **)calloc(size, sizeof(char *))) != NULL);
+ assert((test_strings = calloc(size, sizeof(char *))) != NULL);
for (i = 0; i < (size - 1); i++)
assert((test_strings[i] = strdup(strings[i])) != NULL);
char *buff;
int r;
- assert((buff = calloc(buffsize, sizeof(char))) != NULL);
+ assert((buff = calloc(buffsize, sizeof(*buff))) != NULL);
if (buff == NULL)
return;
archive_write_set_format_xar(a);
archive_write_add_filter_none(a);
size_t used, buffsize = 1500;
- char *buff = (char*) malloc(buffsize);
+ char *buff = malloc(buffsize);
archive_write_open_memory(a, buff, buffsize, &used);
struct archive_entry *ae = archive_entry_new();
assertA(0 == archive_read_next_header(a, &entry));
buf_size = (size_t) archive_entry_size(entry);
assertA(buf_size == 12);
- buf = (unsigned char*) malloc(buf_size);
+ buf = malloc(buf_size);
assertA(NULL != buf);
assertA(buf_size == (size_t) archive_read_data(a, buf, buf_size));
free(buf);
assertA(0 == archive_read_next_header(a, &entry));
buf_size = (size_t) archive_entry_size(entry);
assertA(buf_size == 12);
- buf = (unsigned char*) malloc(buf_size);
+ buf = malloc(buf_size);
assertA(NULL != buf);
assertA(buf_size == (size_t) archive_read_data(a, buf, buf_size));
free(buf);
/* Save contents of inner Zip. */
innerLength = (size_t)archive_entry_size(ae);
- inner = calloc(innerLength, sizeof(char));
+ inner = calloc(innerLength, sizeof(*inner));
assertEqualInt(innerLength, archive_read_data(a, inner, innerLength));
assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae));
int i, r, use_prog;
buffsize = 2000000;
- assert(NULL != (buff = (char *)malloc(buffsize)));
+ assert(NULL != (buff = malloc(buffsize)));
if (buff == NULL)
return;
datasize = 10000;
- assert(NULL != (data = (char *)malloc(datasize)));
+ assert(NULL != (data = malloc(datasize)));
if (data == NULL) {
free(buff);
return;
} else {
/* Yes, we're assuming the very first write is metadata. */
/* It's header or metadata, copy and save it. */
- block = (struct memblock *)malloc(sizeof(*block));
+ block = malloc(sizeof(*block));
memset(block, 0, sizeof(*block));
block->size = size;
block->buff = malloc(size);
int i;
buffsize = 2000000;
- assert(NULL != (buff = (char *)malloc(buffsize)));
+ assert(NULL != (buff = malloc(buffsize)));
datasize = 10000;
- assert(NULL != (data = (char *)malloc(datasize)));
+ assert(NULL != (data = malloc(datasize)));
memset(data, 0, datasize);
/*
int i, r, use_prog;
buffsize = 2000000;
- assert(NULL != (buff = (char *)malloc(buffsize)));
+ assert(NULL != (buff = malloc(buffsize)));
if (buff == NULL)
return;
datasize = 10000;
- assert(NULL != (data = (char *)malloc(datasize)));
+ assert(NULL != (data = malloc(datasize)));
if (data == NULL) {
free(buff);
return;
int i;
buffsize = 1000000;
- assert(NULL != (buff = (char *)malloc(buffsize)));
+ assert(NULL != (buff = malloc(buffsize)));
datasize = 10000;
- assert(NULL != (data = (char *)malloc(datasize)));
+ assert(NULL != (data = malloc(datasize)));
memset(data, 0, datasize);
assert((a = archive_write_new()) != NULL);
int i, r, use_prog = 0;
buffsize = 2000000;
- assert(NULL != (buff = (char *)malloc(buffsize)));
+ assert(NULL != (buff = malloc(buffsize)));
if (buff == NULL)
return;
datasize = 10000;
- assert(NULL != (data = (char *)malloc(datasize)));
+ assert(NULL != (data = malloc(datasize)));
if (data == NULL) {
free(buff);
return;
int r, use_prog = 0;
buffsize = 10000;
- assert(NULL != (buff = (char *)malloc(buffsize)));
+ assert(NULL != (buff = malloc(buffsize)));
if (buff == NULL)
return;
datasize = 10000;
- assert(NULL != (data = (char *)malloc(datasize)));
+ assert(NULL != (data = malloc(datasize)));
if (data == NULL) {
free(buff);
return;
}
buffsize = 2000000;
- assert(NULL != (buff = (char *)malloc(buffsize)));
+ assert(NULL != (buff = malloc(buffsize)));
datasize = 10000;
- assert(NULL != (data = (char *)malloc(datasize)));
+ assert(NULL != (data = malloc(datasize)));
memset(data, 0, datasize);
/*
assertEqualInt(ARCHIVE_OK, archive_write_free(a));
buffsize = 2000000;
- assert(NULL != (buff = (char *)malloc(buffsize)));
+ assert(NULL != (buff = malloc(buffsize)));
datasize = 10000;
- assert(NULL != (data = (char *)calloc(datasize, 1)));
+ assert(NULL != (data = calloc(datasize, 1)));
filecount = 10;
/*
assertEqualInt(ARCHIVE_OK, archive_write_free(a));
buffsize = 2000000;
- assert(NULL != (buff = (char *)malloc(buffsize)));
+ assert(NULL != (buff = malloc(buffsize)));
datasize = 10000;
- assert(NULL != (data = (char *)calloc(datasize, 1)));
+ assert(NULL != (data = calloc(datasize, 1)));
filecount = 10;
/*
int i, r;
buffsize = 2000000;
- assert(NULL != (buff = (char *)malloc(buffsize)));
+ assert(NULL != (buff = malloc(buffsize)));
if (buff == NULL)
return;
datasize = 10000;
- assert(NULL != (data = (char *)malloc(datasize)));
+ assert(NULL != (data = malloc(datasize)));
if (data == NULL) {
free(buff);
return;
int i, r;
buffsize = 2000000;
- assert(NULL != (buff = (char *)malloc(buffsize)));
+ assert(NULL != (buff = malloc(buffsize)));
if (buff == NULL)
return;
datasize = 10000;
- assert(NULL != (data = (char *)malloc(datasize)));
+ assert(NULL != (data = malloc(datasize)));
if (data == NULL) {
free(buff);
return;
}
buffsize = 2000000;
- assert(NULL != (buff = (char *)malloc(buffsize)));
+ assert(NULL != (buff = malloc(buffsize)));
datasize = 10000;
- assert(NULL != (data = (char *)calloc(datasize, 1)));
+ assert(NULL != (data = calloc(datasize, 1)));
filecount = 10;
/*
int i;
buffsize = 2000000;
- assert(NULL != (buff = (char *)malloc(buffsize)));
+ assert(NULL != (buff = malloc(buffsize)));
datasize = 10000;
- assert(NULL != (data = (char *)malloc(datasize)));
+ assert(NULL != (data = malloc(datasize)));
memset(data, 0, datasize);
/*
int i, r;
buffsize = 2000000;
- assert(NULL != (buff = (char *)malloc(buffsize)));
+ assert(NULL != (buff = malloc(buffsize)));
if (buff == NULL)
return;
datasize = 10000;
- assert(NULL != (data = (char *)malloc(datasize)));
+ assert(NULL != (data = malloc(datasize)));
if (data == NULL) {
free(buff);
return;
int i, r;
buffsize = 2000000;
- assert(NULL != (buff = (char *)malloc(buffsize)));
+ assert(NULL != (buff = malloc(buffsize)));
if (buff == NULL)
return;
datasize = 10000;
- assert(NULL != (data = (char *)malloc(datasize)));
+ assert(NULL != (data = malloc(datasize)));
if (data == NULL) {
free(buff);
return;
*/
fcnt = create_iso_image(buff, buffsize, &used, NULL);
- fns.names = (char **)malloc(sizeof(char *) * fcnt);
+ fns.names = malloc(sizeof(char *) * fcnt);
assert(fns.names != NULL);
if (fns.names == NULL) {
free(buff);
} else {
/* Yes, we're assuming the very first write is metadata. */
/* It's header or metadata, copy and save it. */
- block = (struct fileblock *)malloc(sizeof(*block));
+ block = malloc(sizeof(*block));
memset(block, 0, sizeof(*block));
block->size = (int)size;
block->buff = malloc(size);
struct filter_set *new_ptr;
char *new_filter;
- new_ptr = (struct filter_set *)realloc(cset->filters,
+ new_ptr = realloc(cset->filters,
sizeof(*cset->filters) * (cset->filter_count + 1));
if (new_ptr == NULL)
lafe_errc(1, 0, "No memory");
#endif
#include <sys/types.h> /* Windows requires this before sys/stat.h */
+#if !HAVE_SUSECONDS_T
+#define suseconds_t long
+#endif
#include <sys/stat.h>
#if HAVE_DIRENT_H
int assertion_set_nodump(const char *, int, const char *);
int assertion_text_file_contents(const char *, int, const char *buff, const char *f);
int assertion_umask(const char *, int, int);
-int assertion_utimes(const char *, int, const char *, long, long, long, long );
+int assertion_utimes(const char *, int, const char *, time_t, suseconds_t, time_t, suseconds_t);
int assertion_version(const char*, int, const char *, const char *);
void skipping_setup(const char *, int);
#include <membership.h>
#endif
+#ifndef nitems
+#define nitems(arr) (sizeof(arr) / sizeof((arr)[0]))
+#endif
+
/*
*
* Windows support routines
if (tlen == 0 || llen == 0)
return (0);
- tgt = malloc((tlen + 1) * sizeof(char));
+ tgt = malloc(tlen + 1);
if (tgt == NULL)
return (0);
- src = malloc((llen + 1) * sizeof(char));
+ src = malloc(llen + 1);
if (src == NULL) {
free(tgt);
return (0);
}
expected_count = i;
if (expected_count) {
- expected = malloc(sizeof(char *) * expected_count);
+ expected = calloc(expected_count, sizeof(*expected));
if (expected == NULL) {
failure_start(pathname, line, "Can't allocate memory");
failure_finish(NULL);
- free(expected);
- free(buff);
- return (0);
+ goto cleanup;
}
for (i = 0; lines[i] != NULL; ++i) {
expected[i] = strdup(lines[i]);
+ if (expected[i] == NULL) {
+ failure_start(pathname, line, "Can't allocate memory");
+ failure_finish(NULL);
+ goto cleanup;
+ }
}
}
if (actual == NULL) {
failure_start(pathname, line, "Can't allocate memory");
failure_finish(NULL);
- free(expected);
- free(buff);
- return (0);
+ goto cleanup;
}
for (j = 0, p = buff; p < buff + buff_size;
p += 1 + strlen(p)) {
/* Erase matching lines from both lists */
for (i = 0; i < expected_count; ++i) {
- if (expected[i] == NULL)
- continue;
for (j = 0; j < actual_count; ++j) {
if (actual[j] == NULL)
continue;
++actual_failure;
}
if (expected_failure == 0 && actual_failure == 0) {
- free(buff);
- free(expected);
free(actual);
+ free(expected);
+ free(buff);
return (1);
}
failure_start(file, line, "File doesn't match: %s", pathname);
if (expected[i] != NULL) {
logprintf(" Expected but not present: %s\n", expected[i]);
free(expected[i]);
+ expected[i] = NULL;
}
}
for (j = 0; j < actual_count; ++j) {
logprintf(" Present but not expected: %s\n", actual[j]);
}
failure_finish(NULL);
- free(buff);
- free(expected);
+cleanup:
free(actual);
+ if (expected != NULL) {
+ for (i = 0; i < expected_count; ++i)
+ if (expected[i] != NULL)
+ free(expected[i]);
+ free(expected);
+ }
+ free(buff);
return (0);
}
FILE_FLAG_OPEN_REPARSE_POINT;
/* Replace slashes with backslashes in pathname */
- pn = malloc((strlen(pathname) + 1) * sizeof(char));
- p = pathname;
- s = pn;
- while(*p != '\0') {
- if(*p == '/')
+ pn = malloc(strlen(pathname) + 1);
+ if (pn == NULL) {
+ failure_start(file, line, "Can't allocate memory");
+ failure_finish(NULL);
+ return (0);
+ }
+ for (p = pathname, s = pn; *p != '\0'; p++, s++) {
+ if (*p == '/')
*s = '\\';
else
*s = *p;
- p++;
- s++;
}
*s = '\0';
/* Set times, report failures. */
int
-assertion_utimes(const char *file, int line,
- const char *pathname, long at, long at_nsec, long mt, long mt_nsec)
+assertion_utimes(const char *file, int line, const char *pathname,
+ time_t at, suseconds_t at_nsec, time_t mt, suseconds_t mt_nsec)
{
int r;
acl_permset_t permset;
const uid_t uid = 1;
uuid_t uuid;
- int i;
const acl_perm_t acl_perms[] = {
ACL_READ_DATA,
ACL_WRITE_DATA,
failure("acl_get_permset() error: %s", strerror(errno));
if (assertEqualInt(r, 0) == 0)
goto testacl_free;
- for (i = 0; i < (int)(sizeof(acl_perms) / sizeof(acl_perms[0])); i++) {
+ for (size_t i = 0; i < nitems(acl_perms); i++) {
r = acl_add_perm(permset, acl_perms[i]);
failure("acl_add_perm() error: %s", strerror(errno));
if (assertEqualInt(r, 0) == 0)
static void
usage(const char *program)
{
- static const int limit = sizeof(tests) / sizeof(tests[0]);
+ static const int limit = nitems(tests);
int i;
printf("Usage: %s [options] <test> <test> ...\n", program);
int
main(int argc, char **argv)
{
- static const int limit = sizeof(tests) / sizeof(tests[0]);
- int test_set[sizeof(tests) / sizeof(tests[0])];
+ static const int limit = nitems(tests);
+ int test_set[nitems(tests)];
int i = 0, j = 0, tests_run = 0, tests_failed = 0, option;
size_t testprogdir_len;
+ size_t tmplen;
#ifdef PROGRAM
size_t tmp2_len;
#endif
*/
progname = p = argv[0];
testprogdir_len = strlen(progname) + 1;
- if ((testprogdir = (char *)malloc(testprogdir_len)) == NULL)
+ if ((testprogdir = malloc(testprogdir_len)) == NULL)
{
fprintf(stderr, "ERROR: Out of memory.");
exit(1);
#endif
{
/* Fixup path for relative directories. */
- if ((testprogdir = (char *)realloc(testprogdir,
+ if ((testprogdir = realloc(testprogdir,
strlen(pwd) + 1 + strlen(testprogdir) + 1)) == NULL)
{
fprintf(stderr, "ERROR: Out of memory.");
tmp = getenv("TEMPDIR");
else
tmp = "/tmp";
+ tmplen = strlen(tmp);
+ while (tmplen > 0 && tmp[tmplen - 1] == '/')
+ tmplen--;
/* Allow -d to be controlled through the environment. */
if (getenv(ENVBASE "_DEBUG") != NULL)
if (testprogfile == NULL)
{
tmp2_len = strlen(testprogdir) + 1 + strlen(PROGRAM) + 1;
- if ((tmp2 = (char *)malloc(tmp2_len)) == NULL)
+ if ((tmp2 = malloc(tmp2_len)) == NULL)
{
fprintf(stderr, "ERROR: Out of memory.");
exit(1);
#endif
strftime(tmpdir_timestamp, sizeof(tmpdir_timestamp),
"%Y-%m-%dT%H.%M.%S", tmptr);
- if ((strlen(tmp) + 1 + strlen(progname) + 1 +
- strlen(tmpdir_timestamp) + 1 + 3) >
- (sizeof(tmpdir) / sizeof(char))) {
+ if (tmplen + 1 + strlen(progname) + 1 +
+ strlen(tmpdir_timestamp) + 1 + 3 >=
+ nitems(tmpdir)) {
fprintf(stderr,
"ERROR: Temp directory pathname too long\n");
exit(1);
}
- snprintf(tmpdir, sizeof(tmpdir), "%s/%s.%s-%03d", tmp,
- progname, tmpdir_timestamp, i);
- if (assertMakeDir(tmpdir,0755))
+ snprintf(tmpdir, sizeof(tmpdir), "%.*s/%s.%s-%03d",
+ (int)tmplen, tmp, progname, tmpdir_timestamp, i);
+ if (assertMakeDir(tmpdir, 0755))
break;
if (i >= 999) {
fprintf(stderr,