Add const qualifiers to function parameters and local variables for improved type safety

This commit is contained in:
2025-10-01 02:34:42 +01:00
parent f1811e6b3c
commit a7434322ea
23 changed files with 106 additions and 97 deletions

View File

@@ -31,8 +31,9 @@ int printhex(unsigned char *array, unsigned int length, int width, bool color)
int read_long(unsigned long long sector_no, const char *path);
int verify(const char *path);
int verify_sectors(const char *path);
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);
bool check_cd_sector_channel(CdEccContext *context, const 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 compare(const char *path1, const char *path2);
int cli_compare(const char *path1, const char *path2);
int convert(const char *input_path, const char *output_path);

View File

@@ -110,9 +110,9 @@ int cli_compare(const char *path1, const char *path2)
read_result2 = aaruf_read_sector(ctx2, sector, buffer2, &buffer2_length);
// Handle read errors or missing sectors
bool sector1_available = (read_result1 == AARUF_STATUS_OK);
bool sector2_available = (read_result2 == AARUF_STATUS_OK);
bool sectors_different = false;
const bool sector1_available = (read_result1 == AARUF_STATUS_OK);
const bool sector2_available = (read_result2 == AARUF_STATUS_OK);
bool sectors_different = false;
if(!sector1_available && !sector2_available)
{
@@ -149,7 +149,7 @@ int cli_compare(const char *path1, const char *path2)
// Update progress every 1000 sectors or at the end
if(sectors_processed % 1000 == 0 || sector == total_sectors - 1)
{
int progress = (int)((sectors_processed * 100) / total_sectors);
const int progress = (int)((sectors_processed * 100) / total_sectors);
printf("Progress: %d%% (%llu/%llu sectors)\r", progress, (unsigned long long)sectors_processed,
(unsigned long long)total_sectors);
fflush(stdout);

View File

@@ -39,7 +39,7 @@ int cmd_identify(int argc, char *argv[])
return -1;
}
int result = identify(filename->sval[0]);
const int result = identify(filename->sval[0]);
arg_freetable(argtable, sizeof(argtable) / sizeof(argtable[0]));
return result;
}
@@ -58,7 +58,7 @@ int cmd_info(int argc, char *argv[])
return -1;
}
int result = info(filename->sval[0]);
const int result = info(filename->sval[0]);
arg_freetable(argtable, sizeof(argtable) / sizeof(argtable[0]));
return result;
}
@@ -78,7 +78,7 @@ int cmd_compare(int argc, char *argv[])
return -1;
}
int result = compare(filename1->sval[0], filename2->sval[0]);
const int result = compare(filename1->sval[0], filename2->sval[0]);
arg_freetable(argtable, sizeof(argtable) / sizeof(argtable[0]));
return result;
}
@@ -98,7 +98,7 @@ int cmd_cli_compare(int argc, char *argv[])
return -1;
}
int result = cli_compare(filename1->sval[0], filename2->sval[0]);
const int result = cli_compare(filename1->sval[0], filename2->sval[0]);
arg_freetable(argtable, sizeof(argtable) / sizeof(argtable[0]));
return result;
}
@@ -118,7 +118,8 @@ int cmd_read_common(int argc, char *argv[], bool long_mode)
return -1;
}
int result = long_mode ? read_long(sector->ival[0], filename->sval[0]) : read(sector->ival[0], filename->sval[0]);
const int result =
long_mode ? read_long(sector->ival[0], filename->sval[0]) : read(sector->ival[0], filename->sval[0]);
arg_freetable(argtable, sizeof(argtable) / sizeof(argtable[0]));
return result;
@@ -142,7 +143,7 @@ int cmd_verify_common(int argc, char *argv[], bool sectors_mode)
return -1;
}
int result = sectors_mode ? verify_sectors(filename->sval[0]) : verify(filename->sval[0]);
const int result = sectors_mode ? verify_sectors(filename->sval[0]) : verify(filename->sval[0]);
arg_freetable(argtable, sizeof(argtable) / sizeof(argtable[0]));
return result;
@@ -167,7 +168,7 @@ int cmd_convert(int argc, char *argv[])
return -1;
}
int result = convert(input_filename->sval[0], output_filename->sval[0]);
const int result = convert(input_filename->sval[0], output_filename->sval[0]);
arg_freetable(argtable, sizeof(argtable) / sizeof(argtable[0]));
return result;
}

View File

@@ -28,9 +28,9 @@
void draw_progress_bar(int row, int percent)
{
int width = tb_width() / 2;
int bar_width = width - 4; // leave space for borders
int filled = (bar_width * percent) / 100;
const int width = tb_width() / 2;
const int bar_width = width - 4; // leave space for borders
const int filled = (bar_width * percent) / 100;
// Draw progress bar outline
tb_printf(2, row, TB_YELLOW | TB_BOLD, TB_BLUE, "[");

View File

@@ -22,11 +22,12 @@
#include <aaruformat.h>
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)
bool check_cd_sector_channel(CdEccContext *context, const 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)
{
uint32_t storedEdc = 0, edc = 0, calculatedEdc = 0;
int size = 0, pos = 0;
int size = 0, pos = 0;
uint8_t zeroaddress[4];
*has_edc = false;

View File

@@ -24,7 +24,7 @@
#include "aaruformattool.h"
int read(unsigned long long sector_no, const char *path)
int read(const unsigned long long sector_no, const char *path)
{
aaruformatContext *ctx = NULL;
int32_t res = 0;
@@ -76,7 +76,7 @@ int read(unsigned long long sector_no, const char *path)
return AARUF_STATUS_OK;
}
int read_long(unsigned long long sector_no, const char *path)
int read_long(const unsigned long long sector_no, const char *path)
{
aaruformatContext *ctx = NULL;
int32_t res = 0;