From 1d9d6da4c8492d49d0cd49013c046f5102040dd2 Mon Sep 17 00:00:00 2001 From: David Parsons Date: Thu, 3 Jan 2008 22:20:54 -0800 Subject: [PATCH] Don't forget to do null pointer checking before trying to dereference them. --- markdown.c | 4 +- tests/crash.t | 27 +++++++++++++ tests/quote.t | 10 ----- tests/quote.text | 4 -- tests/smarty.t | 102 +++++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 132 insertions(+), 15 deletions(-) create mode 100644 tests/crash.t delete mode 100644 tests/quote.t delete mode 100644 tests/quote.text create mode 100644 tests/smarty.t diff --git a/markdown.c b/markdown.c index 24987f6..251da50 100644 --- a/markdown.c +++ b/markdown.c @@ -758,7 +758,7 @@ static Paragraph *display(Paragraph*, MMIOT*, int); static void emit(Paragraph *p, MMIOT *f) { - int multiple = ( p->next != 0 ); + int multiple = p && p->next; while (( p = display(p, f, multiple) )) ; @@ -790,6 +790,8 @@ listdisplay(Paragraph *p, MMIOT* f) static Paragraph* display(Paragraph *p, MMIOT *f, int multiple) { + if ( !p ) return; + switch ( p->typ ) { case FORCED: break; diff --git a/tests/crash.t b/tests/crash.t new file mode 100644 index 0000000..b161bc4 --- /dev/null +++ b/tests/crash.t @@ -0,0 +1,27 @@ +echo "crashes" + +rc=0 + +echo -n ' hanging quote in list ............ ' + +./markdown >/dev/null 2>/dev/null << EOF + * > this should not die + +no. +EOF + +if [ "$?" -eq 0 ]; then + echo "OK" +else + echo "Failed" + rc=1 +fi + +echo -n ' dangling list item ............... ' + +if echo ' - ' | ./markdown >/dev/null 2>/dev/null; then + echo "OK" +else + echo "Failed" + rc=1 +fi diff --git a/tests/quote.t b/tests/quote.t deleted file mode 100644 index d882f76..0000000 --- a/tests/quote.t +++ /dev/null @@ -1,10 +0,0 @@ -echo -n "quote................................" - -exec 2> /dev/null - -if ./markdown tests/quote.text >/dev/null; then - echo "OK" - exit 0 -fi -echo "FAILED" -exit 1 diff --git a/tests/quote.text b/tests/quote.text deleted file mode 100644 index 9a99539..0000000 --- a/tests/quote.text +++ /dev/null @@ -1,4 +0,0 @@ -1. > this is a test - - -And this is not a test. diff --git a/tests/smarty.t b/tests/smarty.t new file mode 100644 index 0000000..3083b5f --- /dev/null +++ b/tests/smarty.t @@ -0,0 +1,102 @@ +echo "smarty pants" + +rc=0 + +echo -n ' (c) -> © .................... ' + +if echo '(c)' | ./markdown | grep '©' >/dev/null; then + echo "OK" +else + echo "FAILED" + rc=1 +fi + +echo -n ' (r) -> ® ..................... ' + +if echo '(r)' | ./markdown | grep '®' >/dev/null; then + echo "OK" +else + echo "FAILED" + rc=1 +fi + +echo -n ' (tm) -> ™ .................. ' + +if echo '(tm)' | ./markdown | grep '™' >/dev/null; then + echo "OK" +else + echo "FAILED" + rc=1 +fi + +echo -n ' ... -> … .................. ' + +if echo '...' | ./markdown | grep '…' >/dev/null; then + echo "OK" +else + echo "FAILED" + rc=1 +fi + +echo -n ' -- -> — .................... ' + +if echo '--' | ./markdown | grep '—' >/dev/null; then + echo "OK" +else + echo "FAILED" + rc=1 +fi + +echo -n ' - -> – ..................... ' + +if echo 'regular - ' | ./markdown | grep '–' >/dev/null; then + echo "OK" +else + echo "FAILED" + rc=1 +fi + +echo -n ' A-B -> A-B ....................... ' + +if echo 'A-B' | ./markdown | grep '–' >/dev/null; then + echo "FAILED" + rc=1 +else + echo "OK" +fi + +echo -n ' "fancy" -> “fancy” ... ' + +if echo '"fancy"' | ./markdown | grep '“fancy”' >/dev/null; then + echo "OK" +else + echo "FAILED" + rc=1 +fi + +echo -n ' '"'fancy'"' -> ‘fancy’ ... ' + +if echo "'fancy'" | ./markdown | grep '‘fancy’' >/dev/null; then + echo "OK" +else + echo "FAILED" + rc=1 +fi + +echo -n " don't -> don't ................... " + +if echo "don't" | ./markdown | grep "don't" >/dev/null; then + echo "OK" +else + echo "FAILED" + rc=1 +fi + +echo -n ' `` ` `` -> ` ...... ' + +if echo '`` ` ``' | ./markdown | grep ' ` ' >/dev/null; then + echo "OK" +else + echo "FAILED" + rc=1 +fi