Fix integer mismatch usages/comparisons.
Use "size_t" instead of "unsigned int" for data structures.
#include "helpers.h"
-#define TEMP_FILENAME_CMP "%s%ssimple_archiver_compressed_%u.tmp"
-#define FILE_COUNTS_OUTPUT_FORMAT_STR_0 "\nFile %%%uu of %%%uu.\n"
-#define FILE_COUNTS_OUTPUT_FORMAT_STR_1 "[%%%uu/%%%uu]\n"
+#define TEMP_FILENAME_CMP "%s%ssimple_archiver_compressed_%lu.tmp"
+#define FILE_COUNTS_OUTPUT_FORMAT_STR_0 "\nFile %%%lulu of %%%lulu.\n"
+#define FILE_COUNTS_OUTPUT_FORMAT_STR_1 "[%%%lulu/%%%lulu]\n"
#if SIMPLE_ARCHIVER_PLATFORM == SIMPLE_ARCHIVER_PLATFORM_COSMOPOLITAN || \
SIMPLE_ARCHIVER_PLATFORM == SIMPLE_ARCHIVER_PLATFORM_MAC || \
SIMPLE_ARCHIVER_PLATFORM == SIMPLE_ARCHIVER_PLATFORM_LINUX
// Use temp file to store compressed data.
char temp_filename[512];
- unsigned int idx = 0;
- unsigned int temp_dir_end = strlen(state->parsed->temp_dir);
+ size_t idx = 0;
+ size_t temp_dir_end = strlen(state->parsed->temp_dir);
snprintf(temp_filename, 512, TEMP_FILENAME_CMP, state->parsed->temp_dir,
state->parsed->temp_dir[temp_dir_end - 1] == '/' ? "" : "/",
idx);
if (!read_done) {
ret = read(pipe_outof_cmd[0], read_buf, 1024);
if (ret > 0) {
- read_count = fwrite(read_buf, 1, ret, tmp_fd);
+ read_count = fwrite(read_buf, 1, (size_t)ret, tmp_fd);
if (read_count != (size_t)ret) {
// Write to tmp_fd error.
fprintf(stderr,
uint16_t u16;
uint64_t u64;
- u16 = strlen(file_info->filename);
+ size_t temp_size = strlen(file_info->filename);
+ if (temp_size > 0xFFFF) {
+ fprintf(stderr, "ERROR: Filename size is too large to store!\n");
+ return 1;
+ }
+ u16 = (uint16_t)temp_size;
// Write filename length.
simple_archiver_helper_16_bit_be(&u16);
temp_to_write = malloc(sizeof(SDArchiverInternalToWrite));
temp_to_write->buf = malloc(4);
temp_to_write->size = 4;
- for (unsigned int idx = 0; idx < temp_to_write->size; ++idx) {
+ for (size_t idx = 0; idx < temp_to_write->size; ++idx) {
((unsigned char *)temp_to_write->buf)[idx] = 0;
}
}
// Write file length.
- u64 = end;
+ u64 = (uint64_t)end;
simple_archiver_helper_64_bit_be(&u64);
temp_to_write = malloc(sizeof(SDArchiverInternalToWrite));
temp_to_write->buf = malloc(8);
uint16_t u16;
uint64_t u64;
- u16 = strlen(file_info->filename);
+ size_t temp_size = strlen(file_info->filename);
+ if (temp_size > 0xFFFF) {
+ fprintf(stderr, "ERROR: Filename is too large to store!\n");
+ return 1;
+ }
+ u16 = (uint16_t)temp_size;
// Write filename length.
simple_archiver_helper_16_bit_be(&u16);
temp_to_write = malloc(sizeof(SDArchiverInternalToWrite));
temp_to_write->buf = malloc(4);
temp_to_write->size = 4;
- for (unsigned int idx = 0; idx < temp_to_write->size; ++idx) {
+ for (size_t idx = 0; idx < temp_to_write->size; ++idx) {
((unsigned char *)temp_to_write->buf)[idx] = 0;
}
// Error.
return 1;
}
- u64 = end;
+ u64 = (uint64_t)end;
simple_archiver_helper_64_bit_be(&u64);
temp_to_write = malloc(sizeof(SDArchiverInternalToWrite));
temp_to_write->buf = malloc(8);
// A symblic link.
uint16_t u16;
- u16 = strlen(file_info->filename);
+ size_t temp_size = strlen(file_info->filename);
+ if (temp_size > 0xFFFF) {
+ fprintf(stderr, "ERROR: Filename is too large to store!\n");
+ return 1;
+ }
+ u16 = (uint16_t)temp_size;
// Write filename length.
simple_archiver_helper_16_bit_be(&u16);
temp_to_write = malloc(sizeof(SDArchiverInternalToWrite));
temp_to_write->buf = malloc(4);
temp_to_write->size = 4;
- for (unsigned int idx = 0; idx < temp_to_write->size; ++idx) {
+ for (size_t idx = 0; idx < temp_to_write->size; ++idx) {
((unsigned char *)temp_to_write->buf)[idx] = 0;
}
// Compare paths to get relative path.
// Get first non-common char.
- unsigned int idx;
- unsigned int last_slash;
+ size_t idx;
+ size_t last_slash;
for (idx = 0, last_slash = 0;
idx < strlen(abs_path) && idx < strlen(link_abs_path); ++idx) {
if (((const char *)abs_path)[idx] !=
simple_archiver_list_add(to_write, temp_to_write, free_internal_to_write);
} else if ((state->parsed->flags & 0x20) == 0) {
// Write absolute path length.
- u16 = strlen(abs_path);
+ size_t temp_size = strlen(abs_path);
+ if (temp_size > 0xFFFF) {
+ fprintf(stderr, "ERROR: Absolute path name is too large!\n");
+ return 1;
+ }
+ u16 = (uint16_t)temp_size;
simple_archiver_helper_16_bit_be(&u16);
temp_to_write = malloc(sizeof(SDArchiverInternalToWrite));
if (rel_path) {
// Write relative path length.
- u16 = strlen(rel_path);
+ size_t temp_size = strlen(rel_path);
+ if (temp_size > 0xFFFF) {
+ fprintf(stderr, "ERROR: Relative path name is too large!\n");
+ return 1;
+ }
+ u16 = (uint16_t)temp_size;
simple_archiver_helper_16_bit_be(&u16);
temp_to_write = malloc(sizeof(SDArchiverInternalToWrite));
temp_to_write->buf = malloc(2);
return SDAS_FAILED_TO_WRITE;
}
c = 0;
- for (unsigned int i = 0; i < 3; ++i) {
+ for (size_t i = 0; i < 3; ++i) {
if (fwrite(&c, 1, 1, out_f) != 1) {
return SDAS_FAILED_TO_WRITE;
}
}
// De/compressor bytes.
- u16 = strlen(state->parsed->compressor);
+ size_t temp_size = strlen(state->parsed->compressor);
+ if (temp_size > 0xFFFF) {
+ fprintf(stderr, "ERROR: Compressor cmd string is too large!\n");
+ return SDAS_NO_COMPRESSOR;
+ }
+ u16 = (uint16_t)temp_size;
// To big-endian.
simple_archiver_helper_16_bit_be(&u16);
// Write the size in big-endian.
return SDAS_FAILED_TO_WRITE;
}
- u16 = strlen(state->parsed->decompressor);
+ temp_size = strlen(state->parsed->decompressor);
+ if (temp_size > 0xFFFF) {
+ fprintf(stderr, "ERROR: Decompressor cmd string is too large!\n");
+ return SDAS_NO_DECOMPRESSOR;
+ }
+ u16 = (uint16_t)temp_size;
// To big-endian.
simple_archiver_helper_16_bit_be(&u16);
// Write the size in big-endian.
} else {
// Write the four flag bytes with first bit NOT set.
unsigned char c = 0;
- for (unsigned int i = 0; i < 4; ++i) {
+ for (size_t i = 0; i < 4; ++i) {
if (fwrite(&c, 1, 1, out_f) != 1) {
return SDAS_FAILED_TO_WRITE;
}
// Write file count.
{
- uint32_t u32 = filenames->count;
+ if (filenames->count > 0xFFFFFFFF) {
+ fprintf(stderr, "ERROR: Filenames count is too large!\n");
+ return SDAS_INTERNAL_ERROR;
+ }
+ uint32_t u32 = (uint32_t)filenames->count;
simple_archiver_helper_32_bit_be(&u32);
if (fwrite(&u32, 1, 4, out_f) != 4) {
return SDAS_FAILED_TO_WRITE;
fprintf(stderr, "File count is %u\n", u32);
const uint32_t size = u32;
- const unsigned int digits = simple_archiver_helper_num_digits(size);
+ const size_t digits = simple_archiver_helper_num_digits(size);
char format_str[128];
snprintf(format_str, 128, FILE_COUNTS_OUTPUT_FORMAT_STR_0, digits, digits);
int skip = 0;
state->parsed->working_files[0] != NULL) {
hash_map = simple_archiver_hash_map_init();
for (char **iter = state->parsed->working_files; *iter != NULL; ++iter) {
- int len = strlen(*iter) + 1;
+ size_t len = strlen(*iter) + 1;
char *key = malloc(len);
memcpy(key, *iter, len);
key[len - 1] = 0;
return SDAS_INVALID_FILE;
}
- unsigned int permissions = 0;
+ mode_t permissions = 0;
#if SIMPLE_ARCHIVER_PLATFORM == SIMPLE_ARCHIVER_PLATFORM_COSMOPOLITAN || \
SIMPLE_ARCHIVER_PLATFORM == SIMPLE_ARCHIVER_PLATFORM_MAC || \
SIMPLE_ARCHIVER_PLATFORM == SIMPLE_ARCHIVER_PLATFORM_LINUX
int write_again = 0;
int write_pipe_done = 0;
int read_pipe_done = 0;
- ssize_t fread_ret;
+ size_t fread_ret;
char recv_buf[1024];
size_t amount_to_read;
while (!write_pipe_done || !read_pipe_done) {
// Send over pipe to decompressor.
if (fread_ret > 0) {
ssize_t write_ret = write(pipe_into_cmd[1], buf, fread_ret);
- if (write_ret == fread_ret) {
+ if (write_ret > 0 && (size_t)write_ret == fread_ret) {
// Successful write.
write_again = 0;
if (compressed_file_size == 0) {
if (!read_pipe_done) {
ssize_t read_ret = read(pipe_outof_cmd[0], recv_buf, 1024);
if (read_ret > 0) {
- size_t fwrite_ret = fwrite(recv_buf, 1, read_ret, out_f);
+ size_t fwrite_ret =
+ fwrite(recv_buf, 1, (size_t)read_ret, out_f);
if (fwrite_ret == (size_t)read_ret) {
// Success.
} else if (ferror(out_f)) {
waitpid(decompressor_pid, NULL, 0);
} else {
uint64_t compressed_file_size = u64;
- ssize_t fread_ret;
+ size_t fread_ret;
while (compressed_file_size != 0) {
if (compressed_file_size > 1024) {
fread_ret = fread(buf, 1, 1024, in_f);
} else {
while (u64 != 0) {
if (u64 > 1024) {
- ssize_t read_ret = fread(buf, 1, 1024, in_f);
+ size_t read_ret = fread(buf, 1, 1024, in_f);
if (read_ret > 0) {
u64 -= read_ret;
} else if (ferror(in_f)) {
return SDAS_INTERNAL_ERROR;
}
} else {
- ssize_t read_ret = fread(buf, 1, u64, in_f);
+ size_t read_ret = fread(buf, 1, u64, in_f);
if (read_ret > 0) {
u64 -= read_ret;
} else if (ferror(in_f)) {
const SDArchiverParsed *parsed;
FILE *out_f;
SDArchiverHashMap *map;
- unsigned int count;
- unsigned int max;
- unsigned int digits;
+ size_t count;
+ size_t max;
+ size_t digits;
} SDArchiverState;
enum SDArchiverStateReturns {
typedef struct SDArchiverHashMapData {
void *value;
void *key;
- unsigned int key_size;
+ size_t key_size;
void (*value_cleanup_fn)(void *);
void (*key_cleanup_fn)(void *);
} SDArchiverHashMapData;
typedef struct SDArchiverHashMapKeyData {
void *key;
- unsigned int key_size;
+ size_t key_size;
} SDArchiverHashMapKeyData;
typedef struct SDArchiverInternalIterContext {
- int (*iter_check_fn)(const void *, unsigned int, const void *, void *);
+ int (*iter_check_fn)(const void *, size_t, const void *, void *);
int ret;
void *user_data;
} SDArchiverInternalIterContext;
}
unsigned long long simple_archiver_hash_map_internal_key_to_hash(
- const void *key, unsigned int key_size) {
+ const void *key, size_t key_size) {
unsigned long long seed = 0;
unsigned long long temp = 0;
- unsigned int count = 0;
- for (unsigned int idx = 0; idx < key_size; ++idx) {
+ size_t count = 0;
+ for (size_t idx = 0; idx < key_size; ++idx) {
temp |= ((unsigned long long)*((unsigned char *)key + idx)) << (8 * count);
++count;
if (count >= 8) {
// Pointers have the same size (at least on the same machine), so
// sizeof(void*) should be ok.
new_hash_map->buckets = malloc(sizeof(void *) * new_hash_map->buckets_size);
- for (unsigned int idx = 0; idx < new_hash_map->buckets_size; ++idx) {
+ for (size_t idx = 0; idx < new_hash_map->buckets_size; ++idx) {
new_hash_map->buckets[idx] = simple_archiver_list_init();
}
new_hash_map->count = 0;
// Iterate through the old hash map to populate the new hash map.
- for (unsigned int bucket_idx = 0; bucket_idx < (*hash_map)->buckets_size;
+ for (size_t bucket_idx = 0; bucket_idx < (*hash_map)->buckets_size;
++bucket_idx) {
SDArchiverLLNode *node = (*hash_map)->buckets[bucket_idx]->head;
while (node) {
// Pointers have the same size (at least on the same machine), so
// sizeof(void*) should be ok.
hash_map->buckets = malloc(sizeof(void *) * hash_map->buckets_size);
- for (unsigned int idx = 0; idx < hash_map->buckets_size; ++idx) {
+ for (size_t idx = 0; idx < hash_map->buckets_size; ++idx) {
hash_map->buckets[idx] = simple_archiver_list_init();
}
hash_map->count = 0;
void simple_archiver_hash_map_free(SDArchiverHashMap **hash_map) {
if (hash_map && *hash_map) {
- for (unsigned int idx = 0; idx < (*hash_map)->buckets_size; ++idx) {
+ for (size_t idx = 0; idx < (*hash_map)->buckets_size; ++idx) {
SDArchiverLinkedList **linked_list = (*hash_map)->buckets + idx;
simple_archiver_list_free(linked_list);
}
}
int simple_archiver_hash_map_insert(SDArchiverHashMap **hash_map, void *value,
- void *key, unsigned int key_size,
+ void *key, size_t key_size,
void (*value_cleanup_fn)(void *),
void (*key_cleanup_fn)(void *)) {
if ((*hash_map)->buckets_size <= (*hash_map)->count) {
}
void *simple_archiver_hash_map_get(const SDArchiverHashMap *hash_map,
- const void *key, unsigned int key_size) {
+ const void *key, size_t key_size) {
unsigned long long hash =
simple_archiver_hash_map_internal_key_to_hash(key, key_size) %
hash_map->buckets_size;
}
int simple_archiver_hash_map_remove(SDArchiverHashMap *hash_map, void *key,
- unsigned int key_size) {
+ size_t key_size) {
unsigned long long hash =
simple_archiver_hash_map_internal_key_to_hash(key, key_size) %
hash_map->buckets_size;
}
int simple_archiver_hash_map_iter(const SDArchiverHashMap *hash_map,
- int (*iter_check_fn)(const void *,
- unsigned int,
+ int (*iter_check_fn)(const void *, size_t,
const void *, void *),
void *user_data) {
SDArchiverInternalIterContext ctx;
ctx.iter_check_fn = iter_check_fn;
ctx.ret = 0;
ctx.user_data = user_data;
- for (unsigned int idx = 0; idx < hash_map->buckets_size; ++idx) {
+ for (size_t idx = 0; idx < hash_map->buckets_size; ++idx) {
if (simple_archiver_list_get(
hash_map->buckets[idx],
simple_archiver_internal_hash_map_bucket_iter_fn, &ctx) != 0) {
#define SC_SA_DS_HASH_MAP_START_BUCKET_SIZE 32
+#include <stddef.h>
+
#include "linked_list.h"
typedef struct SDArchiverHashMap {
SDArchiverLinkedList **buckets;
- unsigned int buckets_size;
- unsigned int count;
+ size_t buckets_size;
+ size_t count;
} SDArchiverHashMap;
SDArchiverHashMap *simple_archiver_hash_map_init(void);
/// NOTICE: You must not pass NULL to value, otherwise all "get" checks will
/// fail for the inserted key.
int simple_archiver_hash_map_insert(SDArchiverHashMap **hash_map, void *value,
- void *key, unsigned int key_size,
+ void *key, size_t key_size,
void (*value_cleanup_fn)(void *),
void (*key_cleanup_fn)(void *));
/// Returns NULL if not found.
void *simple_archiver_hash_map_get(const SDArchiverHashMap *hash_map,
- const void *key, unsigned int key_size);
+ const void *key, size_t key_size);
/// Returns zero on success. Returns one if more than one entry was removed.
/// Otherwise returns non-zero and non-one value on error.
int simple_archiver_hash_map_remove(SDArchiverHashMap *hash_map, void *key,
- unsigned int key_size);
+ size_t key_size);
/// Iterates through the hash map with the "iter_check_fn", which is passed the
/// key, key-size, value, and user_data. This function will call "iter_check_fn"
/// "iter_check_fn" returns zero for every call, then this function will return
/// zero after having iterated through every key-value pair.
int simple_archiver_hash_map_iter(const SDArchiverHashMap *hash_map,
- int (*iter_check_fn)(const void *,
- unsigned int,
+ int (*iter_check_fn)(const void *, size_t,
const void *, void *),
void *user_data);
#ifndef SEODISPARATE_COM_SIMPLE_ARCHIVER_DATA_STRUCTURE_LINKED_LIST_H_
#define SEODISPARATE_COM_SIMPLE_ARCHIVER_DATA_STRUCTURE_LINKED_LIST_H_
+#include <stddef.h>
+
typedef struct SDArchiverLLNode {
struct SDArchiverLLNode *next;
struct SDArchiverLLNode *prev;
typedef struct SDArchiverLinkedList {
SDArchiverLLNode *head;
SDArchiverLLNode *tail;
- unsigned int count;
+ size_t count;
} SDArchiverLinkedList;
SDArchiverLinkedList *simple_archiver_list_init(void);
new_priority_heap->nodes =
calloc(new_priority_heap->capacity, sizeof(SDArchiverPHNode));
- for (unsigned int idx = 1; idx < (*priority_heap)->size + 1; ++idx) {
+ for (size_t idx = 1; idx < (*priority_heap)->size + 1; ++idx) {
if ((*priority_heap)->nodes[idx].is_valid != 0) {
simple_archiver_priority_heap_insert(
&new_priority_heap, (*priority_heap)->nodes[idx].priority,
void simple_archiver_priority_heap_free(SDArchiverPHeap **priority_heap) {
if (priority_heap && *priority_heap) {
- for (unsigned int idx = 1; idx < (*priority_heap)->size + 1; ++idx) {
+ for (size_t idx = 1; idx < (*priority_heap)->size + 1; ++idx) {
if ((*priority_heap)->nodes[idx].is_valid != 0) {
if ((*priority_heap)->nodes[idx].data_cleanup_fn) {
(*priority_heap)
simple_archiver_priority_heap_internal_realloc(priority_heap);
}
- unsigned int hole = (*priority_heap)->size + 1;
+ size_t hole = (*priority_heap)->size + 1;
while (hole > 1 &&
(*priority_heap)
SDArchiverPHNode end = priority_heap->nodes[priority_heap->size];
priority_heap->nodes[priority_heap->size].is_valid = 0;
- unsigned int hole = 1;
+ size_t hole = 1;
while (hole * 2 + 1 <= priority_heap->size) {
if (priority_heap->nodes[hole * 2].is_valid != 0 &&
priority_heap->nodes[hole * 2 + 1].is_valid != 0) {
int more_fn(long long a, long long b) { return a > b ? 1 : 0; }
int hash_map_iter_check_fn(__attribute__((unused)) const void *key,
- __attribute__((unused)) unsigned int key_size,
+ __attribute__((unused)) size_t key_size,
const void *value, void *ud) {
char *found_buf = ud;
const size_t real_value = (const size_t)value;
}
int hash_map_iter_check_fn2(__attribute__((unused)) const void *key,
- __attribute__((unused)) unsigned int key_size,
+ __attribute__((unused)) size_t key_size,
__attribute__((unused)) const void *value,
__attribute__((unused)) void *ud) {
return 2;
#if SIMPLE_ARCHIVER_PLATFORM == SIMPLE_ARCHIVER_PLATFORM_LINUX || \
SIMPLE_ARCHIVER_PLATFORM == SIMPLE_ARCHIVER_PLATFORM_MAC || \
SIMPLE_ARCHIVER_PLATFORM == SIMPLE_ARCHIVER_PLATFORM_COSMOPOLITAN
- chdir(*original);
+ __attribute__((unused)) int unused_ret = chdir(*original);
#endif
free(*original);
*original = NULL;
#endif
}
-char *simple_archiver_helper_cut_substr(const char *s, unsigned int start_idx,
- unsigned int end_idx) {
- unsigned int s_len = strlen(s);
+char *simple_archiver_helper_cut_substr(const char *s, size_t start_idx,
+ size_t end_idx) {
+ size_t s_len = strlen(s);
if (start_idx > end_idx || start_idx >= s_len || end_idx > s_len) {
return NULL;
} else if (end_idx == s_len) {
}
}
-unsigned int simple_archiver_helper_num_digits(unsigned int value) {
- unsigned int digits = 0;
+size_t simple_archiver_helper_num_digits(size_t value) {
+ size_t digits = 0;
do {
++digits;
value /= 10;
/// Returns non-NULL on success.
/// Must be free'd with "free()" if non-NULL.
/// start_idx is inclusive and end_idx is exclusive.
-char *simple_archiver_helper_cut_substr(const char *s, unsigned int start_idx,
- unsigned int end_idx);
+char *simple_archiver_helper_cut_substr(const char *s, size_t start_idx,
+ size_t end_idx);
-unsigned int simple_archiver_helper_num_digits(unsigned int value);
+size_t simple_archiver_helper_num_digits(size_t value);
void simple_archiver_helper_cleanup_FILE(FILE **fd);
void simple_archiver_helper_cleanup_malloced(void **data);
#include "parser_internal.h"
/// Gets the first non "./"-like character in the filename.
-unsigned int simple_archiver_parser_internal_get_first_non_current_idx(
+size_t simple_archiver_parser_internal_get_first_non_current_idx(
const char *filename) {
- unsigned int idx = 0;
- unsigned int known_good_idx = 0;
- const unsigned int length = strlen(filename);
+ size_t idx = 0;
+ size_t known_good_idx = 0;
+ const size_t length = strlen(filename);
// 0b0001 - checked that idx char is '.'
// 0b0010 - checked that idx char is '/'
- unsigned int flags = 0;
+ size_t flags = 0;
for (; idx < length; ++idx) {
if ((flags & 3) == 0) {
}
void simple_archiver_parser_internal_remove_end_slash(char *filename) {
- int len = strlen(filename);
- int idx;
+ size_t len = strlen(filename);
+ size_t idx;
for (idx = len; idx-- > 0;) {
if (filename[idx] != '/') {
++idx;
out->filename = NULL;
} else {
out->flags &= 0xFFFFFFEF;
- int size = strlen(argv[1]) + 1;
+ size_t size = strlen(argv[1]) + 1;
out->filename = malloc(size);
strncpy(out->filename, argv[1], size);
}
simple_archiver_print_usage();
return 1;
}
- int size = strlen(argv[1]) + 1;
+ size_t size = strlen(argv[1]) + 1;
out->compressor = malloc(size);
strncpy(out->compressor, argv[1], size);
--argc;
simple_archiver_print_usage();
return 1;
}
- int size = strlen(argv[1]) + 1;
+ size_t size = strlen(argv[1]) + 1;
out->decompressor = malloc(size);
strncpy(out->decompressor, argv[1], size);
--argc;
} else {
if (out->working_files == NULL) {
out->working_files = malloc(sizeof(char *) * 2);
- unsigned int arg_idx =
+ size_t arg_idx =
simple_archiver_parser_internal_get_first_non_current_idx(argv[0]);
- unsigned int arg_length = strlen(argv[0] + arg_idx) + 1;
+ size_t arg_length = strlen(argv[0] + arg_idx) + 1;
out->working_files[0] = malloc(arg_length);
strncpy(out->working_files[0], argv[0] + arg_idx, arg_length);
simple_archiver_parser_internal_remove_end_slash(out->working_files[0]);
out->working_files[1] = NULL;
} else {
- int working_size = 1;
+ size_t working_size = 1;
char **ptr = out->working_files;
while (ptr && *ptr) {
++working_size;
// Set new actual last element to NULL.
out->working_files[working_size] = NULL;
- unsigned int arg_idx =
+ size_t arg_idx =
simple_archiver_parser_internal_get_first_non_current_idx(argv[0]);
- int size = strlen(argv[0] + arg_idx) + 1;
+ size_t size = strlen(argv[0] + arg_idx) + 1;
// Set last element to the arg.
out->working_files[working_size - 1] = malloc(size);
strncpy(out->working_files[working_size - 1], argv[0] + arg_idx, size);
fstatat(AT_FDCWD, file_path, &st, AT_SYMLINK_NOFOLLOW);
if ((st.st_mode & S_IFMT) == S_IFREG || (st.st_mode & S_IFMT) == S_IFLNK) {
// Is a regular file or a symbolic link.
- int len = strlen(file_path) + 1;
+ size_t len = strlen(file_path) + 1;
char *filename = malloc(len);
strncpy(filename, file_path, len);
if (simple_archiver_hash_map_get(hash_map, filename, len - 1) == NULL) {
}
// fprintf(stderr, "dir entry in %s is %s\n", next,
// dir_entry->d_name);
- int combined_size = strlen(next) + strlen(dir_entry->d_name) + 2;
+ size_t combined_size = strlen(next) + strlen(dir_entry->d_name) + 2;
char *combined_path = malloc(combined_size);
snprintf(combined_path, combined_size, "%s/%s", next,
dir_entry->d_name);
- unsigned int valid_idx =
+ size_t valid_idx =
simple_archiver_parser_internal_get_first_non_current_idx(
combined_path);
if (valid_idx > 0) {
SDArchiverFileInfo *file_info = iter->data;
// Remove leading "./" entries from files_list.
- unsigned int idx =
- simple_archiver_parser_internal_get_first_non_current_idx(
- file_info->filename);
+ size_t idx = simple_archiver_parser_internal_get_first_non_current_idx(
+ file_info->filename);
if (idx > 0) {
- int len = strlen(file_info->filename) + 1 - idx;
+ size_t len = strlen(file_info->filename) + 1 - idx;
char *substr = malloc(len);
strncpy(substr, file_info->filename + idx, len);
free(file_info->filename);
#include "parser.h"
-unsigned int simple_archiver_parser_internal_get_first_non_current_idx(
+size_t simple_archiver_parser_internal_get_first_non_current_idx(
const char *filename);
#endif