Hello values-> mode pass normally even with -Wall -Wextra, should I remove (mode_t) -1 ?
It is needed for tmpfs_root_mode in the if statement when using -Wall -Wextra : if (tmpfs_root_mode == (mode_t)-1) So I put it for values->mode to be more clear On Tue, Nov 24, 2026 at 2:39 AM Samuel Thibault <[email protected]> wrote: > Re, > > Ahmed Khider, le mar. 24 nov. 2026 03:59:57 +0300, a ecrit: > > --- > > tmpfs/tmpfs.c | 14 ++++++++++---- > > 1 file changed, 10 insertions(+), 4 deletions(-) > > > > diff --git a/tmpfs/tmpfs.c b/tmpfs/tmpfs.c > > index ad5e298..ce43a36 100644 > > --- a/tmpfs/tmpfs.c > > +++ b/tmpfs/tmpfs.c > > @@ -191,7 +191,7 @@ parse_opt (int key, char *arg, struct argp_state > *state) > > return ENOMEM; > > state->hook = values; > > values->size = -1; > > - values->mode = -1; > > + values->mode = (mode_t) -1; > > Again, is this fixing a warning? > > > break; > > case ARGP_KEY_FINI: > > free (values); > > @@ -199,10 +199,11 @@ parse_opt (int key, char *arg, struct argp_state > *state) > > break; > > > > case 'm': /* --mode=OCTAL */ > > - { > > + { > > + errno = 0; > > char *end = NULL; > > mode_t mode = strtoul (arg, &end, 8); > > - if (end == NULL || end == arg) > > + if (errno != 0 || *end != '\0' || end == NULL || end == arg) > > It's no use testing for end == NULL after reading *end. > > > { > > argp_error (state, "argument must be an octal number"); > > return EINVAL; > > @@ -257,7 +258,12 @@ parse_opt (int key, char *arg, struct argp_state > *state) > > > > case ARGP_KEY_SUCCESS: > > /* All options parse successfully, so implement ours if > possible. */ > > - tmpfs_page_limit = values->size / vm_page_size; > > + > > + if(values->size > vm_page_size ) > > + tmpfs_page_limit = (values->size + vm_page_size -1) / vm_page_size; > > + else > > + tmpfs_page_limit = 1; > > You do not need to make a special case: whenever size is between 1 and > vm_page_size-1, the rounded-up division will end up with one page. > > Samuel >
