Permalink
Browse files

fixes dirty buffer bug

  • Loading branch information...
1 parent 2c971d1 commit d833d53fe34c97d829f43eaa06912c2ce6b568fb @dtjm committed May 24, 2012
Showing with 32 additions and 10 deletions.
  1. +4 −2 Makefile
  2. +1 −1 convert.js
  3. +8 −7 multimarkdown.cc
  4. +19 −0 test.js
View
@@ -5,11 +5,13 @@ all: build/Release/multimarkdown.node
build/Release/multimarkdown.node: multimarkdown.cc wscript ${PEGMMD}/markdown_lib.o
node-waf configure build
-${PEGMMD}/markdown_lib.o:
- git clone https://github.com/fletcher/peg-multimarkdown.git deps/peg-multimarkdown
+${PEGMMD}/markdown_lib.o: ${PEGMMD}
cd deps/peg-multimarkdown; git checkout 3.5.1
make -C deps/peg-multimarkdown
+${PEGMMD}:
+ git clone https://github.com/fletcher/peg-multimarkdown.git deps/peg-multimarkdown
+
clean:
node-waf clean distclean
make -C ${PEGMMD} clean
View
@@ -1,4 +1,4 @@
-var MMD = require("./build/Release/multimarkdown");
+var MMD = require("multimarkdown");
var input = "";
process.stdin.on("data", function(chunk){
View
@@ -29,17 +29,18 @@ extern "C" {
}
using namespace v8;
-char *buf;
+char *buf = NULL;
int buflen = -1;
void reallocbuf(int len) {
- if(len < buflen) {
- return;
+ // Do the actual allocation if we requested more space that we have
+ // allocated.
+ if(len > buflen) {
+ buflen = len + 1;
+ buf = (char*) realloc(buf, buflen);
}
- free(buf);
- buflen = len + 1;
- buf = (char*) malloc(buflen);
- memset(buf, 0, buflen);
+ // Clear the memory space
+ memset(buf, 0, len + 1);
}
int format = HTML_FORMAT;
View
19 test.js
@@ -0,0 +1,19 @@
+var MMD = require("./build/Release/multimarkdown.node");
+
+var expected = {
+ "a": "<p>a</p>",
+ "ab": "<p>ab</p>",
+ "c": "<p>c</p>"
+};
+
+console.log("MultiMarkdown Test");
+
+for(var input in expected){
+ var out = MMD.convert(input);
+ if(expected[input] !== out) {
+ console.log("FAIL");
+ console.log(input, ">>", expected[input], out);
+ } else {
+ console.log("OK ");
+ }
+}

0 comments on commit d833d53

Please sign in to comment.