app/xcf/xcf-write.[ch] app/xcf/xcf-save.c ported the fix for bug #101340

2002-12-20  Nathan Summers  <rock@gimp.org>

        * app/xcf/xcf-write.[ch]
        * app/xcf/xcf-save.c
        * app/xcf/xcf.c: ported the fix for bug #101340 over from the stable
        branch.  Uses GError to report errors, unlike the stable version, which
        uses a pointer to gboolean.

        * app/xcf/xcf-seek.[ch]: check the return value of fseek and ftell for
        errors.  Return FALSE and set GError if an error is detected.

        * app/xcf/xcf-load.c: since the xcf-seek functions use GError now,
        added a NULL for the error parameter.  Added basic error checking
        on the return value of the xcf-seek functions.  In the future,
        changing xcf-load.c to use GError more completely should be
        considered.

        * POTFILES.in: mark the error messages added for translation
This commit is contained in:
Nathan Summers 2002-12-20 06:26:34 +00:00 committed by Nate Summers
parent 449d4913fa
commit 8127ee74aa
9 changed files with 622 additions and 311 deletions

View File

@ -1,3 +1,22 @@
2002-12-20 Nathan Summers <rock@gimp.org>
* app/xcf/xcf-write.[ch]
* app/xcf/xcf-save.c
* app/xcf/xcf.c: ported the fix for bug #101340 over from the stable
branch. Uses GError to report errors, unlike the stable version, which
uses a pointer to gboolean.
* app/xcf/xcf-seek.[ch]: check the return value of fseek and ftell for
errors. Return FALSE and set GError if an error is detected.
* app/xcf/xcf-load.c: since the xcf-seek functions use GError now,
added a NULL for the error parameter. Added basic error checking
on the return value of the xcf-seek functions. In the future,
changing xcf-load.c to use GError more completely should be
considered.
* po/POTFILES.in: mark the error messages added for translation
2002-12-19 Maurits Rijk <lpeek.mrijk@consunet.nl>
* plug-ins/common/grid.c: replace preview code by calls to libgimp

View File

@ -283,7 +283,8 @@ xcf_load_image (Gimp *gimp,
saved_pos = info->cp;
/* seek to the layer offset */
xcf_seek_pos (info, offset);
if (! xcf_seek_pos (info, offset, NULL))
goto error;
/* read in the layer */
layer = xcf_load_layer (info, gimage);
@ -300,7 +301,8 @@ xcf_load_image (Gimp *gimp,
/* restore the saved position so we'll be ready to
* read the next offset.
*/
xcf_seek_pos (info, saved_pos);
if (! xcf_seek_pos (info, saved_pos, NULL))
goto error;
}
while (TRUE)
@ -320,7 +322,8 @@ xcf_load_image (Gimp *gimp,
saved_pos = info->cp;
/* seek to the channel offset */
xcf_seek_pos (info, offset);
if (! xcf_seek_pos (info, offset, NULL))
goto error;
/* read in the layer */
channel = xcf_load_channel (info, gimage);
@ -336,7 +339,8 @@ xcf_load_image (Gimp *gimp,
/* restore the saved position so we'll be ready to
* read the next offset.
*/
xcf_seek_pos (info, saved_pos);
if (! xcf_seek_pos (info, saved_pos, NULL))
goto error;
}
if (info->active_layer)
@ -395,7 +399,9 @@ xcf_load_image_props (XcfInfo *info,
info->cp +=
xcf_read_int32 (info->fp, (guint32*) &gimage->num_cols, 1);
gimage->cmap = g_new (guchar, gimage->num_cols*3);
xcf_seek_pos (info, info->cp + gimage->num_cols);
if (!xcf_seek_pos (info, info->cp + gimage->num_cols, NULL))
return FALSE;
for (i = 0; i<gimage->num_cols; i++)
{
gimage->cmap[i*3+0] = i;
@ -886,14 +892,17 @@ xcf_load_layer (XcfInfo *info,
info->cp += xcf_read_int32 (info->fp, &layer_mask_offset, 1);
/* read in the hierarchy */
xcf_seek_pos (info, hierarchy_offset);
if (!xcf_seek_pos (info, hierarchy_offset, NULL))
goto error;
if (!xcf_load_hierarchy (info, GIMP_DRAWABLE(layer)->tiles))
goto error;
/* read in the layer mask */
if (layer_mask_offset != 0)
{
xcf_seek_pos (info, layer_mask_offset);
if (! xcf_seek_pos (info, layer_mask_offset, NULL))
goto error;
layer_mask = xcf_load_layer_mask (info, gimage);
if (!layer_mask)
@ -964,7 +973,9 @@ xcf_load_channel (XcfInfo *info,
info->cp += xcf_read_int32 (info->fp, &hierarchy_offset, 1);
/* read in the hierarchy */
xcf_seek_pos (info, hierarchy_offset);
if (!xcf_seek_pos (info, hierarchy_offset, NULL))
goto error;
if (!xcf_load_hierarchy (info, GIMP_DRAWABLE (channel)->tiles))
goto error;
@ -1021,7 +1032,9 @@ xcf_load_layer_mask (XcfInfo *info,
info->cp += xcf_read_int32 (info->fp, &hierarchy_offset, 1);
/* read in the hierarchy */
xcf_seek_pos (info, hierarchy_offset);
if (! xcf_seek_pos (info, hierarchy_offset, NULL))
goto error;
if (!xcf_load_hierarchy (info, GIMP_DRAWABLE (layer_mask)->tiles))
goto error;
@ -1085,7 +1098,8 @@ xcf_load_hierarchy (XcfInfo *info,
saved_pos = info->cp;
/* seek to the level offset */
xcf_seek_pos (info, offset);
if (!xcf_seek_pos (info, offset, NULL))
return FALSE;
/* read in the level */
if (!xcf_load_level (info, tiles))
@ -1094,7 +1108,8 @@ xcf_load_hierarchy (XcfInfo *info,
/* restore the saved position so we'll be ready to
* read the next offset.
*/
xcf_seek_pos (info, saved_pos);
if (!xcf_seek_pos (info, saved_pos, NULL))
return FALSE;
return TRUE;
}
@ -1161,7 +1176,8 @@ xcf_load_level (XcfInfo *info,
than we need to allow */
/* seek to the tile offset */
xcf_seek_pos (info, offset);
if (! xcf_seek_pos (info, offset, NULL))
return FALSE;
/* get the tile from the tile manager */
tile = tile_manager_get (tiles, i, TRUE, TRUE);
@ -1216,7 +1232,8 @@ xcf_load_level (XcfInfo *info,
/* restore the saved position so we'll be ready to
* read the next offset.
*/
xcf_seek_pos (info, saved_pos);
if (!xcf_seek_pos (info, saved_pos, NULL))
return FALSE;
/* read in the offset of the next tile */
info->cp += xcf_read_int32 (info->fp, &offset, 1);

File diff suppressed because it is too large Load Diff

View File

@ -19,6 +19,7 @@
#include "config.h"
#include <stdio.h>
#include <errno.h>
#include <glib-object.h>
@ -27,21 +28,52 @@
#include "xcf-private.h"
#include "xcf-seek.h"
#include "libgimp/gimpintl.h"
void
gboolean
xcf_seek_pos (XcfInfo *info,
guint pos)
guint pos,
GError **error)
{
if (info->cp != pos)
{
info->cp = pos;
fseek (info->fp, info->cp, SEEK_SET);
if (fseek (info->fp, info->cp, SEEK_SET) == -1)
{
g_set_error (error, G_FILE_ERROR, g_file_error_from_errno (errno),
_("Could not seek in XCF file: %s"),
g_strerror (errno));
return FALSE;
}
}
return TRUE;
}
void
xcf_seek_end (XcfInfo *info)
gboolean
xcf_seek_end (XcfInfo *info,
GError **error)
{
fseek (info->fp, 0, SEEK_END);
if (fseek (info->fp, 0, SEEK_END) == -1)
{
g_set_error (error, G_FILE_ERROR, g_file_error_from_errno (errno),
_("Could not seek in XCF file: %s"),
g_strerror (errno));
return FALSE;
}
info->cp = ftell (info->fp);
if (fseek (info->fp, 0, SEEK_END) == -1)
{
g_set_error (error, G_FILE_ERROR, g_file_error_from_errno (errno),
_("Could not seek in XCF file: %s"),
g_strerror (errno));
return FALSE;
}
return TRUE;
}

View File

@ -20,9 +20,11 @@
#define __XCF_SEEK_H__
void xcf_seek_pos (XcfInfo *info,
guint pos);
void xcf_seek_end (XcfInfo *info);
gboolean xcf_seek_pos (XcfInfo *info,
guint pos,
GError **error);
gboolean xcf_seek_end (XcfInfo *info,
GError **error);
#endif /* __XCF_SEEK_H__ */

View File

@ -20,17 +20,22 @@
#include <stdio.h>
#include <string.h> /* strlen */
#include <errno.h>
#include <glib.h>
#include "xcf-write.h"
#include "libgimp/gimpintl.h"
guint
xcf_write_int32 (FILE *fp,
guint32 *data,
gint count)
gint count,
GError **error)
{
GError *tmp_error = NULL;
guint32 tmp;
gint i;
@ -39,7 +44,13 @@ xcf_write_int32 (FILE *fp,
for (i = 0; i < count; i++)
{
tmp = g_htonl (data[i]);
xcf_write_int8 (fp, (guint8*) &tmp, 4);
xcf_write_int8 (fp, (guint8*) &tmp, 4, &tmp_error);
if (tmp_error)
{
g_propagate_error (error, tmp_error);
return i * 4;
}
}
}
@ -49,15 +60,17 @@ xcf_write_int32 (FILE *fp,
guint
xcf_write_float (FILE *fp,
gfloat *data,
gint count)
gint count,
GError **error)
{
return (xcf_write_int32(fp, (guint32 *)((void *)data), count));
return xcf_write_int32 (fp, (guint32 *)((void *)data), count, error);
}
guint
xcf_write_int8 (FILE *fp,
guint8 *data,
gint count)
gint count,
GError **error)
{
guint total;
gint bytes;
@ -66,6 +79,15 @@ xcf_write_int8 (FILE *fp,
while (count > 0)
{
bytes = fwrite ((gchar*) data, sizeof (gchar), count, fp);
if (bytes == 0)
{
g_set_error (error, G_FILE_ERROR, g_file_error_from_errno (errno),
_("Error writing XCF: %s"), g_strerror (errno));
return total;
}
count -= bytes;
data += bytes;
}
@ -76,8 +98,10 @@ xcf_write_int8 (FILE *fp,
guint
xcf_write_string (FILE *fp,
gchar **data,
gint count)
gint count,
GError **error)
{
GError *tmp_error = NULL;
guint32 tmp;
guint total;
gint i;
@ -90,9 +114,20 @@ xcf_write_string (FILE *fp,
else
tmp = 0;
xcf_write_int32 (fp, &tmp, 1);
xcf_write_int32 (fp, &tmp, 1, &tmp_error);
if (tmp_error)
{
g_propagate_error(error, tmp_error);
return total;
}
if (tmp > 0)
xcf_write_int8 (fp, (guint8*) data[i], tmp);
xcf_write_int8 (fp, (guint8*) data[i], tmp, &tmp_error);
if (tmp_error)
{
g_propagate_error(error, tmp_error);
return total;
}
total += 4 + tmp;
}

View File

@ -22,16 +22,20 @@
guint xcf_write_int32 (FILE *fp,
guint32 *data,
gint count);
gint count,
GError **error);
guint xcf_write_float (FILE *fp,
gfloat *data,
gint count);
gint count,
GError **error);
guint xcf_write_int8 (FILE *fp,
guint8 *data,
gint count);
gint count,
GError **error);
guint xcf_write_string (FILE *fp,
gchar **data,
gint count);
gint count,
GError **error);
#endif /* __XCF_WRITE_H__ */

View File

@ -314,7 +314,12 @@ xcf_save_invoker (Gimp *gimp,
xcf_save_choose_format (&info, gimage);
success = xcf_save_image (&info, gimage);
fclose (info.fp);
if (fclose (info.fp) == EOF)
{
g_message (_("Error saving XCF file: %s"), g_strerror (errno));
success = FALSE;
}
}
else
{

View File

@ -203,6 +203,9 @@ app/widgets/gimpwidgets-utils.c
app/xcf/xcf-load.c
app/xcf/xcf-read.c
app/xcf/xcf-save.c
app/xcf/xcf-write.c
app/xcf/xcf-seek.c
app/xcf/xcf.c
data/misc/gimp.desktop.in.in