/*
Presumably comments would be skipped.
#include <stdio.h>
int main(void)
{
printf("Hello, world\n");;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
return 0;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
}
My patch to this hole would be "run the source through GNU indent
with a specified and fixed list of options, remove comments, remove
empty lines and lines consisting only of whitespace, then count
lines. Since GNU indent knows how to parse a good portion of C,
this is getting a lot more complicated.
An immediate problem with this so-called "fix" is that you can insert
goto X; X:
before any statement that doesn't already have a label on it, provided
that you generate labels that aren't already in use. And you can do it
repeatedly.
Other things you can insert before a statement:
while (0);
if (VARIABLE) { ; } else { ; }
(where VARIABLE is declared, in scope, and of integer or pointer type).
do { ; } while (0);
for (;0
{ ; }
It's going to take fairly complicated logic (of the same level as a compiler
optimizer) to determine that code like:
int n;
if(n) { goto k22571; k22571: for(;0
{ while(0); } } else { do { ; } while (0); }
is completely useless.