Fix type confusion in guc_var_compare()
authorAndres Freund <[email protected]>
Mon, 15 Jul 2024 16:26:03 +0000 (09:26 -0700)
committerAndres Freund <[email protected]>
Mon, 15 Jul 2024 16:26:03 +0000 (09:26 -0700)
Before this change guc_var_compare() cast the input arguments to
const struct config_generic *.  That's not quite right however, as the input
on one side is often just a char * on one side.

Instead just use char *, the first field in config_generic.

This fixes a -Warray-bounds warning with some versions of gcc. While the
warning is only known to be triggered for <= 15, the issue the warning points
out seems real, so apply the fix everywhere.

Author: Nazir Bilal Yavuz <[email protected]>
Reported-by: Erik Rijkers <[email protected]>
Suggested-by: Andres Freund <[email protected]>
Discussion: https://postgr.es/m/a74a1a0d-0fd2-3649-5224-4f754e8f91aa%40xs4all.nl

src/backend/utils/misc/guc.c

index 497fd9319994111ce9b1c32dbe5a78636e25a584..8aaab1c10be0906ccae893617383a39b43b037aa 100644 (file)
@@ -5060,10 +5060,10 @@ find_option(const char *name, bool create_placeholders, int elevel)
 static int
 guc_var_compare(const void *a, const void *b)
 {
-   const struct config_generic *confa = *(struct config_generic *const *) a;
-   const struct config_generic *confb = *(struct config_generic *const *) b;
+   const char *namea = **(const char ** const *) a;
+   const char *nameb = **(const char ** const *) b;
 
-   return guc_name_compare(confa->name, confb->name);
+   return guc_name_compare(namea, nameb);
 }
 
 /*