[PATCH 2/7] qom: Use g_ascii_strcasecmp instead of strcasecmp

Kostiantyn Kostiuk posted 7 patches 1 week ago
Maintainers: Paolo Bonzini <pbonzini@redhat.com>, "Marc-André Lureau" <marcandre.lureau@redhat.com>, "Daniel P. Berrangé" <berrange@redhat.com>, "Philippe Mathieu-Daudé" <philmd@linaro.org>, Kevin Wolf <kwolf@redhat.com>
There is a newer version of this series
[PATCH 2/7] qom: Use g_ascii_strcasecmp instead of strcasecmp
Posted by Kostiantyn Kostiuk 1 week ago
Signed-off-by: Kostiantyn Kostiuk <kkostiuk@redhat.com>
---
 qom/object.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/qom/object.c b/qom/object.c
index ff8ede8a32..e5c0c2f53e 100644
--- a/qom/object.c
+++ b/qom/object.c
@@ -1193,8 +1193,8 @@ GSList *object_class_get_list(const char *implements_type,
 
 static gint object_class_cmp(gconstpointer a, gconstpointer b, gpointer d)
 {
-    return strcasecmp(object_class_get_name((ObjectClass *)a),
-                      object_class_get_name((ObjectClass *)b));
+    return g_ascii_strcasecmp(object_class_get_name((ObjectClass *)a),
+                              object_class_get_name((ObjectClass *)b));
 }
 
 GSList *object_class_get_list_sorted(const char *implements_type,
-- 
2.52.0
Re: [PATCH 2/7] qom: Use g_ascii_strcasecmp instead of strcasecmp
Posted by Peter Maydell 1 week ago
On Thu, 26 Mar 2026 at 16:02, Kostiantyn Kostiuk <kkostiuk@redhat.com> wrote:
>
> Signed-off-by: Kostiantyn Kostiuk <kkostiuk@redhat.com>
> ---
>  qom/object.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/qom/object.c b/qom/object.c
> index ff8ede8a32..e5c0c2f53e 100644
> --- a/qom/object.c
> +++ b/qom/object.c
> @@ -1193,8 +1193,8 @@ GSList *object_class_get_list(const char *implements_type,
>
>  static gint object_class_cmp(gconstpointer a, gconstpointer b, gpointer d)
>  {
> -    return strcasecmp(object_class_get_name((ObjectClass *)a),
> -                      object_class_get_name((ObjectClass *)b));
> +    return g_ascii_strcasecmp(object_class_get_name((ObjectClass *)a),
> +                              object_class_get_name((ObjectClass *)b));
>  }

The commit message should note that this is a change in semantics
(g_ascii_strcasecmp() doesn't honour locale but strcasecmp() does)
but that this is OK for two reasons:
 (1) we want the comparison on class names to be a plain ASCII
     one, not to do weird things with "I" in Turkish locales,
     so g_ascii_strcasecmp() is better as it's explicit about that
 (2) QEMU always runs with the C locale so there's not an actual
     behaviour change here

(I forgot about point (2) in my email on the other branch of
this thread -- apologies for the confusion.)

Reviewed-by: Peter Maydell <peter.maydell@linaro.org>

-- PMM