Created
March 8, 2012 15:30
-
-
Save reklis/2001511 to your computer and use it in GitHub Desktop.
discount-null-pointer-dereference-fixes.diff
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/generate.c b/generate.c | |
index 8e82afd..f3a1bd9 100644 | |
--- a/generate.c | |
+++ b/generate.c | |
@@ -629,49 +629,51 @@ static int | |
linkyformat(MMIOT *f, Cstring text, int image, Footnote *ref) | |
{ | |
linkytype *tag; | |
- | |
+ | |
if ( image || (ref == 0) ) | |
- tag = &imaget; | |
+ tag = &imaget; | |
else if ( tag = pseudo(ref->link) ) { | |
- if ( f->flags & (MKD_NO_EXT|MKD_SAFELINK) ) | |
- return 0; | |
+ if ( f->flags & (MKD_NO_EXT|MKD_SAFELINK) ) | |
+ return 0; | |
} | |
else if ( (f->flags & MKD_SAFELINK) && T(ref->link) | |
- && (T(ref->link)[0] != '/') | |
- && !isautoprefix(T(ref->link), S(ref->link)) ) | |
+ && (T(ref->link)[0] != '/') | |
+ && !isautoprefix(T(ref->link), S(ref->link)) ) | |
/* if MKD_SAFELINK, only accept links that are local or | |
* a well-known protocol | |
*/ | |
- return 0; | |
+ return 0; | |
else | |
- tag = &linkt; | |
- | |
+ tag = &linkt; | |
+ | |
if ( f->flags & tag->flags ) | |
- return 0; | |
- | |
+ return 0; | |
+ | |
if ( f->flags & IS_LABEL ) | |
- ___mkd_reparse(T(text), S(text), tag->flags, f, 0); | |
+ ___mkd_reparse(T(text), S(text), tag->flags, f, 0); | |
else if ( tag->link_pfx ) { | |
- printlinkyref(f, tag, T(ref->link), S(ref->link)); | |
- | |
- if ( tag->WxH ) { | |
- if ( ref->height ) Qprintf(f," height=\"%d\"", ref->height); | |
- if ( ref->width ) Qprintf(f, " width=\"%d\"", ref->width); | |
- } | |
- | |
- if ( S(ref->title) ) { | |
- Qstring(" title=\"", f); | |
- ___mkd_reparse(T(ref->title), S(ref->title), MKD_TAGTEXT, f, 0); | |
- Qchar('"', f); | |
- } | |
- | |
- Qstring(tag->text_pfx, f); | |
- ___mkd_reparse(T(text), S(text), tag->flags, f, 0); | |
- Qstring(tag->text_sfx, f); | |
+ if (ref) { | |
+ printlinkyref(f, tag, T(ref->link), S(ref->link)); | |
+ | |
+ if ( tag->WxH ) { | |
+ if ( ref->height ) Qprintf(f," height=\"%d\"", ref->height); | |
+ if ( ref->width ) Qprintf(f, " width=\"%d\"", ref->width); | |
+ } | |
+ | |
+ if ( S(ref->title) ) { | |
+ Qstring(" title=\"", f); | |
+ ___mkd_reparse(T(ref->title), S(ref->title), MKD_TAGTEXT, f, 0); | |
+ Qchar('"', f); | |
+ } | |
+ | |
+ Qstring(tag->text_pfx, f); | |
+ ___mkd_reparse(T(text), S(text), tag->flags, f, 0); | |
+ Qstring(tag->text_sfx, f); | |
+ } | |
} | |
- else | |
- Qwrite(T(ref->link) + tag->szpat, S(ref->link) - tag->szpat, f); | |
- | |
+ else if (ref) | |
+ Qwrite(T(ref->link) + tag->szpat, S(ref->link) - tag->szpat, f); | |
+ | |
return 1; | |
} /* linkyformat */ | |
diff --git a/markdown.c b/markdown.c | |
index 99acc60..d01d5dc 100644 | |
--- a/markdown.c | |
+++ b/markdown.c | |
@@ -753,49 +753,52 @@ quoteblock(Paragraph *p, DWORD flags) | |
{ | |
Line *t, *q; | |
int qp; | |
- | |
+ | |
for ( t = p->text; t ; t = q ) { | |
- if ( isquote(t) ) { | |
- /* clip leading spaces */ | |
- for (qp = 0; T(t->text)[qp] != '>'; qp ++) | |
- /* assert: the first nonblank character on this line | |
- * will be a > | |
- */; | |
- /* clip '>' */ | |
- qp++; | |
- /* clip next space, if any */ | |
- if ( T(t->text)[qp] == ' ' ) | |
- qp++; | |
- CLIP(t->text, 0, qp); | |
- UNCHECK(t); | |
- t->dle = mkd_firstnonblank(t); | |
- } | |
- | |
- q = skipempty(t->next); | |
- | |
- if ( (q == 0) || ((q != t->next) && (!isquote(q) || isdivmarker(q,1,flags))) ) { | |
- ___mkd_freeLineRange(t, q); | |
- t = q; | |
- break; | |
- } | |
+ if ( isquote(t) ) { | |
+ /* clip leading spaces */ | |
+ for (qp = 0; T(t->text)[qp] != '>'; qp ++) | |
+ /* assert: the first nonblank character on this line | |
+ * will be a > | |
+ */; | |
+ /* clip '>' */ | |
+ qp++; | |
+ /* clip next space, if any */ | |
+ if ( T(t->text)[qp] == ' ' ) | |
+ qp++; | |
+ CLIP(t->text, 0, qp); | |
+ UNCHECK(t); | |
+ t->dle = mkd_firstnonblank(t); | |
+ } | |
+ | |
+ q = skipempty(t->next); | |
+ | |
+ if ( (q == 0) || ((q != t->next) && (!isquote(q) || isdivmarker(q,1,flags))) ) { | |
+ ___mkd_freeLineRange(t, q); | |
+ t = q; | |
+ break; | |
+ } | |
} | |
if ( isdivmarker(p->text,0,flags) ) { | |
- char *prefix = "class"; | |
- int i; | |
- | |
- q = p->text; | |
- p->text = p->text->next; | |
- | |
- if ( (i = szmarkerclass(1+T(q->text))) == 3 ) | |
- /* and this would be an "%id:" prefix */ | |
- prefix="id"; | |
- | |
- if ( p->ident = malloc(4+strlen(prefix)+S(q->text)) ) | |
- sprintf(p->ident, "%s=\"%.*s\"", prefix, S(q->text)-(i+2), | |
- T(q->text)+(i+1) ); | |
- | |
- ___mkd_freeLine(q); | |
- } | |
+ char *prefix = "class"; | |
+ int i; | |
+ | |
+ q = p->text; | |
+ | |
+ if (q) { | |
+ p->text = p->text->next; | |
+ | |
+ if ( (i = szmarkerclass(1+T(q->text))) == 3 ) | |
+ /* and this would be an "%id:" prefix */ | |
+ prefix="id"; | |
+ | |
+ if ( p->ident = malloc(4+strlen(prefix)+S(q->text)) ) | |
+ sprintf(p->ident, "%s=\"%.*s\"", prefix, S(q->text)-(i+2), | |
+ T(q->text)+(i+1) ); | |
+ | |
+ ___mkd_freeLine(q); | |
+ } | |
+ }; | |
return t; | |
} | |
@@ -1142,41 +1145,43 @@ actually_a_table(MMIOT *f, Line *pp) | |
Line *r; | |
int j; | |
int c; | |
- | |
+ | |
/* tables need to be turned on */ | |
if ( f->flags & (MKD_STRICT|MKD_NOTABLES) ) | |
- return 0; | |
- | |
+ return 0; | |
+ | |
/* tables need three lines */ | |
if ( !(pp && pp->next && pp->next->next) ) { | |
- return 0; | |
+ return 0; | |
} | |
- | |
+ | |
/* all lines must contain |'s */ | |
for (r = pp; r; r = r->next ) | |
- if ( !(r->flags & PIPECHAR) ) { | |
- return 0; | |
- } | |
- | |
+ if ( !(r->flags & PIPECHAR) ) { | |
+ return 0; | |
+ } | |
+ | |
/* if the header has a leading |, all lines must have leading |'s */ | |
if ( T(pp->text)[pp->dle] == '|' ) { | |
- for ( r = pp; r; r = r->next ) | |
- if ( T(r->text)[first_nonblank_before(r,pp->dle)] != '|' ) { | |
- return 0; | |
- } | |
+ for ( r = pp; r; r = r->next ) | |
+ if ( T(r->text)[first_nonblank_before(r,pp->dle)] != '|' ) { | |
+ return 0; | |
+ } | |
} | |
- | |
+ | |
/* second line must be only whitespace, -, |, or : */ | |
r = pp->next; | |
- | |
- for ( j=r->dle; j < S(r->text); ++j ) { | |
- c = T(r->text)[j]; | |
- | |
- if ( !(isspace(c)||(c=='-')||(c==':')||(c=='|')) ) { | |
- return 0; | |
- } | |
+ | |
+ if (r) { | |
+ for ( j=r->dle; j < S(r->text); ++j ) { | |
+ c = T(r->text)[j]; | |
+ | |
+ if ( !(isspace(c)||(c=='-')||(c==':')||(c=='|')) ) { | |
+ return 0; | |
+ } | |
+ } | |
} | |
- | |
+ | |
return 1; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment