[gimp] Bug 795814 - Error saving VERY large file.
- From: Jehan Pagès <jehanp src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gimp] Bug 795814 - Error saving VERY large file.
- Date: Sat, 5 May 2018 18:14:01 +0000 (UTC)
commit 47a036f7506303b0f4e6fad437ed7d5ea4a57a2b
Author: Jehan <jehan girinstud io>
Date: Sat May 5 20:01:54 2018 +0200
Bug 795814 - Error saving VERY large file.
g_alloca() is not very advisable, especially when it might be used to
allocate a big chunk of memory at once. It is better to allocate dynamic
memory with malloc(), or in particular with g_try_malloc() which won't
abort the program on failure.
This might be slightly slower (one of the advantages of memory on the
stack, though not even an absolute truth) but probably not by much, if
at all, and it's better to be safe anyway.
app/xcf/xcf-write.c | 22 ++++++++++++++++++----
1 files changed, 18 insertions(+), 4 deletions(-)
---
diff --git a/app/xcf/xcf-write.c b/app/xcf/xcf-write.c
index 4609f3b..13a6c5a 100644
--- a/app/xcf/xcf-write.c
+++ b/app/xcf/xcf-write.c
@@ -183,12 +183,26 @@ xcf_write_zero_offset (XcfInfo *info,
{
if (count > 0)
{
- guint8 *tmp = g_alloca (count * info->bytes_per_offset);
+ guint8 *tmp;
+ guint bytes_written = 0;
- memset (tmp, 0, count * info->bytes_per_offset);
+ tmp = g_try_malloc (count * info->bytes_per_offset);
+ if (! tmp)
+ {
+ g_set_error (error, G_FILE_ERROR, G_FILE_ERROR_FAILED,
+ _("Error writing XCF: failed to allocate %d bytes of memory."),
+ count * info->bytes_per_offset);
+ }
+ else
+ {
+ memset (tmp, 0, count * info->bytes_per_offset);
+
+ bytes_written = xcf_write_int8 (info, (const guint8 *) tmp,
+ count * info->bytes_per_offset, error);
+ g_free (tmp);
+ }
- return xcf_write_int8 (info, (const guint8 *) tmp,
- count * info->bytes_per_offset, error);
+ return bytes_written;
}
return 0;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]