fix recent session loading.
authorRobin Gareus <robin@gareus.org>
Thu, 10 Sep 2015 15:34:59 +0000 (17:34 +0200)
committerRobin Gareus <robin@gareus.org>
Thu, 10 Sep 2015 15:39:31 +0000 (17:39 +0200)
std::stringstream::operator<< calls strlen(), but the string in the
temp buffer may not [yet] be NULL terminated.

libs/ardour/recent_sessions.cc

index 85c3c55f1630205cfd351a112acf065621ef4951..f19c0d8d37a80ea3a6380369ddae3f4873e9dc00 100644 (file)
@@ -61,27 +61,22 @@ ARDOUR::read_recent_sessions (RecentSessions& rs)
                }
        }
 
-
-
-       // Read the file into a std::string;
+       // Read the file into a std::string
        std::stringstream recent;
-       char temporaryBuffer[1024];
-       while (!feof(fin))
-       {
-               size_t charsRead = fread(&temporaryBuffer[0], sizeof(char), 1024, fin);
-               if (charsRead != 1024 && ferror(fin))
-               {
+       while (!feof (fin)) {
+               char buf[1024];
+               size_t charsRead = fread (buf, sizeof(char), 1024, fin);
+               if (ferror (fin)) {
                        error << string_compose (_("Error reading recent session file %1 (%2)"), path, strerror (errno)) << endmsg;
                        fclose(fin);
                        return -1;
                }
-               recent << &temporaryBuffer[0];
+               if (charsRead == 0) {
+                       break;
+               }
+               recent.write (buf, charsRead);
        }
 
-
-
-       //ifstream recent (fin);
-
        while (true) {
 
                pair<string,string> newpair;