[refactor] Initialize variables to default values in multiple files

This commit is contained in:
2025-08-01 15:34:36 +01:00
parent 81633e4445
commit 788c7a2bc7
18 changed files with 120 additions and 115 deletions

View File

@@ -28,9 +28,9 @@
int aaruf_close(void *context)
{
int i;
mediaTagEntry *mediaTag;
mediaTagEntry *tmpMediaTag;
int i = 0;
mediaTagEntry *mediaTag = NULL;
mediaTagEntry *tmpMediaTag = NULL;
if(context == NULL)
{

View File

@@ -22,7 +22,6 @@
AARU_EXPORT crc64_ctx *AARU_CALL aaruf_crc64_init(void)
{
int i, slice;
crc64_ctx *ctx = (crc64_ctx *)malloc(sizeof(crc64_ctx));
if(!ctx) return NULL;
@@ -68,7 +67,7 @@ AARU_EXPORT void AARU_CALL aaruf_crc64_slicing(uint64_t *previous_crc, const uin
if(len > 4)
{
const uint8_t *limit;
const uint8_t *limit = NULL;
while((uintptr_t)(data) & 3)
{

View File

@@ -24,15 +24,22 @@
int32_t aaruf_cst_transform(const uint8_t *interleaved, uint8_t *sequential, size_t length)
{
uint8_t *p, *q, *r, *s, *t, *u, *v, *w;
size_t qStart;
size_t rStart;
size_t sStart;
size_t tStart;
size_t uStart;
size_t vStart;
size_t wStart;
size_t i;
uint8_t *p = NULL;
uint8_t *q = NULL;
uint8_t *r = NULL;
uint8_t *s = NULL;
uint8_t *t = NULL;
uint8_t *u = NULL;
uint8_t *v = NULL;
uint8_t *w = NULL;
size_t qStart = 0;
size_t rStart = 0;
size_t sStart = 0;
size_t tStart = 0;
size_t uStart = 0;
size_t vStart = 0;
size_t wStart = 0;
size_t i = 0;
if(interleaved == NULL || sequential == NULL) return AARUF_ERROR_BUFFER_TOO_SMALL;

View File

@@ -26,8 +26,8 @@
void *aaruf_ecc_cd_init()
{
CdEccContext *context;
uint32_t edc, i, j;
CdEccContext *context = NULL;
uint32_t edc = 0, i = 0, j = 0;
context = (CdEccContext *)malloc(sizeof(CdEccContext));

View File

@@ -37,10 +37,10 @@ static void error_callback(const FLAC__StreamDecoder *decoder, FLAC__StreamDecod
AARU_EXPORT size_t AARU_CALL aaruf_flac_decode_redbook_buffer(uint8_t *dst_buffer, size_t dst_size,
const uint8_t *src_buffer, size_t src_size)
{
FLAC__StreamDecoder *decoder;
FLAC__StreamDecoderInitStatus init_status;
FLAC__StreamDecoder *decoder = NULL;
FLAC__StreamDecoderInitStatus init_status = FLAC__STREAM_DECODER_INIT_STATUS_OK;
aaru_flac_ctx *ctx = (aaru_flac_ctx *)malloc(sizeof(aaru_flac_ctx));
size_t ret_size;
size_t ret_size = 0;
memset(ctx, 0, sizeof(aaru_flac_ctx));
@@ -148,12 +148,12 @@ AARU_EXPORT size_t AARU_CALL aaruf_flac_encode_redbook_buffer(
uint32_t min_residual_partition_order, uint32_t max_residual_partition_order, const char *application_id,
uint32_t application_id_len)
{
FLAC__StreamEncoder *encoder;
FLAC__StreamEncoder *encoder = NULL;
aaru_flac_ctx *ctx = (aaru_flac_ctx *)malloc(sizeof(aaru_flac_ctx));
FLAC__StreamEncoderInitStatus init_status;
size_t ret_size;
FLAC__int32 *pcm;
int i;
FLAC__StreamEncoderInitStatus init_status = FLAC__STREAM_ENCODER_INIT_STATUS_OK;
size_t ret_size = 0;
FLAC__int32 *pcm = NULL;
int i = 0;
int16_t *buffer16 = (int16_t *)src_buffer;
FLAC__StreamMetadata *metadata[1];

View File

@@ -30,7 +30,7 @@
*/
int aaruf_identify(const char *filename)
{
FILE *stream;
FILE *stream = NULL;
stream = fopen(filename, "rb");

View File

@@ -30,25 +30,25 @@
void *aaruf_open(const char *filepath)
{
aaruformatContext *ctx;
int errorNo;
size_t readBytes;
long pos;
aaruformatContext *ctx = NULL;
int errorNo = 0;
size_t readBytes = 0;
long pos = 0;
IndexHeader idxHeader;
IndexEntry *idxEntries;
uint8_t *data;
uint8_t *cmpData;
uint8_t *cstData;
uint32_t *cdDdt;
uint64_t crc64;
int i, j, k;
uint16_t e;
IndexEntry *idxEntries = NULL;
uint8_t *data = NULL;
uint8_t *cmpData = NULL;
uint8_t *cstData = NULL;
uint32_t *cdDdt = NULL;
uint64_t crc64 = 0;
int i = 0, j = 0, k = 0;
uint16_t e = 0;
uint8_t lzmaProperties[LZMA_PROPERTIES_LENGTH];
size_t lzmaSize;
size_t lzmaSize = 0;
ChecksumHeader checksum_header;
ChecksumEntry *checksum_entry;
mediaTagEntry *mediaTag;
mediaTagEntry *oldMediaTag;
ChecksumEntry const *checksum_entry = NULL;
mediaTagEntry *mediaTag = NULL;
mediaTagEntry *oldMediaTag = NULL;
ctx = (aaruformatContext *)malloc(sizeof(aaruformatContext));
memset(ctx, 0, sizeof(aaruformatContext));

View File

@@ -55,18 +55,18 @@ int32_t aaruf_read_media_tag(void *context, uint8_t *data, int32_t tag, uint32_t
int32_t aaruf_read_sector(void *context, uint64_t sectorAddress, uint8_t *data, uint32_t *length)
{
aaruformatContext *ctx;
uint64_t ddtEntry;
uint32_t offsetMask;
uint64_t offset;
uint64_t blockOffset;
BlockHeader *blockHeader;
uint8_t *block;
size_t readBytes;
aaruformatContext *ctx = NULL;
uint64_t ddtEntry = 0;
uint32_t offsetMask = 0;
uint64_t offset = 0;
uint64_t blockOffset = 0;
BlockHeader *blockHeader = NULL;
uint8_t *block = NULL;
size_t readBytes = 0;
uint8_t lzmaProperties[LZMA_PROPERTIES_LENGTH];
size_t lzmaSize;
uint8_t *cmpData;
int errorNo;
size_t lzmaSize = 0;
uint8_t *cmpData = NULL;
int errorNo = 0;
if(context == NULL) return AARUF_ERROR_NOT_AARUFORMAT;
@@ -279,14 +279,14 @@ int32_t aaruf_read_track_sector(void *context, uint8_t *data, uint64_t sectorAdd
int32_t aaruf_read_sector_long(void *context, uint64_t sectorAddress, uint8_t *data, uint32_t *length)
{
aaruformatContext *ctx;
uint32_t bareLength;
uint32_t tagLength;
uint8_t *bareData;
int32_t res;
aaruformatContext *ctx = NULL;
uint32_t bareLength = 0;
uint32_t tagLength = 0;
uint8_t *bareData = NULL;
int32_t res = 0;
TrackEntry trk;
int i;
bool trkFound;
int i = 0;
bool trkFound = false;
if(context == NULL) return AARUF_ERROR_NOT_AARUFORMAT;

View File

@@ -126,7 +126,7 @@ int have_avx2()
#if(defined(__aarch64__) || defined(_M_ARM64) || defined(__arm__) || defined(_M_ARM)) && defined(__APPLE__)
int have_neon_apple()
{
int value;
int value = 0;
size_t len = sizeof(int);
int ret = sysctlbyname("hw.optional.neon", &value, &len, NULL, 0);
@@ -137,7 +137,7 @@ int have_neon_apple()
int have_crc32_apple()
{
int value;
int value = 0;
size_t len = sizeof(int);
int ret = sysctlbyname("hw.optional.crc32", &value, &len, NULL, 0);

View File

@@ -50,10 +50,9 @@ AARU_EXPORT spamsum_ctx *AARU_CALL aaruf_spamsum_init(void)
AARU_EXPORT int AARU_CALL aaruf_spamsum_update(spamsum_ctx *ctx, const uint8_t *data, uint32_t len)
{
int i;
if(!ctx || !data) return -1;
for(i = 0; i < len; i++) fuzzy_engine_step(ctx, data[i]);
for (int i = 0; i < len; i++) fuzzy_engine_step(ctx, data[i]);
ctx->total_size += len;
@@ -71,7 +70,7 @@ AARU_EXPORT void AARU_CALL aaruf_spamsum_free(spamsum_ctx *ctx)
AARU_LOCAL inline void fuzzy_engine_step(spamsum_ctx *ctx, uint8_t c)
{
uint32_t i;
uint32_t i = 0;
/* At each character we update the rolling hash and the normal hashes.
* When the rolling hash hits a reset value then we emit a normal hash
* as a element of the signature and reset the normal hash. */

View File

@@ -24,16 +24,16 @@
int32_t aaruf_verify_image(void *context)
{
aaruformatContext *ctx;
uint64_t crc64;
int i;
aaruformatContext *ctx = NULL;
uint64_t crc64 = 0;
int i = 0;
IndexHeader index_header;
IndexEntry *index_entries;
size_t read_bytes;
void *buffer;
crc64_ctx *crc64_context;
IndexEntry *index_entries = NULL;
size_t read_bytes = 0;
void *buffer = NULL;
crc64_ctx *crc64_context = NULL;
BlockHeader block_header;
uint64_t verified_bytes;
uint64_t verified_bytes = 0;
DdtHeader ddt_header;
TracksHeader tracks_header;
@@ -88,7 +88,7 @@ int32_t aaruf_verify_image(void *context)
if(crc64 != index_header.crc64)
{
fprintf(stderr, "Expected index CRC 0x%16llX but got 0x%16lX.\n", index_header.crc64, crc64);
fprintf(stderr, "Expected index CRC 0x%16llX but got 0x%16llX.\n", index_header.crc64, crc64);
free(index_entries);
return AARUF_ERROR_INVALID_BLOCK_CRC;
}
@@ -148,7 +148,7 @@ int32_t aaruf_verify_image(void *context)
if(crc64 != block_header.cmpCrc64)
{
fprintf(stderr, "Expected block CRC 0x%16llX but got 0x%16lX.\n", block_header.cmpCrc64, crc64);
fprintf(stderr, "Expected block CRC 0x%16llX but got 0x%16llX.\n", block_header.cmpCrc64, crc64);
free(index_entries);
return AARUF_ERROR_INVALID_BLOCK_CRC;
}

View File

@@ -25,9 +25,9 @@
bool check_cd_sector_channel(CdEccContext *context, uint8_t *sector, bool *unknown, bool *has_edc, bool *edc_correct,
bool *has_ecc_p, bool *ecc_p_correct, bool *has_ecc_q, bool *ecc_q_correct)
{
int i;
uint32_t storedEdc, edc, calculatedEdc;
int size, pos;
int i = 0;
uint32_t storedEdc = 0, edc = 0, calculatedEdc = 0;
int size = 0, pos = 0;
uint8_t zeroaddress[4];
*has_edc = false;

View File

@@ -25,15 +25,14 @@
char *byte_array_to_hex_string(const unsigned char *array, int array_size)
{
char *hex_string = NULL;
int j;
int i;
int j = 0;
hex_string = malloc(array_size * 2 + 1);
if(hex_string == NULL) return NULL;
j = 0;
for(i = 0; i < array_size; i++)
for (int i = 0; i < array_size; i++)
{
hex_string[j] = (array[i] >> 4) + '0';
if(hex_string[j] > '9') hex_string[j] += 0x7;

View File

@@ -21,7 +21,7 @@
int identify(char *path)
{
int ret;
int ret = 0;
ret = aaruf_identify(path);

View File

@@ -29,12 +29,12 @@
int info(char *path)
{
aaruformatContext *ctx;
char *strBuffer;
aaruformatContext *ctx = NULL;
char *strBuffer = NULL;
UErrorCode u_error_code = U_ZERO_ERROR;
uint i, j;
mediaTagEntry *mediaTag;
mediaTagEntry *tmpMediaTag;
uint i = 0, j = 0;
mediaTagEntry const *mediaTag = NULL;
mediaTagEntry const *tmpMediaTag = NULL;
UChar ustr[128];
ctx = aaruf_open(path);

View File

@@ -27,16 +27,16 @@ int printhex(unsigned char *array, unsigned int length, int width, bool color)
char length_hex[17];
char str[256];
char format[256];
int rows;
int last;
int offset_length;
int rows = 0;
int last = 0;
int offset_length = 0;
int str_length = strlen("Offset");
int i;
int b;
int last_bytes;
int last_spaces;
int j;
unsigned char v;
int i = 0;
int b = 0;
int last_bytes = 0;
int last_spaces = 0;
int j = 0;
unsigned char v = 0;
if(array == NULL) return 0;

View File

@@ -26,10 +26,10 @@
int read(unsigned long long sector_no, char *path)
{
aaruformatContext *ctx;
int32_t res;
uint32_t length;
uint8_t *data;
aaruformatContext *ctx = NULL;
int32_t res = 0;
uint32_t length = 0;
uint8_t *data = NULL;
ctx = aaruf_open(path);
@@ -76,10 +76,10 @@ int read(unsigned long long sector_no, char *path)
int read_long(unsigned long long sector_no, char *path)
{
aaruformatContext *ctx;
int32_t res;
uint32_t length;
uint8_t *data;
aaruformatContext *ctx = NULL;
int32_t res = 0;
uint32_t length = 0;
uint8_t *data = NULL;
ctx = aaruf_open(path);

View File

@@ -25,8 +25,8 @@
int verify(char *path)
{
aaruformatContext *ctx;
uint32_t res;
aaruformatContext *ctx = NULL;
uint32_t res = 0;
ctx = aaruf_open(path);
@@ -50,17 +50,18 @@ int verify(char *path)
int verify_sectors(char *path)
{
aaruformatContext *ctx;
uint64_t s;
uint8_t *buffer;
aaruformatContext *ctx = NULL;
uint8_t *buffer = NULL;
uint32_t buffer_len = 2352;
int32_t res;
CdEccContext *cd_ecc_context;
int32_t res = 0;
CdEccContext *cd_ecc_context = NULL;
ctx = aaruf_open(path);
bool verify_result;
bool unknown, has_edc, edc_correct, has_ecc_p, ecc_p_correct, has_ecc_q, ecc_q_correct;
uint64_t errors, unknowns;
bool any_error;
bool verify_result = false;
bool has_edc = false, has_ecc_p = false, ecc_p_correct = false, has_ecc_q = false, ecc_q_correct = false;
bool edc_correct = false;
bool unknown = false;
uint64_t errors = 0, unknowns = 0;
bool any_error = false;
if(ctx == NULL)
{
@@ -79,7 +80,7 @@ int verify_sectors(char *path)
unknowns = 0;
any_error = false;
for(s = 0; s < ctx->imageInfo.Sectors; s++)
for (uint64_t s = 0; s < ctx->imageInfo.Sectors; s++)
{
printf("\rVerifying sector %llu...", s);
res = aaruf_read_sector_long(ctx, s, buffer, &buffer_len);