From: Diego Nieto Cid <[email protected]>
Hello,
I was looking at some warnings in Hurd build logs and found one
about discarding const qualifier at some places like, for instance, fatfs:
------->>8--- fatfs compiler warning --->8---
../../fatfs/node-create.c: In function 'diskfs_create_node':
../../fatfs/node-create.c:180:37: warning: passing argument 2 of
'diskfs_lookup' discards 'const' qualifier from pointer target type
[-Wdiscarded-qualifiers]
180 | err = diskfs_lookup (dir, name, REMOVE, &foo, ds, cred);
| ^~~~
In file included from ../include/hurd/diskfs.h:1,
from ../../fatfs/node-create.c:29:
../../fatfs/../libdiskfs/diskfs.h:825:30: note: expected 'char *' but
argument is of type 'const char *'
825 | char *name, lookup_flags_t l_flags,
| ~~~~~~^~~~
------->8------------------------------->8---
The related libdiskfs interfaces have a mixture of const and non const name
arguments as shown below:
------->8--- libdiskfs interface --->8---
error_t
diskfs_create_node (struct node *dir, const char *name, mode_t mode,
struct node **newnode, struct protid *cred,
struct dirstat *ds);
error_t diskfs_lookup_hard (struct node *dp,
const char *name, lookup_flags_t l_flags,
struct node **np, struct dirstat *ds,
struct protid *cred);
error_t diskfs_lookup (struct node *dp,
char *name, lookup_flags_t l_flags,
struct node **np, struct dirstat *ds,
struct protid *cred);
------->8--------------------------->8---
So, diskfs_crate_node claims not to modify the name parameter and
diskfs_lookup decides not to do so such that it can trim leading and
trailing forward slashes.
However, fatfs calls diskfs_lookup from diskfs_crate_node passing over
the name argument and, thus, discarding it's const qualifier.
------->8--- fatfs/node-create.c --->8---
...
err = diskfs_lookup (dir, name, REMOVE, &foo, ds, cred);
if (err)
{
/* The new node couldn't be removed, we have a big
problem now. */
*newnode = NULL;
return err;
}
...
------->8--------------------------->8---
So, I propose this RFC patch for discussion. Currently, I'm not
very fond of it as it may pose unforeseeable consequences for
callers of diskfs_lookup which rely on its trimming side effect.
Maybe an assert would be better than just returning EINVAL.
--
2.53.0