Re: Build failure with GCC 15 due to -Werror=unterminated-string-initialization

From: Brahmajit
Date: Thu Oct 03 2024 - 02:52:55 EST


On 02.10.2024 22:54, Al Viro wrote:
> ... and looking at the actual code using that, just lose the entire
> array -
> if (memcmp(dir_entry[0].de_fname, ".", 2) ||
> memcmp(dir_entry[1].de_fname, "..", 3))
> error = 1;
> and be done with that.

Hey sorry for the initial bad code, I'm just starting out. With your
recommendation I wrote this, does this look good?

--- a/fs/qnx6/inode.c
+++ b/fs/qnx6/inode.c
@@ -179,8 +179,7 @@ static int qnx6_statfs(struct dentry *dentry, struct kstatfs *buf)
*/
static const char *qnx6_checkroot(struct super_block *s)
{
- static char match_root[2][3] = {".\0\0", "..\0"};
- int i, error = 0;
+ int error = 0;
struct qnx6_dir_entry *dir_entry;
struct inode *root = d_inode(s->s_root);
struct address_space *mapping = root->i_mapping;
@@ -189,11 +188,9 @@ static const char *qnx6_checkroot(struct super_block *s)
if (IS_ERR(folio))
return "error reading root directory";
dir_entry = kmap_local_folio(folio, 0);
- for (i = 0; i < 2; i++) {
- /* maximum 3 bytes - due to match_root limitation */
- if (strncmp(dir_entry[i].de_fname, match_root[i], 3))
- error = 1;
- }
+ if (memcmp(dir_entry[0].de_fname, ".", 2) ||
+ memcmp(dir_entry[1].de_fname, "..", 3))
+ error = 1;
folio_release_kmap(folio, dir_entry);
if (error)
return "error reading root directory.";

--
Regards,
listout