From bb43a5dc53221dbb2608beafe023f30948312d0f Mon Sep 17 00:00:00 2001 From: Intel A80486DX2-66 Date: Wed, 27 Dec 2023 21:29:16 +0300 Subject: [PATCH] reverse-ramdisk.c: fix file name length, use PRIuMAX for format, flush stdout in debug --- c-programming/reverse-ramdisk.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/c-programming/reverse-ramdisk.c b/c-programming/reverse-ramdisk.c index e658e1a..0c2e414 100644 --- a/c-programming/reverse-ramdisk.c +++ b/c-programming/reverse-ramdisk.c @@ -9,7 +9,7 @@ production purposes. GCC/Clang/TCC: Compile with -DTEST to set macro TEST as defined, with -DDEBUG to enable debug mode -To-Do: error handling on line 167, function fread() +To-Do: error handling on line 179, function fread() */ #include @@ -52,14 +52,15 @@ int tf_alloc(size_t n, size_t type_size) { if (num_temp_files == 0) len_digit = 1; else - len_digit = (size_t) log((double) num_temp_files + 1.) / log(10.); + len_digit = (size_t) ceil(log((double) num_temp_files + 1.) / log(10.)); size_t file_path_len = len_digit + strlen("tf_.tmp"); char* file_path = malloc((file_path_len + 1) * sizeof(char)); if (file_path == NULL) { line_fail(-2); return -1; } - int res = snprintf(file_path, file_path_len, "tf_%zu.tmp", num_temp_files); + int res = snprintf(file_path, file_path_len, "tf_%" PRIuMAX ".tmp", + (uintmax_t) num_temp_files); if ((size_t) res != file_path_len) { line_fail(-2); return -1; @@ -191,6 +192,7 @@ int tf_read(int ID, size_t offset, void* dest, size_t data_size) { for (size_t i = 0; i < data_size; i++) printf("0x%02" PRIX8 " ", *((uint8_t*)((uint8_t*)dest + i))); printf("'\n"); + fflush(stdout); #endif return 0; }