The Birdfont Source Code


All Repositories / birdfont.git / commit – RSS feed

Report error if malloc fails

These changes was commited to the Birdfont repository Tue, 26 May 2015 15:41:45 +0000.

Contributing

Send patches or pull requests to johan.mattsson.m@gmail.com.
Clone this repository: git clone https://github.com/johanmattssonm/birdfont.git
author Johan Mattsson <johan.mattsson.m@gmail.com>
Tue, 26 May 2015 15:41:45 +0000 (17:41 +0200)
committer Johan Mattsson <johan.mattsson.m@gmail.com>
Tue, 26 May 2015 15:41:45 +0000 (17:41 +0200)
commit e6b5ff0c1e374c7de80b8dbe3c1d3027ed25dc5e
tree 3a59d667ba0dfa6e22f8b6c7856657937eb790cd
parent 586fcd6f59dca10e584ec0099dd5484963326ae0
Report error if malloc fails

libbirdxml/Xml.vala
libbirdxml/XmlData.vala
--- a/libbirdxml/Xml.vala +++ b/libbirdxml/Xml.vala @@ -69,11 +69,10 @@ * */ public class XmlParser : GLib.Object { - public Tag root; - public XmlData data; - public string input; - public bool error; - public int refcount = 1; + Tag root; + XmlData data; + string input; + bool error; /** * Create a new xml parser. @@ -81,7 +80,7 @@ */ public XmlParser (string data) { this.input = data; - this.data = new XmlData (data, data.length); + this.data = new XmlData (data, data.length); reparse (NONE); } @@ -90,6 +89,11 @@ * @return true if the xml document is valid xml. */ public bool validate () { + if (this.data.error) { + error = true; + return false; + } + reparse (NONE); if (error) {
--- a/libbirdxml/XmlData.vala +++ b/libbirdxml/XmlData.vala @@ -18,6 +18,8 @@ int* start_tags; int tags_capacity; int tags_size; + + internal bool error = false; public XmlData (char* data, int length) { base (data, length); @@ -92,8 +94,8 @@ bool increase_capacity () { int* tags; - tags_capacity += 10; - tags = (int*) new int [tags_capacity]; + tags_capacity += 512; + tags = (int*) try_malloc (tags_capacity * sizeof (int)); if (tags == null) { tags_capacity = 0; @@ -101,6 +103,8 @@ if (start_tags != null) { delete start_tags; start_tags = null; + tags_size = 0; + error = true; } warning ("Can not allocate xml data buffer.");