Commit 9b1f1d17 authored by Poul-Henning Kamp's avatar Poul-Henning Kamp

Fix PeekToken(): Should never be called with EOI token, and thus cannot return NULL.

parent 0a4884c6
...@@ -457,7 +457,7 @@ vcc_acl_entry(struct vcc *tl) ...@@ -457,7 +457,7 @@ vcc_acl_entry(struct vcc *tl)
*/ */
static void static void
vcc_acl_emit_tokens(struct vcc *tl, const struct acl_e *ae) vcc_acl_emit_tokens(const struct vcc *tl, const struct acl_e *ae)
{ {
struct token *t; struct token *t;
const char *sep = ""; const char *sep = "";
...@@ -490,7 +490,7 @@ vcc_acl_emit_tokens(struct vcc *tl, const struct acl_e *ae) ...@@ -490,7 +490,7 @@ vcc_acl_emit_tokens(struct vcc *tl, const struct acl_e *ae)
*/ */
static unsigned static unsigned
vcc_acl_emit_tables(struct vcc *tl, unsigned n, const char *name) vcc_acl_emit_tables(const struct vcc *tl, unsigned n, const char *name)
{ {
struct acl_e *ae; struct acl_e *ae;
unsigned rv = sizeof(ae->data) + 3; unsigned rv = sizeof(ae->data) + 3;
......
...@@ -415,13 +415,13 @@ void vcc_Warn(struct vcc *); ...@@ -415,13 +415,13 @@ void vcc_Warn(struct vcc *);
void vcc__Expect(struct vcc *tl, unsigned tok, unsigned line); void vcc__Expect(struct vcc *tl, unsigned tok, unsigned line);
int vcc_IdIs(const struct token *t, const char *p); int vcc_IdIs(const struct token *t, const char *p);
void vcc_PrintTokens(struct vcc *tl, const struct token *tb, void vcc_PrintTokens(const struct vcc *tl, const struct token *tb,
const struct token *te); const struct token *te);
void vcc_ExpectVid(struct vcc *tl, const char *what); void vcc_ExpectVid(struct vcc *tl, const char *what);
void vcc_Lexer(struct vcc *tl, struct source *sp); void vcc_Lexer(struct vcc *tl, struct source *sp);
void vcc_NextToken(struct vcc *tl); void vcc_NextToken(struct vcc *tl);
struct token * vcc_PeekToken(struct vcc *tl); struct token * vcc_PeekToken(const struct vcc *tl);
struct token * vcc_PeekTokenFrom(struct vcc *tl, const struct token *t); struct token * vcc_PeekTokenFrom(const struct vcc *tl, const struct token *t);
void vcc__ErrInternal(struct vcc *tl, const char *func, void vcc__ErrInternal(struct vcc *tl, const char *func,
unsigned line); unsigned line);
......
...@@ -264,24 +264,20 @@ vcc_ErrWhere(struct vcc *tl, const struct token *t) ...@@ -264,24 +264,20 @@ vcc_ErrWhere(struct vcc *tl, const struct token *t)
/*--------------------------------------------------------------------*/ /*--------------------------------------------------------------------*/
struct token * struct token *
vcc_PeekTokenFrom(struct vcc *tl, const struct token *t) vcc_PeekTokenFrom(const struct vcc *tl, const struct token *t)
{ {
struct token *tn; struct token *t2;
CHECK_OBJ_NOTNULL(tl, VCC_MAGIC); CHECK_OBJ_NOTNULL(tl, VCC_MAGIC);
AN(t); AN(t);
tn = VTAILQ_NEXT(t, list); assert(t->tok != EOI);
if (tn == NULL) { t2 = VTAILQ_NEXT(t, list);
VSB_cat(tl->sb, AN(t2);
"Ran out of input, something is missing or" return (t2);
" maybe unbalanced (...) or {...}\n");
tl->err = 1;
}
return (tn);
} }
struct token * struct token *
vcc_PeekToken(struct vcc *tl) vcc_PeekToken(const struct vcc *tl)
{ {
CHECK_OBJ_NOTNULL(tl, VCC_MAGIC); CHECK_OBJ_NOTNULL(tl, VCC_MAGIC);
...@@ -330,7 +326,8 @@ vcc_IdIs(const struct token *t, const char *p) ...@@ -330,7 +326,8 @@ vcc_IdIs(const struct token *t, const char *p)
*/ */
void void
vcc_PrintTokens(struct vcc *tl, const struct token *tb, const struct token *te) vcc_PrintTokens(const struct vcc *tl,
const struct token *tb, const struct token *te)
{ {
CHECK_OBJ_NOTNULL(tl, VCC_MAGIC); CHECK_OBJ_NOTNULL(tl, VCC_MAGIC);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment