[easytag] Improve two cases where realloc() fails
- From: David King <davidk src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [easytag] Improve two cases where realloc() fails
- Date: Wed, 6 Feb 2013 20:51:53 +0000 (UTC)
commit 3437d3c283bb6b86049f4148cd15de6903108bd5
Author: David King <amigadave amigadave com>
Date: Wed Feb 6 17:51:39 2013 +0000
Improve two cases where realloc() fails
src/charset.c | 8 ++++++--
src/libapetag/id3v2_read.c | 17 +++++++++++++----
2 files changed, 19 insertions(+), 6 deletions(-)
---
diff --git a/src/charset.c b/src/charset.c
index fa4a312..081e44a 100644
--- a/src/charset.c
+++ b/src/charset.c
@@ -421,9 +421,13 @@ convert_string_1 (const gchar *string, gssize length, const gchar *from_codeset,
// g_convert returns null-terminated string only with one \0 at the
// end. It can cause some garbage at the end of a string for UTF-16.
// The second \0 should be set manually.
- output = g_realloc(output, bytes_written + 2);
- if (output != NULL)
+ gchar *new_output;
+ new_output = g_realloc (output, bytes_written + 2);
+ if (new_output != NULL)
+ {
+ output = new_output;
output[bytes_written] = output[bytes_written + 1] = 0;
+ }
}
//g_print("from %s => len: %d, string: '%s'\n (%x %x %x %x %x %x %x %x)\n",from_codeset,length,string,string[0],string[1],string[2],string[3],string[4],string[5],string[6],string[7]);
diff --git a/src/libapetag/id3v2_read.c b/src/libapetag/id3v2_read.c
index f4c8a64..f26772f 100644
--- a/src/libapetag/id3v2_read.c
+++ b/src/libapetag/id3v2_read.c
@@ -183,10 +183,19 @@ libapetag_convertID3v2toAPE (const ID3Frame * frame,
value_len2 = 0;
value[0]='\0';
} else {
- item = (char *) realloc( item, (*item_len) + value_len2 + 3);
- item[(*item_len)++]='-'; item[(*item_len)]='\0';
- strncpy(item + (*item_len),value_ds ,(value_len2 + 1));
- (*item_len)+=value_len2;
+ char *new_item;
+ new_item = (char *) realloc( item, (*item_len) + value_len2 + 3);
+ if (new_item != NULL)
+ {
+ item = new_item;
+ item[(*item_len)++]='-'; item[(*item_len)]='\0';
+ strncpy(item + (*item_len),value_ds ,(value_len2 + 1));
+ (*item_len)+=value_len2;
+ }
+ else
+ {
+ abort ();
+ }
}
free(value_ds);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]