Skip to content

Commit

Permalink
Fix code reviews
Browse files Browse the repository at this point in the history
  • Loading branch information
fujiwarat committed Jun 16, 2021
1 parent d105a39 commit e9e1642
Show file tree
Hide file tree
Showing 29 changed files with 524 additions and 172 deletions.
23 changes: 18 additions & 5 deletions bus/ibusimpl.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
/* vim:set et sts=4: */
/* ibus - The Input Bus
* Copyright (C) 2008-2013 Peng Huang <shawn.p.huang@gmail.com>
* Copyright (C) 2011-2020 Takao Fujiwara <takao.fujiwara1@gmail.com>
* Copyright (C) 2008-2020 Red Hat, Inc.
* Copyright (C) 2011-2021 Takao Fujiwara <takao.fujiwara1@gmail.com>
* Copyright (C) 2008-2021 Red Hat, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
Expand Down Expand Up @@ -624,7 +624,6 @@ bus_ibus_impl_destroy (BusIBusImpl *ibus)

g_list_foreach (ibus->components, (GFunc) bus_component_stop, NULL);

pid = 0;
timeout = 0;
flag = FALSE;
while (1) {
Expand Down Expand Up @@ -1190,6 +1189,7 @@ _ibus_get_current_input_context (BusIBusImpl *ibus,
GDBusConnection *connection,
GError **error)
{
GVariant *retval = NULL;
if (error) {
*error = NULL;
}
Expand All @@ -1204,8 +1204,14 @@ _ibus_get_current_input_context (BusIBusImpl *ibus,
const gchar *path = ibus_service_get_object_path (
(IBusService *) ibus->focused_context);
/* the format-string 'o' is for a D-Bus object path. */
return g_variant_new_object_path (path);
retval = g_variant_new_object_path (path);
if (!retval) {
g_set_error (error, G_DBUS_ERROR, G_DBUS_ERROR_FAILED,
"Could not get object path from %s",
path ? path : "(null)");
}
}
return retval;
}

static void
Expand Down Expand Up @@ -1572,6 +1578,7 @@ _ibus_get_global_engine (BusIBusImpl *ibus,
GError **error)
{
IBusEngineDesc *desc = NULL;
GVariant *retval = NULL;

if (error) {
*error = NULL;
Expand All @@ -1592,7 +1599,13 @@ _ibus_get_global_engine (BusIBusImpl *ibus,
GVariant *variant = ibus_serializable_serialize (
(IBusSerializable *) desc);
// Set type "v" for introspection_xml.
return g_variant_new_variant (variant);
retval = g_variant_new_variant (variant);
if (!retval) {
g_set_error (error,
G_DBUS_ERROR, G_DBUS_ERROR_FAILED,
"Failed to serialize engine desc.");
}
return retval;
} while (0);

g_set_error (error,
Expand Down
10 changes: 5 additions & 5 deletions bus/server.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
/* vim:set et sts=4: */
/* bus - The Input Bus
* Copyright (C) 2008-2010 Peng Huang <shawn.p.huang@gmail.com>
* Copyright (C) 2011-2019 Takao Fujiwara <takao.fujiwara1@gmail.com>
* Copyright (C) 2008-2019 Red Hat, Inc.
* Copyright (C) 2011-2021 Takao Fujiwara <takao.fujiwara1@gmail.com>
* Copyright (C) 2008-2021 Red Hat, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
Expand All @@ -22,12 +22,11 @@
*/
#include "server.h"

#include <errno.h>
#include <glib/gstdio.h>
#include <gio/gio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <errno.h>
#include <fcntl.h>
#include <stdlib.h>
#include <string.h>

#include "dbusimpl.h"
Expand Down Expand Up @@ -282,6 +281,7 @@ bus_server_init (void)
* `chmod` runs for the last directory only not to change the modes
* of the parent directories. E.g. "/tmp/ibus".
*/
errno = 0;
if (g_mkdir_with_parents (unix_dir, 0700) != 0) {
g_error ("mkdir is failed in: %s: %s",
unix_dir, g_strerror (errno));
Expand Down
8 changes: 8 additions & 0 deletions client/gtk2/ibusimcontext.c
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,9 @@ _process_key_event_done (GObject *object,

ProcessKeyEventData *data = (ProcessKeyEventData *)user_data;
GdkEvent *event = data->event;
#if GTK_CHECK_VERSION (3, 98, 4)
IBusIMContext *ibusimcontext = data->ibusimcontext;
#endif
GError *error = NULL;

g_slice_free (ProcessKeyEventData, data);
Expand Down Expand Up @@ -1634,6 +1636,7 @@ get_selection_anchor_point (IBusIMContext *ibusimcontext,
return anchor;
}

#if !GTK_CHECK_VERSION (4, 1, 2)
static void
ibus_im_context_set_surrounding (GtkIMContext *context,
const gchar *text,
Expand All @@ -1646,6 +1649,7 @@ ibus_im_context_set_surrounding (GtkIMContext *context,
cursor_index,
cursor_index);
}
#endif

static void
ibus_im_context_set_surrounding_with_selection (GtkIMContext *context,
Expand Down Expand Up @@ -1851,7 +1855,11 @@ _create_gdk_event (IBusIMContext *ibusimcontext,
if (event->state & GDK_CONTROL_MASK) {
if ((c >= '@' && c < '\177') || c == ' ') c &= 0x1F;
else if (c == '2') {
#if GLIB_CHECK_VERSION (2, 68, 0)
event->string = g_memdup2 ("\0\0", 2);
#else
event->string = g_memdup ("\0\0", 2);
#endif
event->length = 1;
buf[0] = '\0';
goto out;
Expand Down
9 changes: 6 additions & 3 deletions client/wayland/main.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* -*- mode: C; c-basic-offset: 4; indent-tabs-mode: nil; -*- */
/* vim:set et sts=4: */
/* ibus - The Input Bus
* Copyright (C) 2019 Takao Fujiwara <takao.fujiwara1@gmail.com>
* Copyright (C) 2019-2021 Takao Fujiwara <takao.fujiwara1@gmail.com>
* Copyright (C) 2013 Intel Corporation
* Copyright (C) 2013-2019 Red Hat, Inc.
*
Expand Down Expand Up @@ -339,16 +339,19 @@ input_method_keyboard_keymap (void *data,
{
IBusWaylandIM *wlim = data;
GMappedFile *map;
GError *error;
GError *error = NULL;

if (format != WL_KEYBOARD_KEYMAP_FORMAT_XKB_V1) {
close(fd);
return;
}

error = NULL;
map = g_mapped_file_new_from_fd (fd, FALSE, &error);
if (map == NULL) {
if (error) {
g_warning ("Failed to map file fd %s", error->message);
g_error_free (error);
}
close (fd);
return;
}
Expand Down
22 changes: 17 additions & 5 deletions client/x11/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/* vim:set et sts=4: */
/* ibus
* Copyright (C) 2007-2015 Peng Huang <shawn.p.huang@gmail.com>
* Copyright (C) 2015-2019 Takao Fujiwara <takao.fujiwara1@gmail.com>
* Copyright (C) 2015-2021 Takao Fujiwara <takao.fujiwara1@gmail.com>
* Copyright (C) 2007-2015 Red Hat, Inc.
*
* main.c:
Expand Down Expand Up @@ -229,12 +229,13 @@ _xim_preedit_callback_draw (XIMS xims, X11IC *x11ic, const gchar *preedit_string
}
}

for (i = 0; i < len; i++) {
for (i = 0; feedback && i < len; i++) {
if (feedback[i] == 0) {
feedback[i] = XIMUnderline;
}
}
feedback[len] = 0;
if (feedback)
feedback[len] = 0;

pcb.major_code = XIM_PREEDIT_DRAW;
pcb.connect_id = x11ic->connect_id;
Expand Down Expand Up @@ -736,9 +737,20 @@ xim_get_ic_values (XIMS xims, IMChangeICStruct *call_data)

for (i = 0; i < (int) call_data->ic_attr_num; ++i, ++ic_attr) {
if (g_strcmp0 (XNFilterEvents, ic_attr->name) == 0) {
/* ic_attr->value will be freed in server side and ignore
* leak of malloc with -Wanalyzer-malloc-leak flags in gcc 11.0.1
*/
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wanalyzer-malloc-leak"
ic_attr->value = (void *) malloc (sizeof (CARD32));
*(CARD32 *) ic_attr->value = KeyPressMask | KeyReleaseMask;
ic_attr->value_length = sizeof (CARD32);
if (ic_attr->value) {
*(CARD32 *) ic_attr->value = KeyPressMask | KeyReleaseMask;
ic_attr->value_length = sizeof (CARD32);
} else {
g_warning ("Failed to malloc");
ic_attr->value_length = 0;
}
#pragma GCC diagnostic pop
}
}

Expand Down
7 changes: 5 additions & 2 deletions conf/dconf/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
/* vim:set et sts=4: */
/* ibus - The Input Bus
* Copyright (C) 2008-2010 Peng Huang <shawn.p.huang@gmail.com>
* Copyright (C) 2008-2010 Red Hat, Inc.
* Copyright (C) 2012-2021 Takao Fujiwara <takao.fujiwara1@gmail.com>
* Copyright (C) 2008-2021 Red Hat, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
Expand Down Expand Up @@ -70,7 +71,9 @@ main (gint argc, gchar **argv)
GOptionContext *context;

setlocale (LC_ALL, "");
g_setenv ("DCONF_PROFILE", "ibus", FALSE);
errno = 0;
if (!g_setenv ("DCONF_PROFILE", "ibus", FALSE))
g_warning ("Failed setenv %s", strerror (errno));

context = g_option_context_new ("- ibus dconf component");

Expand Down
7 changes: 4 additions & 3 deletions portal/portal.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* -*- mode: C; c-basic-offset: 4; indent-tabs-mode: nil; -*- */
/* vim:set et sts=4: */
/* ibus - The Input Bus
* Copyright (C) 2017-2019 Red Hat, Inc.
* Copyright (C) 2017-2021 Red Hat, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
Expand Down Expand Up @@ -508,7 +508,6 @@ create_input_context_done (IBusBus *bus,
if (portal_context == NULL) {
g_dbus_method_invocation_return_gerror (invocation, error);
g_error_free (error);
g_object_unref (portal_context);
return;
}

Expand Down Expand Up @@ -656,8 +655,10 @@ main (gint argc, gchar **argv)
exit (-1);
}

errno = 0;
/* Avoid even loading gvfs to avoid accidental confusion */
g_setenv ("GIO_USE_VFS", "local", TRUE);
if (!g_setenv ("GIO_USE_VFS", "local", TRUE))
g_warning ("Failed setenv %s", strerror (errno));

ibus_init ();

Expand Down
2 changes: 1 addition & 1 deletion setup/ibus-setup.in
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,5 @@ export IBUS_PREFIX=@prefix@
export IBUS_DATAROOTDIR=@datarootdir@
export IBUS_LOCALEDIR=@localedir@
export IBUS_LIBEXECDIR=${libexecdir}
exec ${PYTHON:-@PYTHON@} @prefix@/share/ibus/setup/main.py $@
exec ${PYTHON:-@PYTHON@} @prefix@/share/ibus/setup/main.py "$@"

46 changes: 25 additions & 21 deletions src/emoji-parser.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* -*- mode: C; c-basic-offset: 4; indent-tabs-mode: nil; -*- */
/* vim:set et sts=4: */
/* ibus - The Input Bus
* Copyright (C) 2016-2020 Takao Fujiwara <takao.fujiwara1@gmail.com>
* Copyright (C) 2016-2021 Takao Fujiwara <takao.fujiwara1@gmail.com>
* Copyright (C) 2016 Red Hat, Inc.
*
* This library is free software; you can redistribute it and/or
Expand Down Expand Up @@ -291,11 +291,9 @@ emoji_data_new_object (EmojiData *data)
"annotations",
data->annotations,
"description",
data->description ? data->description
: g_strdup (""),
data->description ? data->description : "",
"category",
data->category ? data->category
: g_strdup (""),
data->category ? data->category : "",
NULL);
data->list = g_slist_append (data->list, emoji);
}
Expand Down Expand Up @@ -608,7 +606,7 @@ unicode_emoji_test_parse_line (const gchar *line,
return FALSE;
}
unicode_emoji_test_parse_description (segments[1], data);
g_strfreev (segments);
g_clear_pointer (&segments, g_strfreev);
if (data->annotations == NULL) {
if (data->subcategory) {
int i;
Expand All @@ -631,7 +629,7 @@ unicode_emoji_test_parse_line (const gchar *line,
data->annotations = g_slist_append (data->annotations,
g_strdup (segments[i]));
}
g_strfreev (segments);
g_clear_pointer (&segments, g_strfreev);
} else {
g_warning ("No subcategory line\n");
goto failed_to_parse_unicode_emoji_test_line;
Expand Down Expand Up @@ -672,7 +670,7 @@ unicode_emoji_test_parse_file (const gchar *filename,
filename, error ? error->message : "");
goto failed_to_parse_unicode_emoji_test;
}
head = end = content;
end = content;
while (*end == '\n' && end - content < length) {
end++;
n++;
Expand Down Expand Up @@ -1100,10 +1098,12 @@ static void
category_list_dump (const gchar *category,
GString *buff)
{
gchar *line;
g_return_if_fail (buff != NULL);

const gchar *line = g_strdup_printf (" N_(\"%s\"),\n", category);
line = g_strdup_printf (" N_(\"%s\"),\n", category);
g_string_append (buff, line);
g_free (line);
}

static void
Expand All @@ -1113,7 +1113,7 @@ category_file_save (const gchar *filename,
gchar *content = NULL;
gsize length = 0;
GError *error = NULL;
gchar *p;
gchar *p, *substr;
GString *buff = NULL;
int i;
GSList *list_categories = NULL;
Expand All @@ -1139,24 +1139,28 @@ category_file_save (const gchar *filename,
break;
}
if (p != NULL) {
g_string_append (buff, g_strndup (content, p - content));
substr = g_strndup (content, p - content);
g_string_append (buff, substr);
g_free (substr);
g_string_append_c (buff, '\n');
}
g_clear_pointer (&content, g_free);

g_string_append (buff, g_strdup ("\n"));
g_string_append (buff, g_strdup_printf ("/* This file is generated by %s. */", __FILE__));
g_string_append (buff, g_strdup ("\n"));
g_string_append (buff, g_strdup ("include <glib/gi18n.h>\n"));
g_string_append (buff, g_strdup ("\n"));
g_string_append (buff, g_strdup ("#ifndef __IBUS_EMOJI_GEN_H_\n"));
g_string_append (buff, g_strdup ("#define __IBUS_EMOJI_GEN_H_\n"));
g_string_append (buff, g_strdup ("const static char *unicode_emoji_categories[] = {\n"));
g_string_append (buff, "\n");
substr = g_strdup_printf ("/* This file is generated by %s. */", __FILE__);
g_string_append (buff, substr);
g_free (substr);
g_string_append (buff, "\n");
g_string_append (buff, "include <glib/gi18n.h>\n");
g_string_append (buff, "\n");
g_string_append (buff, "#ifndef __IBUS_EMOJI_GEN_H_\n");
g_string_append (buff, "#define __IBUS_EMOJI_GEN_H_\n");
g_string_append (buff, "const static char *unicode_emoji_categories[] = {\n");
list_categories = g_slist_sort (list_categories, (GCompareFunc)g_strcmp0);
g_slist_foreach (list_categories, (GFunc)category_list_dump, buff);
g_slist_free (list_categories);
g_string_append (buff, g_strdup ("};\n"));
g_string_append (buff, g_strdup ("#endif\n"));
g_string_append (buff, "};\n");
g_string_append (buff, "#endif\n");

if (!g_file_set_contents (filename, buff->str, -1, &error)) {
g_warning ("Failed to save emoji category file %s: %s", filename, error->message);
Expand Down
2 changes: 1 addition & 1 deletion src/ibusaccelgroup.c
Original file line number Diff line number Diff line change
Expand Up @@ -468,7 +468,7 @@ ibus_accelerator_name (guint accelerator_key,
if (accelerator_mods & IBUS_SUPER_MASK)
l += sizeof (text_super) - 1;

accelerator = g_new (gchar, l + 1);
g_return_val_if_fail ((accelerator = g_new (gchar, l + 1)), NULL);

accelerator_mods = saved_mods;
l = 0;
Expand Down
Loading

0 comments on commit e9e1642

Please sign in to comment.