Subj : rmw compile warnings To : Maurice Kinal From : Andrew Alt Date : Wed Mar 03 2021 11:15:20 -=> Maurice Kinal wrote to Andrew Alt <=- MK> -={ 2021-03-01 17:54:39.246915930+00:00 }=- MK> Hey Andrew! MK> The above was done on my custom pure 64-bit nondistribution rootfs (aka MK> motorshed) using gcc-10.2.0/glibc-2.33 and friends. MK> Does this help any? Hi, Maurice! On Debian with gcc 8 I wasn't getting any warnings. So.. that reminds me I might have to make some changes to get rid of those warnings. :) I'm not really sure of the best way to fix those though. I have mixed feelings about using snprintf(). I have redundant checks in place to check string lengths before concatenating, and I don't want strings to just get truncated. rmw is designed to exit (without a segfault) with a message if a buffer overflow is attempted. I think I should just change all my snprintf() statements to sprintf()... Which probably won't fix the warnings you mentioned, lol ;) I can get even more if I use CFLAGS="-Wformat -Wstringop-truncation -Wformat-overflow=2 -pedantic -Wextra -Wformat-truncation=2" :) Any suggestions? Probably if don't set fixed lengths in the structures and instead use calloc() at the time when I concatenate and write the final string, that would get rid of some of these annoying messages I get when I use the flags mentioned above. Seems like that would require a lot of extra manual memory management though. Things are working fine right now so I'm reluctant to change the code until I really understand well how best to fix those warnings. CC main.o .../../rmw/src/main.c: In function â ÿremove_to_wasteâ Ö: ../../rmw/src/main.c:422:101: warning: â ÿ%sâ Ö directive output between 0 and 4096 bytes may exceed minimum required size of 4095 [-Wformat-truncation=] tf (st_file_properties.waste_dest_name, sizeof (st_file_properties.waste_dest_name), "%s%s", ^~ .../../rmw/src/main.c:422:100: note: assuming directive output of 1 byte tf (st_file_properties.waste_dest_name, sizeof (st_file_properties.waste_dest_name), "%s%s", ^~~~~~ .../../rmw/src/main.c:422:9: note: â ÿsnprintfâ Ö output 1 or more bytes (assuming 4098) into a destination of size 4097 snprintf (st_file_properties.waste_dest_name, sizeof (st_file_properties.waste_dest_name), "%s%s", ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~ waste_curr->files, st_file_properties.base_name); ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ CC restore_rmw.o .../../rmw/src/restore_rmw.c: In function â ÿrestoreâ Ö: ../../rmw/src/restore_rmw.c:72:47: warning: â ÿ%sâ Ö directive output between 0 and 4096 bytes may exceed minimum required size of 4095 [-Wformat-truncation=] snprintf (file.info, sizeof (file.info), "%s%s%s%s", file.relative_path, file.relative_info_path, ^~ ~~~~~~~~~~~~~~~~~~ .../../rmw/src/restore_rmw.c:72:46: note: assuming directive output of 1 byte snprintf (file.info, sizeof (file.info), "%s%s%s%s", file.relative_path, file.relative_info_path, ^~~~~~~~~~ .../../rmw/src/restore_rmw.c:72:5: note: â ÿsnprintfâ Ö output 11 or more bytes (assuming 4116) into a destination of size 4097 snprintf (file.info, sizeof (file.info), "%s%s%s%s", file.relative_path, file.relative_info_path, ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~ file.base_name, TRASHINFO_EXT); ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ .../../rmw/src/restore_rmw.c: In function â ÿrestore_selectâ Ö: ../../rmw/src/restore_rmw.c:364:59: warning: â ÿ%sâ Ö directive output between 0 and 4096 bytes may exceed minimum required size of 4095 [-Wformat-truncation=] snprintf (recover_file, sizeof (recover_file), "%s%s", waste_curr->files, item_name (items[i])); ^~ .../../rmw/src/restore_rmw.c:364:58: note: assuming directive output of 1 byte snprintf (recover_file, sizeof (recover_file), "%s%s", waste_curr->files, item_name (items[i])); ^~~~~~ .../../rmw/src/restore_rmw.c:364:11: note: â ÿsnprintfâ Ö output 1 or more bytes (assuming 4098) into a destination of size 4097 snprintf (recover_file, sizeof (recover_file), "%s%s", waste_curr->files, item_name (items[i])); ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~ .../../rmw/src/restore_rmw.c:244:38: warning: â ÿ%sâ Ö directive output between 0 and 4096 bytes may exceed minimum required size of 4095 [-Wformat-truncation=] snprintf (full_path, req_len, "%s%s", waste_curr->files, entry->d_name); ^~ CC config_rmw.o .../../rmw/src/config_rmw.c: In function â ÿparse_line_wasteâ Ö: ../../rmw/src/config_rmw.c:306:42: warning: â ÿ%sâ Ö directive output between 0 and 4096 bytes may exceed minimum required size of 4095 [-Wformat-truncation=] snprintf (waste_curr->files, req_len, "%s%s", waste_curr->parent, "/files/"); ^~ .../../rmw/src/config_rmw.c:324:41: warning: â ÿ%sâ Ö directive output between 0 and 4096 bytes may exceed minimum required size of 4095 [-Wformat-truncation=] snprintf (waste_curr->info, req_len, "%s%s", waste_curr->parent, "/info/"); ^~ CC parse_cli_options.o CC strings_rmw.o CC purging_rmw.o .../../rmw/src/purging_rmw.c: In function â ÿpurgeâ Ö: ../../rmw/src/purging_rmw.c:332:18: warning: â ÿ%sâ Ö directive output between 0 and 4096 bytes may exceed minimum required size of 4095 [-Wformat-truncation=] "%s%s", waste_curr->info, st_trashinfo_dir_entry->d_name); ^~ .../../rmw/src/purging_rmw.c: In function â ÿorphan_maintâ Ö: ../../rmw/src/purging_rmw.c:562:46: warning: â ÿ%sâ Ö directive output between 0 and 4096 bytes may exceed minimum required size of 4095 [-Wformat-truncation=] snprintf (path_to_trashinfo, req_len, "%s%s%s", waste_curr->info, ^~ .../../rmw/src/purging_rmw.c:562:45: note: assuming directive output of 1 byte snprintf (path_to_trashinfo, req_len, "%s%s%s", waste_curr->info, ^~~~~~~~ .../../rmw/src/purging_rmw.c:574:57: warning: â ÿ%sâ Ö directive output between 0 and 4096 bytes may exceed minimum required size of 4095 [-Wformat-truncation=] snprintf (st_file_properties.real_path, req_len, "%s%s%s", ^~ .../../rmw/src/purging_rmw.c:574:56: note: assuming directive output of 1 byte snprintf (st_file_properties.real_path, req_len, "%s%s%s", ^~~~~~~~ CC messages_rmw.o CC time_rmw.o CC trashinfo_rmw.o .../../rmw/src/trashinfo_rmw.c:31:36: warning: initializer element is not a constant expression [-Wpedantic] const int LEN_MAX_TRASHINFO_LINE = (PATH_MAX * 3 + strlen ("Path=") + 1); ^ .../../rmw/src/trashinfo_rmw.c: In function â ÿcreate_trashinfoâ Ö: ../../rmw/src/trashinfo_rmw.c:47:40: warning: â ÿ%sâ Ö directive output between 0 and 4096 bytes may exceed minimum required size of 4095 [-Wformat-truncation=] snprintf (final_info_dest, req_len, "%s%s", waste_curr->info, st_f_props->base_name); ^~ .../../rmw/src/trashinfo_rmw.c:47:39: note: assuming directive output of 1 byte snprintf (final_info_dest, req_len, "%s%s", waste_curr->info, st_f_props->base_name); ^~~~~~ CC utils_rmw.o .../../rmw/src/utils_rmw.c: In function â ÿunescape_urlâ Ö: ../../rmw/src/utils_rmw.c:317:35: warning: format â ÿ%hhxâ Ö expects argument of type â ÿunsigned char *â Ö, but argument 3 has type â ÿchar *â Ö [-Wformat=] sscanf (str + pos_str, "%2hhx", dest + pos_dest); ~~~~^ ~~~~~~~~~~~~~~~ %2hhx .../../rmw/src/utils_rmw.c: In function â ÿhuman_readable_sizeâ Ö: ../../rmw/src/utils_rmw.c:143:44: warning: â ÿ Bâ Ö directive output may be truncated writing 2 bytes into a region of size between 0 and 19 [-Wformat-truncation=] snprintf (buffer, sizeof (buffer), "%ld B", (long) size); ^~ .../../rmw/src/utils_rmw.c:143:5: note: â ÿsnprintfâ Ö output between 4 and 23 bytes into a destination of size 20 snprintf (buffer, sizeof (buffer), "%ld B", (long) size); ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ .../../rmw/src/utils_rmw.c:140:44: warning: â ÿ.â Ö directive output may be truncated writing 1 byte into a region of size between 0 and 19 [-Wformat-truncation=] snprintf (buffer, sizeof (buffer), "%ld.%d %ciB", (long) size, ^ .../../rmw/src/utils_rmw.c:140:5: note: â ÿsnprintfâ Ö output between 8 and 37 bytes into a destination of size 20 snprintf (buffer, sizeof (buffer), "%ld.%d %ciB", (long) size, ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ (remainder * 10) / 1024, prefix[power]); ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ CC bst.o CCLD ../rmw -- -Andy .... A few feathers short of a whole duck. -+- MultiMail/Linux v0.52 --- BBBS/Li6 v4.10 Toy-5 * Origin: Prism bbs (1:261/38) .