diff --git a/c-programming/reverse-ramdisk.c b/c-programming/reverse-ramdisk.c index 5581800..da5a4d1 100644 --- a/c-programming/reverse-ramdisk.c +++ b/c-programming/reverse-ramdisk.c @@ -320,26 +320,29 @@ int tf_read(int ID, size_t offset, void* dest, size_t data_size) { int main(void) { DBG_PRINT("started\n"); - int ID_1 = tf_alloc(4, sizeof(int)); - int ID_2 = tf_alloc(16, sizeof(uint16_t)); +#define ARRAY_1_LEN 4 +#define ARRAY_2_LEN 16 + + int ID_1 = tf_alloc(ARRAY_1_LEN, sizeof(int)); + int ID_2 = tf_alloc(ARRAY_2_LEN, sizeof(uint16_t)); if (ID_1 == -1 || ID_2 == -1) RETREAT("tf_alloc"); DBG_PRINT("allocated memory\n"); - int test_data_1[4] = {123, 456, 789, -123}; + int test_data_1[ARRAY_1_LEN] = {123, 456, 789, -123}; DBG_PRINT("initialized array 1\n"); - uint16_t test_data_2[16]; - for (size_t i = 0; i < 16; i++) + uint16_t test_data_2[ARRAY_2_LEN]; + for (size_t i = 0; i < ARRAY_2_LEN; i++) test_data_2[i] = 1 << i; DBG_PRINT("initialized array 2\n"); - for (size_t i = 0; i < 4; i++) + for (size_t i = 0; i < ARRAY_1_LEN; i++) if (tf_write(ID_1, i * sizeof(int), &test_data_1[i], sizeof(int)) == -1) RETREAT("tf_write"); DBG_PRINT("wrote array 1\n"); - for (size_t i = 0; i < 16; i++) + for (size_t i = 0; i < ARRAY_2_LEN; i++) if (tf_write(ID_2, i * sizeof(uint16_t), &test_data_2[i], sizeof(uint16_t)) == -1) RETREAT("tf_write"); @@ -356,23 +359,23 @@ int main(void) { test_data_2[i] ^= 1; DBG_PRINT("filled array 2 with garbage\n"); - for (size_t i = 0; i < 4; i++) + for (size_t i = 0; i < ARRAY_1_LEN; i++) if (tf_read(ID_1, i * sizeof(int), &test_data_1[i], sizeof(int)) == -1) RETREAT("tf_read"); DBG_PRINT("restored array 1\n"); - for (size_t i = 0; i < 16; i++) + for (size_t i = 0; i < ARRAY_2_LEN; i++) if (tf_read(ID_2, i * sizeof(uint16_t), &test_data_2[i], sizeof(uint16_t)) == -1) RETREAT("tf_read"); DBG_PRINT("restored array 2\n"); DBG_PRINT("Values (1): "); - for (size_t i = 0; i < 4; i++) - DBG_PRINT("%d%c", test_data_1[i], i == 3 ? '\n' : ' '); + for (size_t i = 0; i < ARRAY_1_LEN; i++) + DBG_PRINT("%d%c", test_data_1[i], i == (ARRAY_1_LEN - 1) ? '\n' : ' '); DBG_PRINT("Values (2): "); - for (size_t i = 0; i < 16; i++) - DBG_PRINT("%d%c", test_data_2[i], i == 15 ? '\n' : ' '); + for (size_t i = 0; i < ARRAY_2_LEN; i++) + DBG_PRINT("%d%c", test_data_2[i], i == (ARRAY_2_LEN - 1) ? '\n' : ' '); tf_free(ID_1); tf_free(ID_2);