Subj : rmw compile warnings
To   : Maurice Kinal
From : Andrew Alt
Date : Wed Mar 03 2021 11:15 am

-=> 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

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",

     ^~~~~~


        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

    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,
                                             ^~~~~~~~~~

    snprintf (file.info, sizeof (file.info), "%s%s%s%s", file.relative_path,
file.relative_info_path,

^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~
             file.base_name, TRASHINFO_EXT);
             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

          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]));
                                                         ^~~~~~

          snprintf (recover_file, sizeof (recover_file), "%s%s",
waste_curr->files, item_name (items[i]));

^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~

      snprintf (full_path, req_len, "%s%s", waste_curr->files, entry->d_name);
                                     ^~
 CC       config_rmw.o

  snprintf (waste_curr->files, req_len, "%s%s", waste_curr->parent,
"/files/");
                                         ^~

  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

                "%s%s", waste_curr->info, st_trashinfo_dir_entry->d_name);
                 ^~

      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,
                                            ^~~~~~~~

      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);
                                   ^

  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

      sscanf (str + pos_str, "%2hhx", dest + pos_dest);
                              ~~~~^   ~~~~~~~~~~~~~~~
                              %2hhx

    snprintf (buffer, sizeof (buffer), "%ld B", (long) size);
                                           ^~

    snprintf (buffer, sizeof (buffer), "%ld B", (long) size);
    ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    snprintf (buffer, sizeof (buffer), "%ld.%d %ciB", (long) size,
                                           ^

    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)