]> git.lyx.org Git - features.git/commitdiff
Fix crash when data.find('=') returns string::npos.
authorAngus Leeming <leeming@lyx.org>
Tue, 5 Mar 2002 17:36:22 +0000 (17:36 +0000)
committerAngus Leeming <leeming@lyx.org>
Tue, 5 Mar 2002 17:36:22 +0000 (17:36 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@3670 a592a061-630c-0410-9148-cb99ea01b6c8

src/frontends/controllers/ChangeLog
src/frontends/controllers/biblio.C

index e6978f11d4fa28a4ee9154b2402cd7f4e8331700..cb8846e623d68a5de4e100ea71ada4e891bb1e86 100644 (file)
@@ -1,3 +1,9 @@
+2002-03-05  Angus Leeming  <a.leeming@ic.ac.uk>
+
+       * biblio.C (getInfo): return the info field correctly if the key
+       is not a BibTeX one.
+       (parseBibTeX): fix crash when data.find('=') returns string::npos.
+
 2002-02-20  Angus Leeming  <a.leeming@ic.ac.uk>
 
        * ControlForks.[Ch]: new files. A controller for the Forked Child
index 3d8aa28979b1dccc213c52369b86ea7cad8cc007..110c069e75afab1f9a6c05d6e5218504fe3f3347 100644 (file)
@@ -285,10 +285,12 @@ string const getInfo(InfoMap const & map, string const & key)
        if (!year.empty())
                result << ", " << year;
 
-       if (result.str().empty()) // not a BibTeX record
-               result << it->second;
+       char const * const tmp = result.str().c_str();
+       string result_str = tmp ? strip(tmp) : string();
+       if (result_str.empty()) // not a BibTeX record
+               result_str = it->second;
 
-       return result.str().c_str();
+       return result_str;
 }
  
 
@@ -328,15 +330,24 @@ string const parseBibTeX(string data, string const & findkey)
        while (!dummy.empty()) {
                dummy = subst(dummy, '\t', ' ');        // no tabs
                dummy = frontStrip(dummy);      // no leading spaces
-               if (dummy.find('%') != string::npos) {
-                   if (dummy.find('%') > 0)
-                       data_ += dummy.substr(0,data.find('%'));
+               string::size_type const idx =
+                       dummy.empty() ? string::npos : dummy.find('%');
+               if (idx != string::npos) {
+                       if (idx > 0) {
+                               // This is safe. data MUST contain a '%'
+                               data_ += dummy.substr(0,data.find('%'));
+                       }
+               } else {
+                       data_ += dummy;
                }
-               else
-                   data_ += dummy;
                dummy = token(data, '\n', ++Entries);
        }
        data = data_;
+
+       // unlikely!
+       if (data.empty())
+               return string();
+
        // now get only the important line of the bibtex entry.
        // all entries are devided by ',' except the last one.  
        data += ',';  // now we have same behaviour for all entries
@@ -361,9 +372,15 @@ string const parseBibTeX(string data, string const & findkey)
        if (!contains(data, '{'))       // no opening '{'
                data = strip(data, '}');// maybe there is a main closing '}'
        // happens, when last keyword
-       string key = lowercase(data.substr(0, data.find('=')));
-       data = data.substr(data.find('='), data.length() - 1);
+       string::size_type const idx =
+               data.empty() ? data.find('=') : string::npos;
+
+       if (idx == string::npos)
+               return string();
+
+       data = data.substr(idx, data.length() - 1);
        data = frontStrip(strip(data));
+
        if (data.length() < 2 || data[0] != '=') {      // a valid entry?
                return string();
        } else {