summaryrefslogtreecommitdiffabout
path: root/libid3tag
authorSergey Poznyakoff <gray@gnu.org.ua>2011-03-26 21:01:50 (GMT)
committer Sergey Poznyakoff <gray@gnu.org.ua>2011-03-26 21:01:50 (GMT)
commit65bfbf2c783c82f22074fb2653105692ec354c3c (patch) (side-by-side diff)
treefe2bbae705c88d56aba6a714edb3fbc21c8f364a /libid3tag
parentf4692d0867aac664180cd20e0eb7c52f6a931f76 (diff)
downloadidest-65bfbf2c783c82f22074fb2653105692ec354c3c.tar.gz
idest-65bfbf2c783c82f22074fb2653105692ec354c3c.tar.bz2
libid3tag: Fix writing v2 tags to a clean mp3 file.
This fixes a bug introduced by 4c887e9caf. * libid3tag/file.c (v2_write): Proceed even if ntags is 0, but take care not to dereference file->tags. After writing, add new tag to the file.
Diffstat (limited to 'libid3tag') (more/less context) (ignore whitespace changes)
-rw-r--r--libid3tag/file.c24
1 files changed, 13 insertions, 11 deletions
diff --git a/libid3tag/file.c b/libid3tag/file.c
index 8c1aa54..1feb504 100644
--- a/libid3tag/file.c
+++ b/libid3tag/file.c
@@ -727,8 +727,6 @@ v2_write(struct id3_file *file,
{
int rc;
- if (file->ntags == 0)
- return 0;
if (data &&
((file->ntags == 1 && !(file->flags & ID3_FILE_FLAG_ID3V1)) ||
(file->ntags == 2 && (file->flags & ID3_FILE_FLAG_ID3V1))) &&
@@ -769,14 +767,17 @@ v2_write(struct id3_file *file,
* FIXME: Should I check
* tag->version instead?
*/
- (file->tags[0].location == 0) ?
+ (file->ntags > 0 &&
+ file->tags[0].location == 0) ?
file->tags[0].length : 0, -1);
fclose(tmp);
if (rc)
unlink(tmpname);
else {
- file->tags[0].length = length;
+ if (file->ntags > 0)
+ file->tags[0].length = length;
+
fclose(file->iofile);
rc = unlink(file->path);
if (rc == 0) {
@@ -784,6 +785,11 @@ v2_write(struct id3_file *file,
chmod(file->path, st.st_mode & 0777);
chown(file->path, st.st_uid, st.st_gid);
file->iofile = fopen(file->path, "r+b");
+ if (file->ntags == 0)
+ add_tag(file, length);
+ /* FIXME: See also comment after the
+ call to this function in id3_file_update.
+ */
}
}
free(tmpname);
@@ -798,13 +804,9 @@ v2_write(struct id3_file *file,
int
id3_file_update(struct id3_file *file)
{
- int options,
- result = 0;
- id3_length_t v1size = 0,
- v2size = 0;
- id3_byte_t id3v1_data[128],
- *id3v1 = 0,
- *id3v2 = 0;
+ int options, result = 0;
+ id3_length_t v1size = 0, v2size = 0;
+ id3_byte_t id3v1_data[128], *id3v1 = 0, *id3v2 = 0;
assert(file);

Return to:

Send suggestions and report system problems to the System administrator.