The order of tests in
for(i=Pl-1;T[i]==P[i]&&i>=0;i--)
is wrong. After a complete match, you compare T[-1]
to P[-1]
before checking whether the index is admissible.
If a mismatch occurs at the last pattern character,
Tl -= D[T[i+1]];
T += D[T[i+1]];
skips according to a character that need not exist (if the pattern end is aligned with the text end).