[master] 9b1f1d170 Fix PeekToken(): Should never be called with EOI token, and thus cannot return NULL.

Poul-Henning Kamp phk at FreeBSD.org
Wed Jun 2 15:17:05 UTC 2021


commit 9b1f1d170781ffa8a881b46455327ca9d7d5c514
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date:   Wed Jun 2 15:11:55 2021 +0000

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

diff --git a/lib/libvcc/vcc_acl.c b/lib/libvcc/vcc_acl.c
index d7e4a63b3..724d5bfe8 100644
--- a/lib/libvcc/vcc_acl.c
+++ b/lib/libvcc/vcc_acl.c
@@ -457,7 +457,7 @@ vcc_acl_entry(struct vcc *tl)
  */
 
 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;
 	const char *sep = "";
@@ -490,7 +490,7 @@ vcc_acl_emit_tokens(struct vcc *tl, const struct acl_e *ae)
  */
 
 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;
 	unsigned rv = sizeof(ae->data) + 3;
diff --git a/lib/libvcc/vcc_compile.h b/lib/libvcc/vcc_compile.h
index 40c46ca5d..3f3ccc3c0 100644
--- a/lib/libvcc/vcc_compile.h
+++ b/lib/libvcc/vcc_compile.h
@@ -415,13 +415,13 @@ void vcc_Warn(struct vcc *);
 
 void vcc__Expect(struct vcc *tl, unsigned tok, unsigned line);
 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);
 void vcc_ExpectVid(struct vcc *tl, const char *what);
 void vcc_Lexer(struct vcc *tl, struct source *sp);
 void vcc_NextToken(struct vcc *tl);
-struct token * vcc_PeekToken(struct vcc *tl);
-struct token * vcc_PeekTokenFrom(struct vcc *tl, const struct token *t);
+struct token * vcc_PeekToken(const struct vcc *tl);
+struct token * vcc_PeekTokenFrom(const struct vcc *tl, const struct token *t);
 void vcc__ErrInternal(struct vcc *tl, const char *func,
     unsigned line);
 
diff --git a/lib/libvcc/vcc_token.c b/lib/libvcc/vcc_token.c
index b965c298d..77ce5c075 100644
--- a/lib/libvcc/vcc_token.c
+++ b/lib/libvcc/vcc_token.c
@@ -264,24 +264,20 @@ vcc_ErrWhere(struct vcc *tl, const struct token *t)
 /*--------------------------------------------------------------------*/
 
 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);
 	AN(t);
-	tn = VTAILQ_NEXT(t, list);
-	if (tn == NULL) {
-		VSB_cat(tl->sb,
-		    "Ran out of input, something is missing or"
-		    " maybe unbalanced (...) or {...}\n");
-		tl->err = 1;
-	}
-	return (tn);
+	assert(t->tok != EOI);
+	t2 = VTAILQ_NEXT(t, list);
+	AN(t2);
+	return (t2);
 }
 
 struct token *
-vcc_PeekToken(struct vcc *tl)
+vcc_PeekToken(const struct vcc *tl)
 {
 
 	CHECK_OBJ_NOTNULL(tl, VCC_MAGIC);
@@ -330,7 +326,8 @@ vcc_IdIs(const struct token *t, const char *p)
  */
 
 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);


More information about the varnish-commit mailing list