Closed samhatchett closed 2 years ago
I'm a little confused about the logic behind this change (although I'm not objecting to it). Lines read from the input file are limited to 1024 characters so it shouldn't matter how long the original comment is (it will get truncated when read) or whether its length is stored in an int or a size_t.
Ok, I see now where the issue lies. It's at line 674 where len
gets decremented as each token is found. This could create a problem if len
becomes negative, causing an underflow for a size_t (unsigned int) variable.
under some circumstances, like certain input lines that have long comments, the code here can cause an underflow in size_t which casts to a very large integer during comparison and results in the number of tokens being over-reported (max of 40). Most of these tokens are of course garbage. Changing this
len
variable to an integer permits it to be less than zero, thus allowing an exit from thewhile
at L665.