$OpenBSD: patch-taglib_xm_xmfile_cpp,v 1.2 2013/01/27 21:28:25 dcoppa Exp $

Check if file is open before attempting to read tags: fix a crash
in the file constructor if the file does not exist
(upstream git commit d15c8453ac75d9070008b9170ae114ea31a4b586)

Fix a crash when saving xm files
(upstream git commit 2d7414733eaa3263868c74abfa6cff38a8afe8d3)

--- taglib/xm/xmfile.cpp.orig	Thu Sep  6 20:03:15 2012
+++ taglib/xm/xmfile.cpp	Sun Jan 27 19:52:41 2013
@@ -359,7 +359,8 @@ XM::File::File(FileName file, bool readProperties,
   Mod::FileBase(file),
   d(new FilePrivate(propertiesStyle))
 {
-  read(readProperties);
+	if(isOpen())
+		read(readProperties);
 }
 
 XM::File::File(IOStream *stream, bool readProperties,
@@ -367,7 +368,8 @@ XM::File::File(IOStream *stream, bool readProperties,
   Mod::FileBase(stream),
   d(new FilePrivate(propertiesStyle))
 {
-  read(readProperties);
+	if(isOpen())
+		read(readProperties);
 }
 
 XM::File::~File()
@@ -443,7 +445,7 @@ bool XM::File::save()
       return false;
 
     uint len = std::min(22UL, instrumentHeaderSize - 4U);
-    if(i > lines.size())
+    if(i >= lines.size())
       writeString(String::null, len);
     else
       writeString(lines[i], len);
