[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH] dfa: convert "cannot happen" code/comment to use assert
From: |
Jim Meyering |
Subject: |
[PATCH] dfa: convert "cannot happen" code/comment to use assert |
Date: |
Thu, 08 Apr 2010 23:19:22 +0200 |
There were a surprising number of these "cannot happen" comments.
All appear to be accurate, which was slightly surprising,
so I've replaced them with assertions.
All tests still pass, of course.
>From 2936f502f84e238070f5f459f2c52395ddfde158 Mon Sep 17 00:00:00 2001
From: Jim Meyering <address@hidden>
Date: Thu, 8 Apr 2010 10:08:37 +0200
Subject: [PATCH] dfa: convert "cannot happen" code/comment to use assert
* src/dfa.c (dfamust): There were numerous "cannot happen" comments,
some associated with "if (expr) goto done;". Replace each with an
equivalent "assert (!expr);".
---
src/dfa.c | 20 +++++++-------------
1 files changed, 7 insertions(+), 13 deletions(-)
diff --git a/src/dfa.c b/src/dfa.c
index ec015d6..f3f8c60 100644
--- a/src/dfa.c
+++ b/src/dfa.c
@@ -3722,7 +3722,7 @@ dfamust (struct dfa *d)
{
case LPAREN:
case RPAREN:
- goto done; /* "cannot happen" */
+ assert (!"neither LPAREN nor RPAREN may appear here");
case EMPTY:
case BEGLINE:
case ENDLINE:
@@ -3735,15 +3735,13 @@ dfamust (struct dfa *d)
break;
case STAR:
case QMARK:
- if (mp <= musts)
- goto done; /* "cannot happen" */
+ assert (musts < mp);
--mp;
resetmust(mp);
break;
case OR:
case ORTOP:
- if (mp < &musts[2])
- goto done; /* "cannot happen" */
+ assert (&musts[2] <= mp);
{
char **new;
must *lmp;
@@ -3781,14 +3779,12 @@ dfamust (struct dfa *d)
}
break;
case PLUS:
- if (mp <= musts)
- goto done; /* "cannot happen" */
+ assert (musts < mp);
--mp;
mp->is[0] = '\0';
break;
case END:
- if (mp != &musts[1])
- goto done; /* "cannot happen" */
+ assert (mp == &musts[1]);
for (i = 0; musts[0].in[i] != NULL; ++i)
if (strlen(musts[0].in[i]) > strlen(result))
result = musts[0].in[i];
@@ -3796,8 +3792,7 @@ dfamust (struct dfa *d)
exact = 1;
goto done;
case CAT:
- if (mp < &musts[2])
- goto done; /* "cannot happen" */
+ assert (&musts[2] <= mp);
{
must *lmp;
must *rmp;
@@ -3855,8 +3850,7 @@ dfamust (struct dfa *d)
default:
if (t < END)
{
- /* "cannot happen" */
- goto done;
+ assert (!"oops! t >= END");
}
else if (t == '\0')
{
--
1.7.1.rc0.239.g8b27e
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [PATCH] dfa: convert "cannot happen" code/comment to use assert,
Jim Meyering <=