]> Pileus Git - ~andy/gtk/blobdiff - gdk-pixbuf/io-xpm.c
[quartz] Delete the typedef of GdkDevicePrivate
[~andy/gtk] / gdk-pixbuf / io-xpm.c
index 750307005de3b58821d904f7cf545b3795833004..b8a02d84cc4e02261bff97dd974376bbd89f04b5 100644 (file)
@@ -23,7 +23,7 @@
  * Boston, MA 02111-1307, USA.
  */
 
-#include <config.h>
+#include "config.h"
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
@@ -405,7 +405,8 @@ file_buffer (enum buf_op op, gpointer handle)
                /* Fall through to the xpm_read_string. */
 
        case op_body:
-               xpm_read_string (h->infile, &h->buffer, &h->buffer_size);
+               if(!xpm_read_string (h->infile, &h->buffer, &h->buffer_size))
+                       return NULL;
                return h->buffer;
 
        default:
@@ -461,50 +462,52 @@ pixbuf_create_from_xpm (const gchar * (*get_buf) (enum buf_op op, gpointer handl
 
        buffer = (*get_buf) (op_header, handle);
        if (!buffer) {
-                g_set_error (error,
-                             GDK_PIXBUF_ERROR,
-                             GDK_PIXBUF_ERROR_CORRUPT_IMAGE,
-                             _("No XPM header found"));
+                g_set_error_literal (error,
+                                     GDK_PIXBUF_ERROR,
+                                     GDK_PIXBUF_ERROR_CORRUPT_IMAGE,
+                                     _("No XPM header found"));
                return NULL;
        }
        items = sscanf (buffer, "%d %d %d %d %d %d", &w, &h, &n_col, &cpp, &x_hot, &y_hot);
 
        if (items != 4 && items != 6) {
-               g_set_error (error,
-                             GDK_PIXBUF_ERROR,
-                             GDK_PIXBUF_ERROR_CORRUPT_IMAGE,
-                             _("Invalid XPM header"));
+               g_set_error_literal (error,
+                                     GDK_PIXBUF_ERROR,
+                                     GDK_PIXBUF_ERROR_CORRUPT_IMAGE,
+                                     _("Invalid XPM header"));
                return NULL;
        }
 
        if (w <= 0) {
-                g_set_error (error,
-                             GDK_PIXBUF_ERROR,
-                             GDK_PIXBUF_ERROR_CORRUPT_IMAGE,
-                             _("XPM file has image width <= 0"));
+                g_set_error_literal (error,
+                                     GDK_PIXBUF_ERROR,
+                                     GDK_PIXBUF_ERROR_CORRUPT_IMAGE,
+                                     _("XPM file has image width <= 0"));
                return NULL;
 
        }
        if (h <= 0) {
-                g_set_error (error,
-                             GDK_PIXBUF_ERROR,
-                             GDK_PIXBUF_ERROR_CORRUPT_IMAGE,
-                             _("XPM file has image height <= 0"));
+                g_set_error_literal (error,
+                                     GDK_PIXBUF_ERROR,
+                                     GDK_PIXBUF_ERROR_CORRUPT_IMAGE,
+                                     _("XPM file has image height <= 0"));
                return NULL;
 
        }
        if (cpp <= 0 || cpp >= 32) {
-                g_set_error (error,
-                             GDK_PIXBUF_ERROR,
-                             GDK_PIXBUF_ERROR_CORRUPT_IMAGE,
-                             _("XPM has invalid number of chars per pixel"));
+                g_set_error_literal (error,
+                                     GDK_PIXBUF_ERROR,
+                                     GDK_PIXBUF_ERROR_CORRUPT_IMAGE,
+                                     _("XPM has invalid number of chars per pixel"));
                return NULL;
        }
-       if (n_col <= 0 || n_col >= G_MAXINT / (cpp + 1)) {
-                g_set_error (error,
-                             GDK_PIXBUF_ERROR,
-                             GDK_PIXBUF_ERROR_CORRUPT_IMAGE,
-                             _("XPM file has invalid number of colors"));
+       if (n_col <= 0 || 
+           n_col >= G_MAXINT / (cpp + 1) || 
+           n_col >= G_MAXINT / sizeof (XPMColor)) {
+                g_set_error_literal (error,
+                                     GDK_PIXBUF_ERROR,
+                                     GDK_PIXBUF_ERROR_CORRUPT_IMAGE,
+                                     _("XPM file has invalid number of colors"));
                return NULL;
        }
 
@@ -513,19 +516,19 @@ pixbuf_create_from_xpm (const gchar * (*get_buf) (enum buf_op op, gpointer handl
 
        name_buf = g_try_malloc (n_col * (cpp + 1));
        if (!name_buf) {
-               g_set_error (error,
-                            GDK_PIXBUF_ERROR,
-                             GDK_PIXBUF_ERROR_INSUFFICIENT_MEMORY,
-                             _("Cannot allocate memory for loading XPM image"));
+               g_set_error_literal (error,
+                                     GDK_PIXBUF_ERROR,
+                                     GDK_PIXBUF_ERROR_INSUFFICIENT_MEMORY,
+                                     _("Cannot allocate memory for loading XPM image"));
                g_hash_table_destroy (color_hash);
                return NULL;
        }
        colors = (XPMColor *) g_try_malloc (sizeof (XPMColor) * n_col);
        if (!colors) {
-               g_set_error (error,
-                            GDK_PIXBUF_ERROR,
-                             GDK_PIXBUF_ERROR_INSUFFICIENT_MEMORY,
-                             _("Cannot allocate memory for loading XPM image"));
+               g_set_error_literal (error,
+                                     GDK_PIXBUF_ERROR,
+                                     GDK_PIXBUF_ERROR_INSUFFICIENT_MEMORY,
+                                     _("Cannot allocate memory for loading XPM image"));
                g_hash_table_destroy (color_hash);
                g_free (name_buf);
                return NULL;
@@ -536,10 +539,10 @@ pixbuf_create_from_xpm (const gchar * (*get_buf) (enum buf_op op, gpointer handl
 
                buffer = (*get_buf) (op_cmap, handle);
                if (!buffer) {
-                        g_set_error (error,
-                                     GDK_PIXBUF_ERROR,
-                                     GDK_PIXBUF_ERROR_CORRUPT_IMAGE,
-                                     _("Cannot read XPM colormap"));
+                        g_set_error_literal (error,
+                                             GDK_PIXBUF_ERROR,
+                                             GDK_PIXBUF_ERROR_CORRUPT_IMAGE,
+                                             _("Cannot read XPM colormap"));
                        g_hash_table_destroy (color_hash);
                        g_free (name_buf);
                        g_free (colors);
@@ -574,10 +577,10 @@ pixbuf_create_from_xpm (const gchar * (*get_buf) (enum buf_op op, gpointer handl
        pixbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB, is_trans, 8, w, h);
 
        if (!pixbuf) {
-                g_set_error (error,
-                             GDK_PIXBUF_ERROR,
-                             GDK_PIXBUF_ERROR_INSUFFICIENT_MEMORY,
-                             _("Cannot allocate memory for loading XPM image"));
+                g_set_error_literal (error,
+                                     GDK_PIXBUF_ERROR,
+                                     GDK_PIXBUF_ERROR_INSUFFICIENT_MEMORY,
+                                     _("Cannot allocate memory for loading XPM image"));
                g_hash_table_destroy (color_hash);
                g_free (colors);
                g_free (name_buf);
@@ -593,7 +596,7 @@ pixbuf_create_from_xpm (const gchar * (*get_buf) (enum buf_op op, gpointer handl
                if ((!buffer) || (strlen (buffer) < wbytes))
                        continue;
 
-               for (n = 0, cnt = 0, xcnt = 0; n < wbytes; n += cpp, xcnt++) {
+               for (n = 0, xcnt = 0; n < wbytes; n += cpp, xcnt++) {
                        strncpy (pixel_str, &buffer[n], cpp);
                        pixel_str[cpp] = 0;
 
@@ -735,10 +738,12 @@ gdk_pixbuf__xpm_image_stop_load (gpointer data,
                pixbuf = gdk_pixbuf__xpm_image_load (context->file, error);
 
                if (pixbuf != NULL) {
-                       (* context->prepare_func) (pixbuf,
-                                                  NULL,
-                                                  context->user_data);
-                       (* context->update_func) (pixbuf, 0, 0, pixbuf->width, pixbuf->height, context->user_data);
+                      if (context->prepare_func)
+                              (* context->prepare_func) (pixbuf,
+                                                         NULL,
+                                                         context->user_data);
+                      if (context->update_func)
+                              (* context->update_func) (pixbuf, 0, 0, pixbuf->width, pixbuf->height, context->user_data);
                        g_object_unref (pixbuf);
 
                        retval = TRUE;
@@ -764,19 +769,25 @@ gdk_pixbuf__xpm_image_load_increment (gpointer data,
        g_return_val_if_fail (data != NULL, FALSE);
 
        if (fwrite (buf, sizeof (guchar), size, context->file) != size) {
+              gint save_errno = errno;
                context->all_okay = FALSE;
-               g_set_error (error,
-                            G_FILE_ERROR,
-                            g_file_error_from_errno (errno),
-                            _("Failed to write to temporary file when loading XPM image"));
+               g_set_error_literal (error,
+                                    G_FILE_ERROR,
+                                    g_file_error_from_errno (save_errno),
+                                    _("Failed to write to temporary file when loading XPM image"));
                return FALSE;
        }
 
        return TRUE;
 }
 
-void
-MODULE_ENTRY (xpm, fill_vtable) (GdkPixbufModule *module)
+#ifndef INCLUDE_xpm
+#define MODULE_ENTRY(function) G_MODULE_EXPORT void function
+#else
+#define MODULE_ENTRY(function) void _gdk_pixbuf__xpm_ ## function
+#endif
+
+MODULE_ENTRY (fill_vtable) (GdkPixbufModule *module)
 {
        module->load = gdk_pixbuf__xpm_image_load;
        module->load_xpm_data = gdk_pixbuf__xpm_image_load_xpm_data;
@@ -785,8 +796,7 @@ MODULE_ENTRY (xpm, fill_vtable) (GdkPixbufModule *module)
        module->load_increment = gdk_pixbuf__xpm_image_load_increment;
 }
 
-void
-MODULE_ENTRY (xpm, fill_info) (GdkPixbufFormat *info)
+MODULE_ENTRY (fill_info) (GdkPixbufFormat *info)
 {
        static GdkPixbufModulePattern signature[] = {
                { "/* XPM */", NULL, 100 },