Skip to contentSkip to conversation

md/bcache: Mark __nonstring look-up table

PATCH Superseded Kees Cook 3 participants 7 messages Apr 16, 2025 – Apr 17, 2025 bcache (block layer cache)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Kees Cook

author
#0 lore raw

PATCH 1/1 md/bcache: Mark __nonstring look-up table

GCC 15's new -Wunterminated-string-initialization notices that the 16 character lookup table "zero_uuid" (which is not used as a C-String) needs to be marked as "nonstring":

drivers/md/bcache/super.c: In function 'uuid_find_empty':
drivers/md/bcache/super.c:549:43: warning: initializer-string for array of 'char' truncates NUL terminator but destination lacks 'nonstring' attribute (17 chars into 16 available) [-Wunterminated-string-initialization]

  549 |         static const char zero_uuid[16] = "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0";
      |                                           ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Add the annotation to silence the GCC warning.

---
Cc: Coly Li <[email protected]>
Cc: Kent Overstreet <[email protected]>
Cc: [email protected]

---
 drivers/md/bcache/super.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/md/bcache/super.c +1 -1
index e42f1400cea9..577d048170fe 100644
@@ -546,7 +546,7 @@ static struct uuid_entry *uuid_find(struct cache_set *c, const char *uuid)
 
 static struct uuid_entry *uuid_find_empty(struct cache_set *c)
 {
-	static const char zero_uuid[16] = "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0";
+	static const char zero_uuid[] __nonstring = "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0";
 
 	return uuid_find(c, zero_uuid);
 }
Signature · 1 line
2.34.1
#1 lore raw
Quoted 13 lines

2025年4月17日 06:01,Kees Cook <[email protected]> 写道:

GCC 15's new -Wunterminated-string-initialization notices that the 16 character lookup table "zero_uuid" (which is not used as a C-String) needs to be marked as "nonstring":

drivers/md/bcache/super.c: In function 'uuid_find_empty':
drivers/md/bcache/super.c:549:43: warning: initializer-string for array of 'char' truncates NUL terminator but destination lacks 'nonstring' attribute (17 chars into 16 available) [-Wunterminated-string-initialization]

 549 |         static const char zero_uuid[16] = "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0";
     |                                           ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Quoted 7 lines

Add the annotation to silence the GCC warning.

---
Cc: Coly Li <[email protected]>
Cc: Kent Overstreet <[email protected]>
Cc: [email protected] <mailto:[email protected]>

It looks good to me. Thanks for the fix up.

Coly Li

Quoted 21 lines

---
drivers/md/bcache/super.c | 2 +-

1 file changed, 1 insertion(+), 1 deletion(-)
drivers/md/bcache/super.c +1 -1
index e42f1400cea9..577d048170fe 100644
@@ -546,7 +546,7 @@ static struct uuid_entry *uuid_find(struct cache_set *c, const char *uuid)
 
 static struct uuid_entry *uuid_find_empty(struct cache_set *c)
 {
- static const char zero_uuid[16] = "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0";
+ static const char zero_uuid[] __nonstring = "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0";
 
 return uuid_find(c, zero_uuid);
 }
Signature · 1 line
2.34.1
#2 lore raw
In reply to Kees Cook
Quoted 26 lines · Kees Cook

GCC 15's new -Wunterminated-string-initialization notices that the 16 character lookup table "zero_uuid" (which is not used as a C-String) needs to be marked as "nonstring":

drivers/md/bcache/super.c: In function 'uuid_find_empty':
drivers/md/bcache/super.c:549:43: warning: initializer-string for array of 'char' truncates NUL terminator but destination lacks 'nonstring' attribute (17 chars into 16 available) [-Wunterminated-string-initialization]

  549 |         static const char zero_uuid[16] = "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0";
      |                                           ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Add the annotation to silence the GCC warning.

---
Cc: Coly Li <[email protected]>
Cc: Kent Overstreet <[email protected]>
Cc: [email protected]

---
 drivers/md/bcache/super.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/md/bcache/super.c +0 -0
index e42f1400cea9..577d048170fe 100644

drivers/md/bcache/super.c static struct uuid_entry *uuid_find(struct cache_set *c, const char *uuid) · line 550

Quoted 6 lines
drivers/md/bcache/super.c +1 -1
@@ -546,7 +546,7 @@ static struct uuid_entry *uuid_find(struct cache_set *c, const char *uuid)
 
 static struct uuid_entry *uuid_find_empty(struct cache_set *c)
 {
-       static const char zero_uuid[16] = "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0";
+       static const char zero_uuid[] __nonstring = "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0";
 

Just

static const char zero_uuid[16] = {};

should work fine here too. No need for the initializer.

Quoted 6 lines
drivers/md/bcache/super.c +0 -1
        return uuid_find(c, zero_uuid);
 }
--

2.34.1

author
#3 lore raw
Quoted 36 lines · Ard Biesheuvel
Quoted 26 lines · Kees Cook

GCC 15's new -Wunterminated-string-initialization notices that the 16 character lookup table "zero_uuid" (which is not used as a C-String) needs to be marked as "nonstring":

drivers/md/bcache/super.c: In function 'uuid_find_empty':
drivers/md/bcache/super.c:549:43: warning: initializer-string for array of 'char' truncates NUL terminator but destination lacks 'nonstring' attribute (17 chars into 16 available) [-Wunterminated-string-initialization]

  549 |         static const char zero_uuid[16] = "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0";
      |                                           ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Add the annotation to silence the GCC warning.

---
Cc: Coly Li <[email protected]>
Cc: Kent Overstreet <[email protected]>
Cc: [email protected]

---
 drivers/md/bcache/super.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/md/bcache/super.c +0 -0
index e42f1400cea9..577d048170fe 100644

drivers/md/bcache/super.c static struct uuid_entry *uuid_find(struct cache_set *c, const char *uuid) · line 550

Quoted 6 lines
drivers/md/bcache/super.c +1 -1
@@ -546,7 +546,7 @@ static struct uuid_entry *uuid_find(struct cache_set *c, const char *uuid)
 
 static struct uuid_entry *uuid_find_empty(struct cache_set *c)
 {
-       static const char zero_uuid[16] = "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0";
+       static const char zero_uuid[] __nonstring = "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0";
 

Just

Quoted 3 lines

static const char zero_uuid[16] = {};

should work fine here too. No need for the initializer.

🤦 Yes. This is what I get for fixing dozens of these. I'll send a v2...

-Kees

Signature · 1 line
Kees Cook
#4 lore raw
Quoted 43 lines

2025年4月17日 15:10,Kees Cook <[email protected]> 写道:

Quoted 36 lines · Ard Biesheuvel
Quoted 26 lines · Kees Cook

GCC 15's new -Wunterminated-string-initialization notices that the 16 character lookup table "zero_uuid" (which is not used as a C-String) needs to be marked as "nonstring":

drivers/md/bcache/super.c: In function 'uuid_find_empty':
drivers/md/bcache/super.c:549:43: warning: initializer-string for array of 'char' truncates NUL terminator but destination lacks 'nonstring' attribute (17 chars into 16 available) [-Wunterminated-string-initialization]

 549 |         static const char zero_uuid[16] = "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0";
     |                                           ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Add the annotation to silence the GCC warning.

---
Cc: Coly Li <[email protected]>
Cc: Kent Overstreet <[email protected]>
Cc: [email protected]
---
drivers/md/bcache/super.c | 2 +-

1 file changed, 1 insertion(+), 1 deletion(-)
drivers/md/bcache/super.c +0 -0
index e42f1400cea9..577d048170fe 100644

drivers/md/bcache/super.c static struct uuid_entry *uuid_find(struct cache_set *c, const char *uuid) · line 550

Quoted 6 lines
drivers/md/bcache/super.c +1 -1
@@ -546,7 +546,7 @@ static struct uuid_entry *uuid_find(struct cache_set *c, const char *uuid)
 
 static struct uuid_entry *uuid_find_empty(struct cache_set *c)
 {
-       static const char zero_uuid[16] = "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0";
+       static const char zero_uuid[] __nonstring = "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0";
 

Just

Quoted 5 lines
Quoted 3 lines

static const char zero_uuid[16] = {};

should work fine here too. No need for the initializer.

🤦 Yes. This is what I get for fixing dozens of these. I'll send a v2...

Can we do this,

static const char zero_uuid[16] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};

I like the explicit array element number 16, and the explicit uuid content by obvious zero (‘0’) symbols. They provide redundant information. Not sure whether GCC 15 complains or not.

Thanks.

Coly Li

#5 lore raw
Quoted 51 lines · Coly Li
Quoted 44 lines

2025年4月17日 15:10,Kees Cook <[email protected]> 写道:

Quoted 36 lines · Ard Biesheuvel
Quoted 26 lines · Kees Cook

GCC 15's new -Wunterminated-string-initialization notices that the 16 character lookup table "zero_uuid" (which is not used as a C-String) needs to be marked as "nonstring":

drivers/md/bcache/super.c: In function 'uuid_find_empty':
drivers/md/bcache/super.c:549:43: warning: initializer-string for array of 'char' truncates NUL terminator but destination lacks 'nonstring' attribute (17 chars into 16 available) [-Wunterminated-string-initialization]

 549 |         static const char zero_uuid[16] = "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0";
     |                                           ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Add the annotation to silence the GCC warning.

---
Cc: Coly Li <[email protected]>
Cc: Kent Overstreet <[email protected]>
Cc: [email protected]
---
drivers/md/bcache/super.c | 2 +-

1 file changed, 1 insertion(+), 1 deletion(-)
drivers/md/bcache/super.c +0 -0
index e42f1400cea9..577d048170fe 100644

drivers/md/bcache/super.c static struct uuid_entry *uuid_find(struct cache_set *c, const char *uuid) · line 550

Quoted 6 lines
drivers/md/bcache/super.c +1 -1
@@ -546,7 +546,7 @@ static struct uuid_entry *uuid_find(struct cache_set *c, const char *uuid)
 
 static struct uuid_entry *uuid_find_empty(struct cache_set *c)
 {
-       static const char zero_uuid[16] = "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0";
+       static const char zero_uuid[] __nonstring = "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0";
 

Just

Quoted 5 lines
Quoted 3 lines

static const char zero_uuid[16] = {};

should work fine here too. No need for the initializer.

🤦 Yes. This is what I get for fixing dozens of these. I'll send a v2...

Quoted 7 lines

Can we do this,

static const char zero_uuid[16] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};

I like the explicit array element number 16, and the explicit uuid content by obvious zero (‘0’) symbols. They provide redundant information. Not sure whether GCC 15 complains or not.

Even the {} initializer is entirely redundant, given that the variable has static linkage, and so C guarantees that it will be zero initialized.

Could you use NULL_GUID and be done with it?

#6 lore raw
Quoted 64 lines

2025年4月17日 22:08,Ard Biesheuvel <[email protected]> 写道:

Quoted 51 lines · Coly Li
Quoted 44 lines

2025年4月17日 15:10,Kees Cook <[email protected]> 写道:

Quoted 36 lines · Ard Biesheuvel
Quoted 26 lines · Kees Cook

GCC 15's new -Wunterminated-string-initialization notices that the 16 character lookup table "zero_uuid" (which is not used as a C-String) needs to be marked as "nonstring":

drivers/md/bcache/super.c: In function 'uuid_find_empty':
drivers/md/bcache/super.c:549:43: warning: initializer-string for array of 'char' truncates NUL terminator but destination lacks 'nonstring' attribute (17 chars into 16 available) [-Wunterminated-string-initialization]

549 |         static const char zero_uuid[16] = "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0";
    |                                           ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Add the annotation to silence the GCC warning.

---
Cc: Coly Li <[email protected]>
Cc: Kent Overstreet <[email protected]>
Cc: [email protected]
---
drivers/md/bcache/super.c | 2 +-

1 file changed, 1 insertion(+), 1 deletion(-)
drivers/md/bcache/super.c +0 -0
index e42f1400cea9..577d048170fe 100644

drivers/md/bcache/super.c static struct uuid_entry *uuid_find(struct cache_set *c, const char *uuid) · line 550

Quoted 6 lines
drivers/md/bcache/super.c +1 -1
@@ -546,7 +546,7 @@ static struct uuid_entry *uuid_find(struct cache_set *c, const char *uuid)
 
 static struct uuid_entry *uuid_find_empty(struct cache_set *c)
 {
-       static const char zero_uuid[16] = "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0";
+       static const char zero_uuid[] __nonstring = "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0";
 

Just

Quoted 5 lines
Quoted 3 lines

static const char zero_uuid[16] = {};

should work fine here too. No need for the initializer.

🤦 Yes. This is what I get for fixing dozens of these. I'll send a v2...

Quoted 7 lines

Can we do this,

static const char zero_uuid[16] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};

I like the explicit array element number 16, and the explicit uuid content by obvious zero (‘0’) symbols. They provide redundant information. Not sure whether GCC 15 complains or not.

Quoted 5 lines

Even the {} initializer is entirely redundant, given that the variable has static linkage, and so C guarantees that it will be zero initialized.

Could you use NULL_GUID and be done with it?

I feel the “static” here is an optimization to avoid initializing zero_uuid again ….

Kent,

Am I right?

Coly Li