X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=gio%2Fgicon.c;h=b5080dae28e195c0daa29310e5feff40e155033f;hb=f2786908a8858ec9d063e8fae7e4b2d8d612b682;hp=95d47d4c6d43523dd66ce1a01b0be169dc4056c4;hpb=00f0795a84d23f2e2654a86f8bd3a233c8af3771;p=platform%2Fupstream%2Fglib.git diff --git a/gio/gicon.c b/gio/gicon.c index 95d47d4..b5080da 100644 --- a/gio/gicon.c +++ b/gio/gicon.c @@ -13,9 +13,7 @@ * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General - * Public License along with this library; if not, write to the - * Free Software Foundation, Inc., 59 Temple Place, Suite 330, - * Boston, MA 02111-1307, USA. + * Public License along with this library; if not, see . * * Author: Alexander Larsson */ @@ -195,23 +193,18 @@ g_icon_to_string_tokenized (GIcon *icon, GString *s) * The encoding of the returned string is proprietary to #GIcon except * in the following two cases * - * - * - * If @icon is a #GFileIcon, the returned string is a native path - * (such as /path/to/my icon.png) without escaping - * if the #GFile for @icon is a native file. If the file is not - * native, the returned string is the result of g_file_get_uri() - * (such as sftp://path/to/my%20icon.png). - * - * - * If @icon is a #GThemedIcon with exactly one name, the encoding is - * simply the name (such as network-server). - * - * + * - If @icon is a #GFileIcon, the returned string is a native path + * (such as `/path/to/my icon.png`) without escaping + * if the #GFile for @icon is a native file. If the file is not + * native, the returned string is the result of g_file_get_uri() + * (such as `sftp://path/to/my%20icon.png`). + * + * - If @icon is a #GThemedIcon with exactly one name, the encoding is + * simply the name (such as `network-server`). * * Virtual: to_tokens - * Returns: An allocated NUL-terminated UTF8 string or %NULL if @icon can't - * be serialized. Use g_free() to free. + * Returns: (nullable): An allocated NUL-terminated UTF8 string or + * %NULL if @icon can't be serialized. Use g_free() to free. * * Since: 2.20 */ @@ -284,9 +277,20 @@ g_icon_new_from_tokens (char **tokens, int num_tokens; int i; + icon = NULL; + klass = NULL; + num_tokens = g_strv_length (tokens); - g_return_val_if_fail (num_tokens >= 1, NULL); + if (num_tokens < 1) + { + g_set_error (error, + G_IO_ERROR, + G_IO_ERROR_INVALID_ARGUMENT, + _("Wrong number of tokens (%d)"), + num_tokens); + goto out; + } typename = tokens[0]; version_str = strchr (typename, '.'); @@ -298,23 +302,64 @@ g_icon_new_from_tokens (char **tokens, type = g_type_from_name (tokens[0]); - g_return_val_if_fail (type != 0, NULL); - g_return_val_if_fail (g_type_is_a (type, G_TYPE_ICON), NULL); + if (type == 0) + { + g_set_error (error, + G_IO_ERROR, + G_IO_ERROR_INVALID_ARGUMENT, + _("No type for class name %s"), + tokens[0]); + goto out; + } + + if (!g_type_is_a (type, G_TYPE_ICON)) + { + g_set_error (error, + G_IO_ERROR, + G_IO_ERROR_INVALID_ARGUMENT, + _("Type %s does not implement the GIcon interface"), + tokens[0]); + goto out; + } klass = g_type_class_ref (type); - g_return_val_if_fail (klass, NULL); + if (klass == NULL) + { + g_set_error (error, + G_IO_ERROR, + G_IO_ERROR_INVALID_ARGUMENT, + _("Type %s is not classed"), + tokens[0]); + goto out; + } version = 0; if (version_str) { version = strtol (version_str, &endp, 10); - g_return_val_if_fail (endp && *endp, NULL); + if (endp == NULL || *endp != '\0') + { + g_set_error (error, + G_IO_ERROR, + G_IO_ERROR_INVALID_ARGUMENT, + _("Malformed version number: %s"), + version_str); + goto out; + } } icon_iface = g_type_interface_peek (klass, G_TYPE_ICON); g_assert (icon_iface != NULL); - g_return_val_if_fail (icon_iface->from_tokens, NULL); + if (icon_iface->from_tokens == NULL) + { + g_set_error (error, + G_IO_ERROR, + G_IO_ERROR_INVALID_ARGUMENT, + _("Type %s does not implement from_tokens() on the GIcon interface"), + tokens[0]); + goto out; + } for (i = 1; i < num_tokens; i++) { @@ -327,7 +372,9 @@ g_icon_new_from_tokens (char **tokens, icon = icon_iface->from_tokens (tokens + 1, num_tokens - 1, version, error); - g_type_class_unref (klass); + out: + if (klass != NULL) + g_type_class_unref (klass); return icon; } @@ -411,7 +458,7 @@ g_icon_new_for_string (const gchar *str, g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_INVALID_ARGUMENT, - "Can't handle the supplied version of the icon encoding"); + _("Can't handle the supplied version of the icon encoding")); return icon; }